grada-run 0.42.0 → 0.43.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/bin/cli.js +1 -1
  2. package/package.json +1 -1
  3. package/src/commands/add.js +93 -11
  4. package/src/commands/alerts.js +66 -30
  5. package/src/commands/apply.js +61 -9
  6. package/src/commands/db/backup.js +1 -2
  7. package/src/commands/db/connect.js +10 -4
  8. package/src/commands/db/enable-vector.js +19 -6
  9. package/src/commands/db/import.js +114 -22
  10. package/src/commands/db/migrate.js +76 -72
  11. package/src/commands/db/restore.js +38 -6
  12. package/src/commands/destroy.js +20 -3
  13. package/src/commands/diagnose.js +40 -21
  14. package/src/commands/doctor.js +4 -2
  15. package/src/commands/domain.js +20 -2
  16. package/src/commands/drift.js +2 -1
  17. package/src/commands/eject.js +13 -2
  18. package/src/commands/gc.js +100 -3
  19. package/src/commands/init.js +75 -9
  20. package/src/commands/logs.js +3 -1
  21. package/src/commands/mcp.js +2 -1
  22. package/src/commands/rollback.js +54 -5
  23. package/src/commands/secrets.js +224 -57
  24. package/src/commands/status.js +4 -1
  25. package/src/commands/sync-ai.js +4 -3
  26. package/src/commands/wake.js +45 -1
  27. package/src/data/action-pins.js +26 -0
  28. package/src/utils/addons.js +9 -6
  29. package/src/utils/ai-rules.js +3 -2
  30. package/src/utils/backup.js +16 -2
  31. package/src/utils/command.js +20 -0
  32. package/src/utils/db-tunnel.js +15 -5
  33. package/src/utils/detector.js +8 -0
  34. package/src/utils/ecs-runner.js +16 -3
  35. package/src/utils/frameworks.js +14 -2
  36. package/src/utils/generator.js +21 -13
  37. package/src/utils/prompts.js +20 -4
  38. package/src/utils/resolvers.js +9 -7
  39. package/src/utils/revision-discovery.js +19 -7
  40. package/templates/docker/nestjs.Dockerfile +2 -2
  41. package/templates/docker/nextjs.Dockerfile +3 -3
  42. package/templates/docker/node.Dockerfile +2 -2
  43. package/templates/docker/nuxt.Dockerfile +2 -2
  44. package/templates/docker/static.Dockerfile +1 -1
  45. package/templates/docker/svelte.Dockerfile +2 -2
  46. package/templates/github/deploy-lambda.yml +55 -12
  47. package/templates/github/deploy-static.yml +4 -3
  48. package/templates/github/deploy.yml +96 -13
  49. package/templates/github/drift.yml +74 -5
  50. package/templates/github/preview-lambda.yml +143 -13
  51. package/templates/github/preview.yml +141 -13
  52. package/templates/github/teardown.yml +77 -12
  53. package/templates/terraform/addons/s3.tf +33 -0
  54. package/templates/terraform/backend.tf +7 -0
  55. package/templates/terraform/database-mysql.tf +5 -1
  56. package/templates/terraform/database.tf +5 -1
  57. package/templates/terraform/oidc.tf +3 -2
  58. package/templates/terraform/secrets.tf +6 -4
  59. package/templates/terraform/worker.tf +7 -0
@@ -1,12 +1,17 @@
1
1
  name: Ephemeral PR Preview
2
2
 
3
3
  on:
4
- pull_request:
4
+ # pull_request_target (not pull_request): this file comes from the base
5
+ # branch, so a fork PR cannot delete the same-repo guard below to reach
6
+ # the admin CI role (BUG-140). The PR head is checked out explicitly by
7
+ # SHA in the guarded step instead.
8
+ pull_request_target:
5
9
  types: [opened, synchronize, reopened]
6
10
 
7
11
  # One runner per PR: rapid pushes cancel superseded previews instead of
8
- # overlapping applies on the same workspace. Shares its group with
9
- # teardown.yml, which queues (never cancels) behind an in-flight deploy.
12
+ # overlapping applies on the same workspace. Teardown runs in its own
13
+ # group (a reopen must never cancel an in-flight destroy); the state
14
+ # lock serializes the destroy/apply race instead (see -lock-timeout).
10
15
  concurrency:
11
16
  group: preview-${{ github.event.pull_request.number }}
12
17
  cancel-in-progress: true
@@ -15,6 +20,7 @@ env:
15
20
  AWS_REGION: {{REGION}}
16
21
  ECR_REPOSITORY: {{PROJECT_NAME}}{{RESOURCE_SUFFIX}}-repo
17
22
  WORKSPACE: pr-${{ github.event.pull_request.number }}
23
+ CF_COMMENT: {{PROJECT_NAME}}-pr-${{ github.event.pull_request.number }}{{RESOURCE_SUFFIX}}-cdn
18
24
 
19
25
  permissions:
20
26
  id-token: write
@@ -24,23 +30,54 @@ permissions:
24
30
  jobs:
25
31
  deploy-preview:
26
32
  name: Provision Preview Environment
33
+ # Same-repo PRs only: fork code must never execute with the admin CI
34
+ # role or production secrets. Trustworthy because this file comes from
35
+ # base (see trigger above). Public repos needing fork previews should
36
+ # gate this job behind an environment with required reviewers instead
37
+ # of deleting the guard.
38
+ if: github.event.pull_request.head.repo.full_name == github.repository
27
39
  runs-on: ubuntu-latest
40
+ timeout-minutes: 45
28
41
 
29
42
  steps:
30
- - name: Checkout Code
31
- uses: actions/checkout@v4
43
+ - name: Checkout PR head
44
+ uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
45
+ with:
46
+ # Pinned SHA (not a ref name): the exact head this event fired
47
+ # for, immune to ref moves between event and checkout.
48
+ ref: ${{ github.event.pull_request.head.sha }}
32
49
 
33
50
  - name: Configure AWS credentials
34
- uses: aws-actions/configure-aws-credentials@v4
51
+ id: aws-creds
52
+ uses: aws-actions/configure-aws-credentials@7474bc4690e29a8392af63c5b98e7449536d5c3a # v4
53
+ continue-on-error: true
35
54
  with:
36
55
  role-to-assume: arn:aws:iam::{{AWS_ACCOUNT_ID}}:role/{{PROJECT_NAME}}{{RESOURCE_SUFFIX}}-github-actions-role
37
56
  aws-region: ${{ env.AWS_REGION }}
38
57
 
58
+ # A missing role means the stack is absent (never provisioned or
59
+ # destroyed): skip loud instead of bursting red assume noise. Any
60
+ # other assume failure fails loud with both cases named (BUG-138).
61
+ - name: Interpret credential failure
62
+ if: steps.aws-creds.outcome == 'failure'
63
+ run: |
64
+ ROLE_ARN="arn:aws:iam::{{AWS_ACCOUNT_ID}}:role/{{PROJECT_NAME}}{{RESOURCE_SUFFIX}}-github-actions-role"
65
+ TOKEN="$(curl -fsSL -H "Authorization: bearer ${ACTIONS_ID_TOKEN_REQUEST_TOKEN}" "${ACTIONS_ID_TOKEN_REQUEST_URL}&audience=sts.amazonaws.com" | jq -r '.value')"
66
+ ERR="$(aws sts assume-role-with-web-identity --role-arn "$ROLE_ARN" --role-session-name grada-preflight --web-identity-token "$TOKEN" 2>&1)" || true
67
+ if echo "$ERR" | grep -qiE 'NoSuchEntity|does not exist|cannot be found'; then
68
+ echo "::notice::AWS role $ROLE_ARN does not exist — the stack was likely never provisioned or was destroyed. Skipping this run (re-bootstrap with: npx grada-run apply)."
69
+ else
70
+ echo "::error::AWS credential assumption failed. Either the role is missing (stack absent — re-bootstrap with: npx grada-run apply) or the OIDC trust does not cover this run (check terraform/oidc.tf). Raw error: $ERR"
71
+ exit 1
72
+ fi
73
+
39
74
  - name: Login to Amazon ECR
75
+ if: steps.aws-creds.outcome == 'success'
40
76
  id: login-ecr
41
- uses: aws-actions/amazon-ecr-login@v2
77
+ uses: aws-actions/amazon-ecr-login@03f1aad4c6c7ffd436567f42f9384779290529bd # v2
42
78
 
43
79
  - name: Build and Push Docker image
80
+ if: steps.aws-creds.outcome == 'success'
44
81
  env:
45
82
  ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
46
83
  run: |
@@ -49,29 +86,120 @@ jobs:
49
86
  docker push $ECR_REGISTRY/$ECR_REPOSITORY:${{ env.WORKSPACE }}
50
87
 
51
88
  - name: Setup Terraform
52
- uses: hashicorp/setup-terraform@v3
89
+ uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3
53
90
 
54
91
  - name: Terraform Init & Apply
55
92
  id: tf-apply
93
+ if: steps.aws-creds.outcome == 'success'
56
94
  working-directory: ./terraform
57
95
  run: |
58
96
  terraform init -input=false
59
97
  # Create or select the workspace specific to this PR
60
98
  terraform workspace select -or-create ${{ env.WORKSPACE }}
61
- terraform apply -auto-approve
99
+ # Teardown runs in its own group (see teardown.yml): a reopen
100
+ # during teardown waits on the state lock instead of racing it.
101
+ terraform apply -auto-approve -input=false -lock-timeout=10m
62
102
 
63
103
  # Extract the CloudFront URL to post to GitHub (the ALB origin
64
104
  # accepts CloudFront edges only — its direct URL is not browsable)
65
105
  PREVIEW_URL=$(terraform output -raw cloudfront_url)
66
106
  echo "PREVIEW_URL=$PREVIEW_URL" >> $GITHUB_ENV
67
107
 
108
+ # Every push redeploys the preview: clear its CDN so new HTML shows
109
+ # immediately instead of serving stale pages until TTL expiry.
110
+ - name: Invalidate CloudFront
111
+ if: steps.aws-creds.outcome == 'success'
112
+ run: |
113
+ DIST_ID=$(aws cloudfront list-distributions \
114
+ --query "DistributionList.Items[?Comment=='${{ env.CF_COMMENT }}'].Id | [0]" \
115
+ --output text \
116
+ --region ${{ env.AWS_REGION }})
117
+ if [ -z "$DIST_ID" ] || [ "$DIST_ID" = "None" ]; then
118
+ echo "CloudFront distribution '${{ env.CF_COMMENT }}' not found." >&2
119
+ exit 1
120
+ fi
121
+ aws cloudfront create-invalidation \
122
+ --distribution-id "$DIST_ID" \
123
+ --paths "/*" \
124
+ --region ${{ env.AWS_REGION }}
125
+
126
+ # One sticky comment per PR (updated in place), never a new
127
+ # comment per push — and a failed run overwrites the green URL
128
+ # instead of leaving it standing as truth (BUG-190).
68
129
  - name: Comment PR
69
- uses: actions/github-script@v7
130
+ if: steps.aws-creds.outcome == 'success'
131
+ uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
132
+ with:
133
+ script: |
134
+ const marker = '<!-- grada-preview -->';
135
+ const body = `${marker}\n🚀 **Preview Environment Deployed!**\n\nYour ephemeral AWS Fargate environment is live at:\n[${process.env.PREVIEW_URL}](${process.env.PREVIEW_URL})\n\n_This environment will be automatically destroyed when the PR is merged or closed._\n\n---\n<div align="right"><sup>☁️ Generated by <a href="https://github.com/grada-run/grada">Grada</a></sup></div>`;
136
+ const { data: comments } = await github.rest.issues.listComments({
137
+ issue_number: context.issue.number,
138
+ owner: context.repo.owner,
139
+ repo: context.repo.repo,
140
+ });
141
+ const existing = comments.find((comment) => comment.body?.includes(marker));
142
+ if (existing) {
143
+ await github.rest.issues.updateComment({
144
+ owner: context.repo.owner,
145
+ repo: context.repo.repo,
146
+ comment_id: existing.id,
147
+ body,
148
+ });
149
+ } else {
150
+ await github.rest.issues.createComment({
151
+ issue_number: context.issue.number,
152
+ owner: context.repo.owner,
153
+ repo: context.repo.repo,
154
+ body,
155
+ });
156
+ }
157
+
158
+ - name: Report preview failure on PR
159
+ if: failure()
160
+ uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
70
161
  with:
71
162
  script: |
72
- github.rest.issues.createComment({
163
+ const marker = '<!-- grada-preview -->';
164
+ const runUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
165
+ const body = `${marker}\n❌ **Preview Environment Failed**\n\nThe preview deployment for this PR failed — the URL below (if any) is stale. See the [workflow run](${runUrl}) for details.`;
166
+ const { data: comments } = await github.rest.issues.listComments({
73
167
  issue_number: context.issue.number,
74
168
  owner: context.repo.owner,
75
169
  repo: context.repo.repo,
76
- body: `🚀 **Preview Environment Deployed!**\n\nYour ephemeral AWS Fargate environment is live at:\n[${process.env.PREVIEW_URL}](${process.env.PREVIEW_URL})\n\n_This environment will be automatically destroyed when the PR is merged or closed._\n\n---\n<div align="right"><sup>☁️ Generated by <a href="https://github.com/grada-run/grada">Grada</a></sup></div>`
77
- })
170
+ });
171
+ const existing = comments.find((comment) => comment.body?.includes(marker));
172
+ if (existing) {
173
+ await github.rest.issues.updateComment({
174
+ owner: context.repo.owner,
175
+ repo: context.repo.repo,
176
+ comment_id: existing.id,
177
+ body,
178
+ });
179
+ } else {
180
+ await github.rest.issues.createComment({
181
+ issue_number: context.issue.number,
182
+ owner: context.repo.owner,
183
+ repo: context.repo.repo,
184
+ body,
185
+ });
186
+ }
187
+
188
+ # A cancelled apply can strand the S3 state lockfile: point at
189
+ # recovery instead of leaving the next run to fail obscurely
190
+ # (BUG-194). Generic by necessity — the lock ID only exists in the
191
+ # follow-up run's own error.
192
+ - name: Cancellation recovery note
193
+ if: cancelled()
194
+ run: |
195
+ echo "::warning::This run was cancelled while Terraform may have held the state lock. If the next run fails with 'Error acquiring the state lock', run terraform force-unlock <LOCK_ID> (the ID is printed in that error) inside ./terraform — or delete the .tflock object beside the state file in S3 — then re-run."
196
+
197
+ # Fork PRs skip the privileged job above loudly instead of silently:
198
+ # no credentials are issued and no preview is provisioned.
199
+ fork-notice:
200
+ name: Fork PR notice
201
+ if: github.event.pull_request.head.repo.full_name != github.repository
202
+ runs-on: ubuntu-latest
203
+ timeout-minutes: 5
204
+ steps:
205
+ - run: echo "PR previews run for same-repo pull requests only — fork PR #${{ github.event.pull_request.number }} skipped (no AWS credentials issued)."
@@ -1,14 +1,19 @@
1
1
  name: Destroy PR Preview
2
2
 
3
3
  on:
4
- pull_request:
4
+ # pull_request_target (not pull_request): this file comes from the base
5
+ # branch, so a fork PR cannot smuggle privileged steps into its own
6
+ # teardown run (BUG-140). The PR head is checked out explicitly by SHA
7
+ # in the guarded step instead.
8
+ pull_request_target:
5
9
  types: [closed]
6
10
 
7
- # Shared with the preview workflow: teardown queues behind an in-flight
8
- # deploy instead of racing it on the state lock. No cancel-in-progress —
9
- # a teardown must run to completion, never be skipped.
11
+ # Own group (never preview's): a reopen must never cancel an in-flight
12
+ # destroy. No cancel-in-progress — a teardown must run to completion,
13
+ # never be skipped. The state lock serializes the destroy/apply race
14
+ # instead (see -lock-timeout below).
10
15
  concurrency:
11
- group: preview-${{ github.event.pull_request.number }}
16
+ group: teardown-${{ github.event.pull_request.number }}
12
17
 
13
18
  env:
14
19
  AWS_REGION: {{REGION}}
@@ -21,22 +26,71 @@ permissions:
21
26
  jobs:
22
27
  destroy-preview:
23
28
  name: Teardown Preview Environment
29
+ # Same-repo PRs only: fork previews are never provisioned (see the
30
+ # preview workflow guard), so fork teardowns have nothing to destroy.
31
+ # Trustworthy because this file comes from base (see trigger above).
32
+ if: github.event.pull_request.head.repo.full_name == github.repository
24
33
  runs-on: ubuntu-latest
34
+ timeout-minutes: 30
25
35
 
26
36
  steps:
27
- - name: Checkout Code
28
- uses: actions/checkout@v4
37
+ - name: Checkout PR head
38
+ uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
39
+ with:
40
+ # Pinned SHA: destroy exactly the tree the preview applied, so
41
+ # PR-only resources are torn down instead of leaked.
42
+ ref: ${{ github.event.pull_request.head.sha }}
29
43
 
30
44
  - name: Configure AWS credentials
31
- uses: aws-actions/configure-aws-credentials@v4
45
+ id: aws-creds
46
+ uses: aws-actions/configure-aws-credentials@7474bc4690e29a8392af63c5b98e7449536d5c3a # v4
47
+ continue-on-error: true
32
48
  with:
33
49
  role-to-assume: arn:aws:iam::{{AWS_ACCOUNT_ID}}:role/{{PROJECT_NAME}}{{RESOURCE_SUFFIX}}-github-actions-role
34
50
  aws-region: ${{ env.AWS_REGION }}
35
51
 
52
+ # A missing role means the stack is absent (never provisioned or
53
+ # destroyed): skip loud instead of bursting red assume noise. Any
54
+ # other assume failure fails loud with both cases named (BUG-138).
55
+ - name: Interpret credential failure
56
+ if: steps.aws-creds.outcome == 'failure'
57
+ run: |
58
+ ROLE_ARN="arn:aws:iam::{{AWS_ACCOUNT_ID}}:role/{{PROJECT_NAME}}{{RESOURCE_SUFFIX}}-github-actions-role"
59
+ TOKEN="$(curl -fsSL -H "Authorization: bearer ${ACTIONS_ID_TOKEN_REQUEST_TOKEN}" "${ACTIONS_ID_TOKEN_REQUEST_URL}&audience=sts.amazonaws.com" | jq -r '.value')"
60
+ ERR="$(aws sts assume-role-with-web-identity --role-arn "$ROLE_ARN" --role-session-name grada-preflight --web-identity-token "$TOKEN" 2>&1)" || true
61
+ if echo "$ERR" | grep -qiE 'NoSuchEntity|does not exist|cannot be found'; then
62
+ echo "::notice::AWS role $ROLE_ARN does not exist — the stack was likely never provisioned or was destroyed. Skipping this run (re-bootstrap with: npx grada-run apply)."
63
+ else
64
+ echo "::error::AWS credential assumption failed. Either the role is missing (stack absent — re-bootstrap with: npx grada-run apply) or the OIDC trust does not cover this run (check terraform/oidc.tf). Raw error: $ERR"
65
+ exit 1
66
+ fi
67
+
36
68
  - name: Setup Terraform
37
- uses: hashicorp/setup-terraform@v3
69
+ uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3
70
+
71
+ # Preview databases carry deletion protection (database.tf) and
72
+ # `terraform destroy` never applies var updates, so protection is
73
+ # lifted out-of-band first — instance and Aurora-cluster forms.
74
+ # DB-less previews skip quietly (describes find nothing).
75
+ - name: Lift preview deletion protection
76
+ if: steps.aws-creds.outcome == 'success'
77
+ run: |
78
+ APP_NAME="{{PROJECT_NAME}}-${{ env.WORKSPACE }}{{RESOURCE_SUFFIX}}"
79
+ DB_ID="$APP_NAME-db"
80
+ if aws rds describe-db-instances --db-instance-identifier "$DB_ID" --region ${{ env.AWS_REGION }} >/dev/null 2>&1; then
81
+ echo "Lifting deletion protection on $DB_ID..."
82
+ aws rds modify-db-instance --db-instance-identifier "$DB_ID" --no-deletion-protection --apply-immediately --region ${{ env.AWS_REGION }}
83
+ aws rds wait db-instance-available --db-instance-identifier "$DB_ID" --region ${{ env.AWS_REGION }}
84
+ fi
85
+ CLUSTER_ID="$APP_NAME-db-cluster"
86
+ if aws rds describe-db-clusters --db-cluster-identifier "$CLUSTER_ID" --region ${{ env.AWS_REGION }} >/dev/null 2>&1; then
87
+ echo "Lifting deletion protection on $CLUSTER_ID..."
88
+ aws rds modify-db-cluster --db-cluster-identifier "$CLUSTER_ID" --no-deletion-protection --apply-immediately --region ${{ env.AWS_REGION }}
89
+ aws rds wait db-cluster-available --db-cluster-identifier "$CLUSTER_ID" --region ${{ env.AWS_REGION }}
90
+ fi
38
91
 
39
92
  - name: Terraform Init & Destroy
93
+ if: steps.aws-creds.outcome == 'success'
40
94
  working-directory: ./terraform
41
95
  run: |
42
96
  terraform init -input=false
@@ -51,8 +105,19 @@ jobs:
51
105
  fi
52
106
  # Select the PR workspace
53
107
  terraform workspace select ${{ env.WORKSPACE }}
54
- # Destroy all resources in this workspace safely
55
- terraform destroy -auto-approve
108
+ # Destroy all resources in this workspace safely. A close during
109
+ # an in-flight preview waits on the state lock instead of
110
+ # racing it (teardown has its own concurrency group now).
111
+ terraform destroy -auto-approve -input=false -lock-timeout=10m
56
112
  # Switch back to default and delete the PR workspace
57
113
  terraform workspace select default
58
- terraform workspace delete ${{ env.WORKSPACE }}
114
+ terraform workspace delete ${{ env.WORKSPACE }}
115
+
116
+ # A cancelled destroy can strand the S3 state lockfile: point at
117
+ # recovery instead of leaving the next run to fail obscurely
118
+ # (BUG-194). Generic by necessity — the lock ID only exists in the
119
+ # follow-up run's own error.
120
+ - name: Cancellation recovery note
121
+ if: cancelled()
122
+ run: |
123
+ echo "::warning::This run was cancelled while Terraform may have held the state lock. If the next run fails with 'Error acquiring the state lock', run terraform force-unlock <LOCK_ID> (the ID is printed in that error) inside ./terraform — or delete the .tflock object beside the state file in S3 — then re-run."
@@ -35,6 +35,34 @@ resource "aws_s3_bucket_server_side_encryption_configuration" "storage" {
35
35
  }
36
36
  }
37
37
 
38
+ # Versioning: an overwrite or bad deploy never destroys the previous
39
+ # object. Old versions expire via the lifecycle rule below so storage
40
+ # does not grow without bound.
41
+ resource "aws_s3_bucket_versioning" "storage" {
42
+ bucket = aws_s3_bucket.storage.id
43
+
44
+ versioning_configuration {
45
+ status = "Enabled"
46
+ }
47
+ }
48
+
49
+ resource "aws_s3_bucket_lifecycle_configuration" "storage" {
50
+ bucket = aws_s3_bucket.storage.id
51
+
52
+ rule {
53
+ id = "expire-old-versions"
54
+ status = "Enabled"
55
+
56
+ # Empty filter = the whole bucket (required: a filterless rule is a
57
+ # provider warning today and an error in future versions).
58
+ filter {}
59
+
60
+ noncurrent_version_expiration {
61
+ noncurrent_days = 30
62
+ }
63
+ }
64
+ }
65
+
38
66
  resource "aws_s3_bucket_cors_configuration" "storage" {
39
67
  bucket = aws_s3_bucket.storage.id
40
68
 
@@ -58,10 +86,15 @@ resource "aws_cloudfront_origin_access_control" "storage_oac" {
58
86
  }
59
87
 
60
88
  # trivy:ignore:AVD-AWS-0011 - WAF is omitted by default to prevent unexpected monthly costs for users
89
+ # Access logging is intentionally disabled (no logging_config): it doubles
90
+ # request costs into a second bucket. Restrict price_class to
91
+ # PriceClass_100/200 as well if most traffic is US/EU — edge coverage
92
+ # shrinks but so does the transfer bill.
61
93
  resource "aws_cloudfront_distribution" "storage_cdn" {
62
94
  enabled = true
63
95
  is_ipv6_enabled = true
64
96
  wait_for_deployment = false
97
+ price_class = "PriceClass_All"
65
98
 
66
99
  origin {
67
100
  domain_name = aws_s3_bucket.storage.bucket_regional_domain_name
@@ -10,6 +10,13 @@ terraform {
10
10
  source = "hashicorp/tls"
11
11
  version = "~> 4.0"
12
12
  }
13
+ # Declared unconditionally (BUG-137): the conditional injection left
14
+ # pre-existing trees without the pin when the DB arrived via
15
+ # `add database`. Unused on DB-less trees; init installs it anyway.
16
+ random = {
17
+ source = "hashicorp/random"
18
+ version = "~> 3.0"
19
+ }
13
20
  }
14
21
 
15
22
  backend "s3" {
@@ -26,7 +26,11 @@ resource "aws_db_instance" "postgres" {
26
26
  engine_version = "8.0"
27
27
  instance_class = "db.t4g.micro"
28
28
  allocated_storage = 20
29
- storage_encrypted = true
29
+ # Cap storage autoscaling: without a ceiling a runaway workload can
30
+ # grow the volume (and the bill) without bound.
31
+ max_allocated_storage = 200
32
+ backup_retention_period = 7
33
+ storage_encrypted = true
30
34
 
31
35
  # Strip dashes for the database name: RDS MySQL db_name must begin with a
32
36
  # letter and contain only alphanumeric characters (e.g. my-project -> myproject)
@@ -26,7 +26,11 @@ resource "aws_db_instance" "postgres" {
26
26
  engine_version = "16"
27
27
  instance_class = "db.t4g.micro"
28
28
  allocated_storage = 20
29
- storage_encrypted = true
29
+ # Cap storage autoscaling: without a ceiling a runaway workload can
30
+ # grow the volume (and the bill) without bound.
31
+ max_allocated_storage = 200
32
+ backup_retention_period = 7
33
+ storage_encrypted = true
30
34
 
31
35
  # Clean up dashes for the database name (e.g. my-project -> my_project)
32
36
  db_name = replace(local.app_name, "-", "_")
@@ -48,8 +48,9 @@ resource "aws_iam_role" "github_actions" {
48
48
  # remote, or the setup prompt. "repo:*" means any GitHub repo's
49
49
  # Actions can assume this role — re-scope before going live.
50
50
  # Scoped trusts render both subject-claim formats: the classic
51
- # `repo:<owner>/<name>:*` plus the immutable-claim companion
52
- # `repo:<owner>@*/<name>@*:*` (repos created after 2026-07-15).
51
+ # `repo:<owner>/<name>:<suffix>` plus the immutable-claim
52
+ # companion `repo:<owner>@*/<name>@*:<same suffix>`
53
+ # (repos created after 2026-07-15).
53
54
  "token.actions.githubusercontent.com:sub" : {{GITHUB_REPO_SUB}}
54
55
  }
55
56
  StringEquals = {
@@ -2,10 +2,12 @@
2
2
 
3
3
  # 1. Only create the Secret Vault in the default (production) workspace
4
4
  resource "aws_secretsmanager_secret" "app_secrets" {
5
- count = terraform.workspace == "default" ? 1 : 0
6
- name = "{{PROJECT_NAME}}{{RESOURCE_SUFFIX}}-secrets"
7
- description = "Environment variables for {{PROJECT_NAME}}"
8
- recovery_window_in_days = 0 # Allows instant deletion for dev/POC environments
5
+ count = terraform.workspace == "default" ? 1 : 0
6
+ name = "{{PROJECT_NAME}}{{RESOURCE_SUFFIX}}-secrets"
7
+ description = "Environment variables for {{PROJECT_NAME}}"
8
+ # 30-day recovery (BUG-163): an instant-delete vault turns any destroy
9
+ # bug into unrecoverable secret loss. Lower per-tree if you must.
10
+ recovery_window_in_days = 30
9
11
  }
10
12
 
11
13
  # 2. Fetch the existing Secret Vault when running in a PR workspace
@@ -55,6 +55,13 @@ resource "aws_ecs_service" "worker" {
55
55
  desired_count = 1
56
56
  enable_execute_command = true
57
57
 
58
+ # Same safety net as the app service: a bad worker revision rolls
59
+ # back automatically instead of flapping forever.
60
+ deployment_circuit_breaker {
61
+ enable = true
62
+ rollback = true
63
+ }
64
+
58
65
  network_configuration {
59
66
  subnets = aws_subnet.public[*].id
60
67
  security_groups = [aws_security_group.ecs_tasks.id]