feat(templates): add ECS Fargate module to terragrunt and gitlab-cicd templates - #137
feat(templates): add ECS Fargate module to terragrunt and gitlab-cicd templates#137sintiasnn wants to merge 8 commits into
Conversation
|
Testing summary Validated end-to-end against a real AWS account (532090602408, ap-southeast-1):
Reproduction steps and full report: #136 (comment) and #136 (comment) Not tested: the GitLab deploy pipeline itself (needs a GitLab project) — jobs/rules validated as YAML only. Note that the template zips on |
…nabled ECS requires the container to expose a matching port mapping when the service references a container_port in its load balancer configuration, otherwise CreateService fails with InvalidParameterException.
…ALB module, run ECS in private subnets
- Move units under envs/{dev,staging,prod}, shared vars under variables/, ecr at root
- Drop vpc-base/full-vpc units and modules; vpc module now self-contained with
public + private subnets and NAT gateway
- Add modules/alb (public/private, HTTP/HTTPS, per-service target groups)
- Rewrite modules/ecs: services attach to ALB target groups, tasks run in
private subnets, least-privilege IAM (scoped ECR pull, log groups, S3/SSM)
- Add placeholder modules acm, rds-cluster, rds-single
- Add alb/elastic-ip units per env; align ecs-deploy.yml env var paths
3bfbe4a to
b01a964
Compare
The envs/dev|staging|prod restructure added a nesting level, but every unit's terraform.source still pointed two levels up (../../modules/X) instead of three (../../../modules/X). The top-level ecr unit had the opposite issue. Caught by running terragrunt plan against a rendered copy of the template in a sandbox account.
|
Re-test after the Validated end-to-end against a real AWS account (532090602408, ap-southeast-1), same setup as the earlier test in this thread. Setup
Bugs found and fixed during this test
All four are pure path fixes, no logic changes — see the two fix commits on this branch. Apply chain (after fixes) Applied in order:
Task-level check Service task went This is the expected failure — no image has been pushed yet. Importantly it confirms the execution role can authenticate to ECR (an IAM problem would surface as an auth error, not "not found") and that the task in the private subnet can reach ECR through the NAT gateway. Cleanup All test resources destroyed after this comment. |
Same depth miscount as the module source path fix: ecr is a sibling of envs, not envs/<env>, so config_path needs one more ../. Caught by running terragrunt apply against the full chain in a sandbox account.
1abcc25 to
873a25f
Compare
Move the cross-environment ecr unit from the template root into envs/shared/ and restore the s3 unit that was dropped in the envs/ restructure, which had left modules/s3 unreferenced. The ecs units now depend on ../../shared/ecr. Also fixes the Environment tag on shared units: root.hcl derives the environment from the unit's parent directory name, so a root-level unit was tagged with the template directory name instead of "shared".
root.hcl generates a provider config referencing var.region for every unit, but acm, rds-cluster and rds-single never declared it, so those three units failed with "Reference to undeclared input variable" and could not even be planned. Caught by applying every dev unit in a sandbox account.
Description 📋
Adds a reusable ECS Fargate module to the
terragrunttemplate plus a matching deploy pipeline in thegitlab-cicdtemplate.modules/ecs: ECS cluster (Fargate + Fargate Spot), per-entry task definitions, IAM execution/task roles (with optional S3/SSM access), CloudWatch log groups.servicesmap for always-on workloads (task definition + ECS service, optional ALB and/or Cloud Map service discovery).jobsmap for on-demand workloads launched viaecs:RunTask.dev/staging/prod/ecsTerragrunt units wiring the module to the existingvpc,security-groups, andshared/ecrunits.ecssecurity group added to thedev/staging/prod/security-groupsunits (outbound-only; task/ALB security groups are created by the module itself).shared/variables/ecs: per-service CPU/memory sizing and a git-ignoredenv/<environment>/<service>.ymllayout for per-service environment variables.gitlab-cicd/app/ecs-deploy.yml: deploy jobs for dev/staging/prod that convert the app.envCI variable to YAML, setECS_IMAGE_TAGto the image pushed by the existing build jobs, and runterragrunt applytargeted at the service's task definition + ECS service..rules:development, which was referenced bybuild:development-docker/build:staging-docker/build:production-dockerbut never defined independencies/only.yml— surfaced because the new ECS deploy jobs add aneedsdependency on those build jobs.Fixes #136
Type of change 🤔
Submission checklist ✅
Test plan
terraform fmt -checkandterraform validatepass ontemplates/terragrunt/modules/ecs(no automated test harness exists for this template type — verified manually since the module has no{{ }}placeholders).dev/ecs→vpc/security-groups/shared/ecroutputs resolve correctly;sg_ids.ecsmatches the new security group entry added to all three environments.