Skip to content

Lambda trigger and submodule add #24

Merged
merged 4 commits into from
Jun 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/platform-tg-infra.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@
},
{
"path": "../../repo-setup"
},
{
"path": "../../template-eks-cluster"
},
{
"path": "../../module-decomposition"
},
{
"path": "../../csvd-platform-lab-srn"
}
]
}
12 changes: 12 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[submodule "lab/clusters/csvd-platform-lab-mcm"]
path = lab/clusters/csvd-platform-lab-mcm
url = git@github.e.it.census.gov:sct-engineering/csvd-platform-lab-mcm
[submodule "lab/clusters/csvd-platform-lab-srn"]
path = lab/clusters/csvd-platform-lab-srn
url = git@github.e.it.census.gov:sct-engineering/csvd-platform-lab-srn
[submodule "lab/clusters/csvd-platform-lab-dja"]
path = lab/clusters/csvd-platform-lab-dja
url = git@github.e.it.census.gov:sct-engineering/csvd-platform-lab-dja
[submodule "lab/clusters/eks-ois-eem-cribl-prod"]
path = lab/clusters/eks-ois-eem-cribl-prod
url = git@github.e.it.census.gov:sct-engineering/eks-ois-eem-cribl-prod
64 changes: 49 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
.PHONY: help config init validate plan fmt check clean deploy-to-pipeline tail parse
.PHONY: help config init validate plan fmt check clean deploy-to-pipeline tail parse trigger-template
# Default values
ENV ?= development
AWS_REGION ?= us-gov-east-1
AWS_ACCOUNT_ID ?= 066921446319
ACCOUNT_NAME ?= ent-ew-logging-prod
AWS_PROFILE ?= 066921446319-ent-gov-logging-prod
CLUSTER_NAME ?= eks-ois-eem-cribl-prod
REGION_DIR ?= us-gov-east-1
CLUSTER_DIR ?= csvd-platform-lab-mcm
CLUSTER_DIR ?= ois-eem-cribl-prod

help:
@echo "Available targets:"
Expand All @@ -14,26 +19,27 @@ help:
@echo " clean - Clean up Terragrunt cache and temporary files"
@echo " deploy-to-pipeline - Zip and upload to S3 to trigger CodePipeline"
@echo " tail - Tail the logs of the CodeBuild project"
@echo " trigger-template - Trigger template automation lambda with config.json"

# Shared configuration target that exports all variables
config:
@echo "Loading configuration..."

# Detect configuration files
$(eval ACCOUNT_HCL=lab/$(ENV)/account.hcl)
$(eval REGION_HCL=lab/$(ENV)/$(REGION_DIR)/region.hcl)
$(eval CLUSTER_HCL=lab/$(ENV)/$(REGION_DIR)/vpc/$(CLUSTER_DIR)/cluster.hcl)
# # Detect configuration files
# $(eval ACCOUNT_HCL=lab/$(ENV)/account.hcl)
# $(eval REGION_HCL=lab/$(ENV)/$(REGION_DIR)/region.hcl)
# $(eval CLUSTER_HCL=lab/$(ENV)/$(REGION_DIR)/vpc/$(CLUSTER_DIR)/cluster.hcl)

@if [ ! -f "$(ACCOUNT_HCL)" ]; then echo "Error: $(ACCOUNT_HCL) not found"; exit 1; fi
@if [ ! -f "$(REGION_HCL)" ]; then echo "Error: $(REGION_HCL) not found"; exit 1; fi
@if [ ! -f "$(CLUSTER_HCL)" ]; then echo "Error: $(CLUSTER_HCL) not found"; exit 1; fi
# @if [ ! -f "$(ACCOUNT_HCL)" ]; then echo "Error: $(ACCOUNT_HCL) not found"; exit 1; fi
# @if [ ! -f "$(REGION_HCL)" ]; then echo "Error: $(REGION_HCL) not found"; exit 1; fi
# @if [ ! -f "$(CLUSTER_HCL)" ]; then echo "Error: $(CLUSTER_HCL) not found"; exit 1; fi

# Extract values from HCL files
$(eval AWS_ACCOUNT_ID=$(shell grep -oP 'aws_account_id\s*=\s*"\K[^"]+' $(ACCOUNT_HCL)))
$(eval ACCOUNT_NAME=$(shell grep -oP 'account_name\s*=\s*"\K[^"]+' $(ACCOUNT_HCL)))
$(eval AWS_PROFILE=$(shell echo $(AWS_ACCOUNT_ID)-$(shell echo $(ACCOUNT_NAME) | sed 's/-ew/-gov/')))
$(eval AWS_REGION=$(shell grep -oP 'aws_region\s*=\s*"\K[^"]+' $(REGION_HCL)))
$(eval CLUSTER_NAME=$(shell grep -oP 'cluster_name\s*=\s*"\K[^"]+' $(CLUSTER_HCL)))
# # Extract values from HCL files
# $(eval AWS_ACCOUNT_ID=$(shell grep -oP 'aws_account_id\s*=\s*"\K[^"]+' $(ACCOUNT_HCL)))
# $(eval ACCOUNT_NAME=$(shell grep -oP 'account_name\s*=\s*"\K[^"]+' $(ACCOUNT_HCL)))
# $(eval AWS_PROFILE=$(shell echo $(AWS_ACCOUNT_ID)-$(shell echo $(ACCOUNT_NAME) | sed 's/-ew/-gov/')))
# $(eval AWS_REGION=$(shell grep -oP 'aws_region\s*=\s*"\K[^"]+' $(REGION_HCL)))
# $(eval CLUSTER_NAME=$(shell grep -oP 'cluster_name\s*=\s*"\K[^"]+' $(CLUSTER_HCL)))

# Calculate derived values
$(eval REGION_SHORT=$(shell echo $(AWS_REGION) | sed 's/\([a-z]\)[a-z]*-/\1/g'))
Expand Down Expand Up @@ -139,3 +145,31 @@ tail: config
--since 1m \
--region $(AWS_REGION) \
--profile $(AWS_PROFILE)

# Template automation using lambda
trigger-template: config
@echo "Triggering template automation lambda..."
@if [ ! -f "config.json" ]; then \
echo "Error: config.json not found in current directory"; \
exit 1; \
fi

@echo "Invoking lambda function with config.json payload..."
aws lambda invoke \
--function-name arn:aws-us-gov:lambda:us-gov-west-1:229685449397:function:template-repos-template-automation \
--payload file://config.json \
--region us-gov-west-1 \
--profile 229685449397-csvd-dev-gov \
--cli-binary-format raw-in-base64-out \
lambda-response.json

@echo "Lambda response:"
@cat lambda-response.json | jq '.' 2>/dev/null || cat lambda-response.json

@echo "Cleaning up response file..."
@rm -f lambda-response.json

@echo "Template automation lambda triggered successfully!"
@echo "Adding cluster as submodule"
@git submodule add git@github.e.it.census.gov:sct-engineering/$(CLUSTER_NAME) ./lab/clusters/$(CLUSTER_NAME)
@echo "Submodule added successfully!"
15 changes: 2 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ make plan # Preview changes
make fmt # Format files
make check # Run all checks
make clean # Clean up temporary files
make deploy-to-piepeline # zip files and push to s3 for codepipeline
make trigger-template # trigger lambda with config.json to generate new cluster repo
```

### Manual Terragrunt Commands
Expand Down Expand Up @@ -93,23 +95,10 @@ Terragrunt configurations are organized like this:

Check the environment folders for more details.

## Testing

The `/tests` folder has tools to check if everything works. To run tests:

```bash
cd tests
./run_tests.sh
```

## How to Contribute

1. Make a copy of this repository
2. Create a new branch for your changes
3. Make your updates
4. Run `make check` to ensure everything is correct
5. Submit a pull request

## License

Copyright © 2025 Your Organization. All rights reserved.
40 changes: 40 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"body": {
"project_name": "eks-ois-eem-cribl-prod",
"owning_team": "tf-module-admins",
"template_settings": {
"environment": "production",
"region": "us-gov-east-1",
"cluster_dir": "ois-eem-cribl-prod",
"enable_all_modules": true,
"account": {
"account_name": "ent-ew-logging-prod",
"aws_account_id": "066921446319",
"aws_profile": "066921446319-ent-gov-logging-prod",
"environment_abbr": "prod"
},
"vpc": {
"vpc_name": "vpc1-inf-services",
"vpc_domain_name": "services.inf.csp1.census.gov"
},
"cluster": {
"cluster_name": "ois-eem-cribl-prod",
"cluster_mailing_list": "ois.acmt.list@census.gov",
"eks_instance_disk_size": 200,
"eks_ng_desired_size": 2,
"eks_ng_max_size": 2,
"eks_ng_min_size": 2,
"organization": "CHANGEME",
"finops_project_name": "CHANGEME",
"finops_project_number": "CHANGEME",
"finops_project_role": "CHANGEME",
"tags": {
"slim:schedule": "CHANGEME",
"environment": "production",
"owner": "OIS Security Engineering",
"managed_by": "terragrunt"
}
}
}
}
}
26 changes: 0 additions & 26 deletions input_vars.hcl

This file was deleted.

39 changes: 0 additions & 39 deletions lab/_envcommon/common-variables.hcl

This file was deleted.

Loading