Skip to content

Commit 3cce25e

Browse files
authored
Clarify Terraform bootstrap image tag ownership (#4)
- Add `bootstrap_image_tag` Terraform variable for the initial ECS task definition image tag - Replace hardcoded `:latest` in Terraform task definition with `var.bootstrap_image_tag` - Document the ownership split between Terraform bootstrap infrastructure and GitHub Actions SHA-based CD - Clarify that Terraform should not roll back externally deployed ECS task definition revisions Verified: - `terraform fmt` - `terraform validate` - `terraform plan` - Plan reported no infrastructure changes because `bootstrap_image_tag` defaults to `latest`
1 parent b2c459b commit 3cce25e

3 files changed

Lines changed: 46 additions & 6 deletions

File tree

docs/aws_terraform_deployment_sequence.md

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,6 @@ Deferred production hardening:
752752
- production credential registry/admin process
753753
- migration version table
754754
- CI-before-deploy safety clarification and deployment guardrails
755-
- Terraform image tag handling alignment with SHA-based CD
756755

757756
---
758757

@@ -804,7 +803,42 @@ Important distinction:
804803

805804
---
806805

807-
## 20. Implemented AWS runtime mapping
806+
## 20. Clarified Terraform bootstrap image tag ownership
807+
808+
Files:
809+
810+
- `infra/terraform/ecs_task_definition.tf`
811+
- `infra/terraform/variables.tf`
812+
- `infra/terraform/ecs_service.tf`
813+
814+
Why:
815+
816+
- Terraform needs an image reference so it can create the initial ECS task definition.
817+
- GitHub Actions CD owns real application releases after infrastructure exists.
818+
- The CD workflow deploys immutable Git commit SHA image tags by registering new ECS task definition revisions.
819+
- Terraform should not roll back the ECS service to its original bootstrap task definition during later infrastructure applies.
820+
821+
Implemented changes:
822+
823+
- Added `var.bootstrap_image_tag`, defaulting to `latest`.
824+
- Updated the Terraform ECS task definition image reference to use `var.bootstrap_image_tag`.
825+
- Kept the ECS service lifecycle rule that ignores `task_definition` and `desired_count`.
826+
827+
Important distinction:
828+
829+
- Terraform owns the ECS task definition shape and bootstrap image reference.
830+
- GitHub Actions CD owns the currently deployed application image revision.
831+
- Manual operations may temporarily own `desired_count`, for example when pausing the service at zero.
832+
- Terraform should not treat SHA-based CD deployments as infrastructure drift.
833+
834+
Verified result:
835+
836+
- `terraform fmt` completed.
837+
- `terraform validate` passed.
838+
- `terraform plan` reported no changes because `var.bootstrap_image_tag` still defaults to `latest`.
839+
840+
841+
## 21. Implemented AWS runtime mapping
808842

809843
Local Docker Compose mapping:
810844

@@ -838,7 +872,7 @@ The application settings code continues reading the same variable names. The dep
838872

839873
---
840874

841-
## 21. Local-to-AWS environment mapping
875+
## 22. Local-to-AWS environment mapping
842876

843877
Local app configuration:
844878

@@ -899,7 +933,7 @@ Example smoke checks:
899933

900934
---
901935

902-
## 22. Why so many explicit resources are required
936+
## 23. Why so many explicit resources are required
903937

904938
AWS does not infer the runtime wiring automatically.
905939

infra/terraform/ecs_task_definition.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ resource "aws_ecs_task_definition" "app_task_definition" {
1616
container_definitions = jsonencode([
1717
{
1818
name = "app"
19-
image = "${aws_ecr_repository.app.repository_url}:latest"
19+
image = "${aws_ecr_repository.app.repository_url}:${var.bootstrap_image_tag}"
2020
essential = true
2121

2222
portMappings = [

infra/terraform/variables.tf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,10 @@ variable "environment" {
1919
variable "agent_credential_hash_secret_arn" {
2020
description = "ARN of the existing Secrets Manager secret containing AGENT_CREDENTIAL_HASH_SECRET."
2121
type = string
22-
}
22+
}
23+
24+
variable "bootstrap_image_tag" {
25+
description = "Initial image tag used by Terraform when creating the bootstrap ECS task definition. GitHub Actions CD deploys immutable Git SHA image tags after infrastructure exists."
26+
type = string
27+
default = "latest"
28+
}

0 commit comments

Comments
 (0)