grada-run 0.49.0 → 0.49.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "grada-run",
3
- "version": "0.49.0",
3
+ "version": "0.49.1",
4
4
  "description": "Provision production-ready AWS infrastructure and CI/CD pipelines in seconds.",
5
5
  "engines": {
6
6
  "node": ">=18.0.0"
@@ -3,9 +3,9 @@ import path from 'path';
3
3
  import { intro, outro, confirm, spinner, cancel } from '@clack/prompts';
4
4
  import color from 'picocolors';
5
5
  import { RDSClient, DescribeDBInstancesCommand, DescribeDBClustersCommand, DescribeDBSnapshotsCommand, DescribeDBClusterSnapshotsCommand, StartDBInstanceCommand, StartDBClusterCommand, CreateDBSnapshotCommand, CreateDBClusterSnapshotCommand, ModifyDBInstanceCommand, ModifyDBClusterCommand } from '@aws-sdk/client-rds';
6
- import { S3Client } from '@aws-sdk/client-s3';
6
+ import { S3Client, ListObjectVersionsCommand } from '@aws-sdk/client-s3';
7
7
  import { teardownStateBucket, drainBucketObjects, resolveClient } from '../utils/aws.js';
8
- import { checkDependency, pollUntil } from '../utils/system.js';
8
+ import { checkDependency, pollUntil, sleep } from '../utils/system.js';
9
9
  import { trackEvent, flushTelemetry, trackSuccess, setActiveCommandName, resetActiveCommandName } from '../core/telemetry.js';
10
10
  import { failCommand, shouldAutoApprove, refuseIfNonInteractive, refuseUnknownFlags, isProgrammaticCall } from '../utils/command.js';
11
11
  import { runTerraformCommand, readLastRunMarker, isInterruptedMarker, ensureTerraformInit, getTerraformStateBuckets, DEFAULT_TERRAFORM_PHASE_TIMEOUT_MS, PROGRESS_MODES } from '../utils/terraform.js';
@@ -17,6 +17,9 @@ import { normalizeOptions, parseFlags, normalizeArgv } from '../utils/args.js';
17
17
  import { truncateSpinnerText } from '../utils/spinner-text.js';
18
18
 
19
19
  export const DEFAULT_DESTROY_DB_TIMEOUT_MS = 600000;
20
+ export const DEFAULT_DESTROY_DRAIN_SETTLE_TIMEOUT_MS = 120000;
21
+ export const DEFAULT_DESTROY_DRAIN_SETTLE_INTERVAL_MS = 5000;
22
+ export const DEFAULT_DESTROY_NOTEMPTY_RETRY_SETTLE_MS = 10000;
20
23
  export const DEFAULT_DESTROY_DB_SETTLE_TIMEOUT_MS = 1800000;
21
24
  export const DEFAULT_DESTROY_DB_POLL_INTERVAL_MS = 5000;
22
25
  export const DEFAULT_DESTROY_SNAPSHOT_TIMEOUT_MS = 1800000;
@@ -120,6 +123,21 @@ export async function handleDestroyTerraformError({ options, tfDirPath, attemptD
120
123
  return namedFail('STATE_LOCK_HELD');
121
124
  }
122
125
 
126
+ // BUG-210: a drained bucket can still report versions when terraform
127
+ // runs (S3 empty-visibility race). Settle briefly, then retry the
128
+ // destroy exactly once — a second BucketNotEmpty is terminal.
129
+ if (code === 'BUCKET_NOT_EMPTY') {
130
+ trackEvent('bucket_not_empty_retry', { projectName: actualProjectName, command: 'destroy' });
131
+ const sleepFn = typeof options.sleepFn === 'function' ? options.sleepFn : sleep;
132
+ await sleepFn(DEFAULT_DESTROY_NOTEMPTY_RETRY_SETTLE_MS);
133
+ try {
134
+ await attemptDestroy();
135
+ } catch (retryError) {
136
+ return namedFail('BUCKET_NOT_EMPTY');
137
+ }
138
+ return { retried: true };
139
+ }
140
+
123
141
  if (code === 'BACKEND_RECONFIGURE_REQUIRED' || code === 'DESTROY_DEPENDENCY_VIOLATION'
124
142
  || code === 'CLOUDFRONT_IN_PROGRESS' || code === 'DELETION_PROTECTION_ACTIVE') {
125
143
  return namedFail(code);
@@ -555,7 +573,7 @@ async function destroyStackMain(input = {}) {
555
573
  const drainTargets = (await getTerraformStateBuckets(tfDirPath)).filter((name) => name !== bucketName);
556
574
  if (drainTargets.length > 0) {
557
575
  s.start(`Draining ${drainTargets.length} S3 bucket(s) before destroy...`);
558
- const drainClient = new S3Client({ region });
576
+ const drainClient = resolveClient(options.s3Client, S3Client, { region });
559
577
  let drainedObjects = 0;
560
578
  const drainFailures = [];
561
579
  for (const target of drainTargets) {
@@ -595,6 +613,42 @@ async function destroyStackMain(input = {}) {
595
613
  resultExtra: { region },
596
614
  });
597
615
  }
616
+ // BUG-210: versioned deletes can lag S3's empty-reads, so
617
+ // verify each drained bucket reads empty before terraform
618
+ // destroy runs — otherwise destroy flakes on BucketNotEmpty.
619
+ // A bucket deleted out-of-band counts as empty.
620
+ const settleTimeoutMs = options.drainSettleTimeoutMs ?? DEFAULT_DESTROY_DRAIN_SETTLE_TIMEOUT_MS;
621
+ const settleIntervalMs = options.drainSettleIntervalMs ?? DEFAULT_DESTROY_DRAIN_SETTLE_INTERVAL_MS;
622
+ for (const target of drainTargets) {
623
+ const settled = await pollUntil({
624
+ timeoutMs: settleTimeoutMs,
625
+ intervalMs: settleIntervalMs,
626
+ onTick: async () => {
627
+ let listed;
628
+ try {
629
+ listed = await drainClient.send(new ListObjectVersionsCommand({ Bucket: target, MaxKeys: 1 }));
630
+ } catch (error) {
631
+ if (error?.name === 'NoSuchBucket') return { done: true };
632
+ throw error;
633
+ }
634
+ const remaining = (listed.Versions || []).length + (listed.DeleteMarkers || []).length;
635
+ return remaining === 0 ? { done: true } : null;
636
+ },
637
+ });
638
+ if (!settled.done) {
639
+ s.stop(color.red('❌ S3 bucket drain failed.'));
640
+ return failCommand({
641
+ message: `\n✖ S3 bucket ${target} still reports object versions after draining.`,
642
+ hint: ' Re-run destroy (drained buckets usually read empty within a minute), or empty the bucket by hand in the AWS Console.\n',
643
+ useErrorStream: true,
644
+ event: 'infrastructure_destroyed',
645
+ telemetry: { projectName: projectNameForTelemetry },
646
+ errorCode: 'BUCKET_DRAIN_UNSETTLED',
647
+ reason: 'bucket-drain-unsettled',
648
+ resultExtra: { bucket: target, region },
649
+ });
650
+ }
651
+ }
598
652
  s.stop(`Drained ${drainedObjects} object(s) from ${drainTargets.length} bucket(s).`);
599
653
  trackEvent('bucket_drain_completed', {
600
654
  projectName: projectNameForTelemetry,
@@ -1,5 +1,6 @@
1
1
  import fsSync from 'fs';
2
2
  import path from 'path';
3
+ import { execSync } from 'child_process';
3
4
  import { intro, outro, spinner, log, confirm, multiselect, select, cancel, isCancel } from '@clack/prompts';
4
5
  import color from 'picocolors';
5
6
 
@@ -114,20 +115,52 @@ export function renderOidcSubClaim(sub) {
114
115
  return `["${sub}", "${companion}"]`;
115
116
  }
116
117
 
118
+ // Renders a list of classic subs as an HCL fragment with each entry's
119
+ // immutable-claim companion, deduplicated. A single entry renders
120
+ // byte-identical to renderOidcSubClaim.
121
+ function renderOidcSubList(subs) {
122
+ const companions = [];
123
+ for (const sub of subs) {
124
+ const companion = immutableCompanion(sub);
125
+ if (companion !== null) companions.push(companion);
126
+ }
127
+ return `[${[...new Set([...subs, ...companions])].map((entry) => `"${entry}"`).join(', ')}]`;
128
+ }
129
+
130
+ // Detects the repo's default branch (where scheduled workflows run) from
131
+ // origin/HEAD, falling back to the deploy branch when git is absent,
132
+ // has no origin, or never set HEAD. execSyncImpl is injectable for tests.
133
+ export function resolveDefaultBranch(targetDir, deployBranch, execSyncImpl = execSync) {
134
+ try {
135
+ const head = execSyncImpl('git symbolic-ref --short refs/remotes/origin/HEAD', { cwd: targetDir, stdio: 'pipe' }).toString().trim();
136
+ const branch = head.startsWith('origin/') ? head.slice('origin/'.length) : '';
137
+ if (branch !== '') return branch;
138
+ } catch {
139
+ // Fall through to the deploy branch.
140
+ }
141
+ return deployBranch;
142
+ }
143
+
117
144
  // Renders both CI roles' trust claims as HCL fragments from the resolved
118
145
  // repo trust: the deploy role binds to the effective deploy branch (the
119
146
  // same value rendered into the deploy trigger, so the two stay in sync),
120
- // the preview role binds to pull request events. The open trust and
121
- // hand-customized claims render verbatim — never silently widened.
122
- export function renderOidcRoleSubs(resolvedSub, deployBranch) {
147
+ // the preview role binds to pull request events. BUG-209: scheduled drift
148
+ // runs on the default branch, so when it differs from the deploy branch
149
+ // the deploy role trusts both refs. The open trust and hand-customized
150
+ // claims render verbatim — never silently widened.
151
+ export function renderOidcRoleSubs(resolvedSub, deployBranch, defaultBranch = deployBranch) {
123
152
  const match = typeof resolvedSub === 'string' && resolvedSub.match(/^repo:([^:]+\/[^:]+)(?::(.*))?$/);
124
153
  if (!match) return { deploySub: renderOidcSubClaim(resolvedSub), previewSub: renderOidcSubClaim(resolvedSub) };
125
154
  const [, slug, rest] = match;
126
155
  const preview = `repo:${slug}:pull_request`;
127
- const deploy = rest === undefined || rest === '*' || rest.startsWith('ref:refs/heads/')
128
- ? `repo:${slug}:ref:refs/heads/${deployBranch}`
129
- : resolvedSub;
130
- return { deploySub: renderOidcSubClaim(deploy), previewSub: renderOidcSubClaim(preview) };
156
+ if (rest === undefined || rest === '*' || rest.startsWith('ref:refs/heads/')) {
157
+ const refs = [`repo:${slug}:ref:refs/heads/${deployBranch}`];
158
+ if (typeof defaultBranch === 'string' && defaultBranch !== '' && defaultBranch !== deployBranch) {
159
+ refs.push(`repo:${slug}:ref:refs/heads/${defaultBranch}`);
160
+ }
161
+ return { deploySub: renderOidcSubList(refs), previewSub: renderOidcSubClaim(preview) };
162
+ }
163
+ return { deploySub: renderOidcSubClaim(resolvedSub), previewSub: renderOidcSubClaim(preview) };
131
164
  }
132
165
 
133
166
  // Centralized CI role-name construction (R1): the deploy/preview role
@@ -160,6 +193,22 @@ export function buildRoleArn(accountId, roleName) {
160
193
  // dual-format pair resolves back to its classic entry so re-init stays
161
194
  // stable; anything richer is described for warnings and guarded against
162
195
  // silent widening.
196
+ // Recognizes our own canonical dual-branch trust (BUG-209): two classic
197
+ // branch refs for one slug plus each entry's immutable companion, in
198
+ // render order. Returns { deploySub, branches } or null.
199
+ function parseCanonicalDualTrust(entries) {
200
+ const [first, second, third, fourth] = entries;
201
+ if (immutableCompanion(first) !== third || immutableCompanion(second) !== fourth) return null;
202
+ const branchOf = (entry) => {
203
+ const match = typeof entry === 'string' && entry.match(/^repo:([^:]+):ref:refs\/heads\/(.+)$/);
204
+ return match ? { slug: match[1], branch: match[2] } : null;
205
+ };
206
+ const a = branchOf(first);
207
+ const b = branchOf(second);
208
+ if (!a || !b || a.slug !== b.slug || a.branch === b.branch) return null;
209
+ return { deploySub: first, branches: [a.branch, b.branch] };
210
+ }
211
+
163
212
  function classifyTreeTrust(claim) {
164
213
  if (!claim) return { trust: null, complex: null };
165
214
  if (claim.kind === 'string') return { trust: claim.value, complex: null };
@@ -170,6 +219,10 @@ function classifyTreeTrust(claim) {
170
219
  && immutableCompanion(claim.entries[0]) === claim.entries[1]) {
171
220
  return { trust: claim.entries[0], complex: null };
172
221
  }
222
+ if (claim.kind === 'list' && claim.entries.length === 4) {
223
+ const dual = parseCanonicalDualTrust(claim.entries);
224
+ if (dual) return { trust: dual.deploySub, complex: null, branches: dual.branches };
225
+ }
173
226
  if (claim.kind === 'list') {
174
227
  const entries = claim.entries.length > 0 ? ` (${claim.entries.join(', ')})` : '';
175
228
  return { trust: null, complex: `${claim.entries.length}-entry list${entries}` };
@@ -197,7 +250,7 @@ export async function resolveOidcTrust({
197
250
  const answer = await confirm({ message, initialValue: false });
198
251
  return answer === true && !isCancel(answer);
199
252
  });
200
- const { trust: treeTrust, complex: complexClaim } = classifyTreeTrust(treeClaim);
253
+ const { trust: treeTrust, complex: complexClaim, branches: treeBranches } = classifyTreeTrust(treeClaim);
201
254
  if (explicitSlug) {
202
255
  if (complexClaim) {
203
256
  log(color.yellow(`⚠️ --github-repo replaces this tree's ${complexClaim} — the next apply trusts ${explicitSlug} only.`));
@@ -210,7 +263,7 @@ export async function resolveOidcTrust({
210
263
  if (treeTrust === 'repo:*') {
211
264
  log(color.yellow('⚠️ Keeping this tree\'s open CI trust (repo:*): any GitHub repo\'s Actions can assume the deploy role. Re-scope with --github-repo owner/name before going live.'));
212
265
  }
213
- return { sub: treeTrust, source: 'tree' };
266
+ return { sub: treeTrust, source: 'tree', ...(treeBranches ? { treeBranches } : {}) };
214
267
  }
215
268
  const remoteSlug = readRemote(targetDir);
216
269
  if (remoteSlug) {
@@ -909,7 +962,18 @@ async function mainStackMain(input = {}) {
909
962
 
910
963
  // 7. Synthesize Templates
911
964
  s.message('Synthesizing Terraform templates...');
912
- const { deploySub, previewSub } = renderOidcRoleSubs(oidcTrustSub, config.branch);
965
+ // BUG-209: live origin/HEAD wins when it names a real branch; when
966
+ // detection falls back, a re-init keeps the tree's own default branch
967
+ // so dual trust never narrows silently.
968
+ const treeDefaultBranch = oidcResolution.treeBranches?.[1] ?? null;
969
+ const detectedDefaultBranch = resolveDefaultBranch(dirConfig.targetDir, config.branch);
970
+ const defaultBranch = detectedDefaultBranch !== config.branch
971
+ ? detectedDefaultBranch
972
+ : (treeDefaultBranch ?? config.branch);
973
+ if (defaultBranch !== config.branch && treeDefaultBranch === null) {
974
+ log(color.yellow(`⚠️ Trusting default branch "${defaultBranch}" alongside deploy branch "${config.branch}" so scheduled drift can assume the deploy role.`));
975
+ }
976
+ const { deploySub, previewSub } = renderOidcRoleSubs(oidcTrustSub, config.branch, defaultBranch);
913
977
  const renderConfig = {
914
978
  PROJECT_NAME: dirConfig.actualProjectName,
915
979
  RESOURCE_SUFFIX: resourceSuffix,
@@ -1,4 +1,5 @@
1
1
  import path from 'path';
2
+ import fsSync from 'fs';
2
3
  import { text, select, multiselect, confirm, group, cancel } from '@clack/prompts';
3
4
  import color from 'picocolors';
4
5
  import { execSync } from 'child_process';
@@ -89,8 +90,20 @@ export async function getProjectConfig(isHeadless, headlessOptions, targetDir, d
89
90
  const skipsContainerSizing = hints && typeof hints === 'object'
90
91
  && (hints.target === 'lambda' || hints.target === 'static');
91
92
  if (isHeadless) {
93
+ // BUG-211: an undetectable framework with a package.json present is
94
+ // a plain-Node project, not a static site — defaulting to 'static'
95
+ // renders an nginx Dockerfile that can neither build scriptless
96
+ // projects nor run node payloads. No package.json keeps 'static'.
97
+ let headlessFramework = headlessOptions.framework || (detectedFramework ? detectedFramework.id : null);
98
+ if (!headlessFramework) {
99
+ try {
100
+ headlessFramework = fsSync.existsSync(path.join(targetDir, 'package.json')) ? 'node' : 'static';
101
+ } catch {
102
+ headlessFramework = 'static';
103
+ }
104
+ }
92
105
  return {
93
- framework: headlessOptions.framework || (detectedFramework ? detectedFramework.id : 'static'),
106
+ framework: headlessFramework,
94
107
  region: headlessOptions.region || 'us-east-2',
95
108
  port: headlessOptions.port || (headlessOptions.framework === 'static' ? '8080' : '3000'),
96
109
  size: headlessOptions.size || 'micro',
@@ -12,6 +12,7 @@ export const ERROR_CODES = [
12
12
  'RECREATE_COLLISION',
13
13
  'OIDC_PROVIDER_CONFLICT',
14
14
  'CLOUDFRONT_IN_PROGRESS',
15
+ 'BUCKET_NOT_EMPTY',
15
16
  ];
16
17
 
17
18
  // AWS AlreadyExists family: every create-path "reality has what state
@@ -63,6 +64,9 @@ export function classifyTerraformError(stderr, ctx = {}) {
63
64
  if (/cloudfront/i.test(text) && /in.?progress|in use|precondition/i.test(text)) {
64
65
  return { code: 'CLOUDFRONT_IN_PROGRESS', lockId: null };
65
66
  }
67
+ if (/BucketNotEmpty/i.test(text)) {
68
+ return { code: 'BUCKET_NOT_EMPTY', lockId: null };
69
+ }
66
70
  return null;
67
71
  }
68
72
 
@@ -107,6 +111,11 @@ const RUNBOOKS = {
107
111
  headless: 'Wait 5–15 minutes for the distribution to settle, then re-run the same command.',
108
112
  interactive: 'Wait 5–15 minutes for the distribution to settle, then re-run the same command.',
109
113
  },
114
+ BUCKET_NOT_EMPTY: {
115
+ message: 'S3 buckets still report object versions after draining.',
116
+ headless: 'Re-run destroy — drained buckets usually read empty within a minute; if it persists, empty the bucket by hand in the AWS Console.',
117
+ interactive: 'Re-run destroy — drained buckets usually read empty within a minute; if it persists, empty the bucket by hand in the AWS Console.',
118
+ },
110
119
  };
111
120
 
112
121
  // Returns `{ message, hint }` for a named code, or null for unknown
@@ -122,6 +122,7 @@ jobs:
122
122
  const body = `${marker}\n${heading}\n\n**${summary}** ([workflow run](${runUrl})).\n\n<details><summary>Show Plan</summary>\n\n\`\`\`diff\n${plan}\n\`\`\`\n\n</details>`;
123
123
  const { data: comments } = await github.rest.issues.listComments({
124
124
  issue_number: context.issue.number,
125
+ per_page: 100,
125
126
  owner: context.repo.owner,
126
127
  repo: context.repo.repo,
127
128
  });
@@ -129,6 +129,7 @@ jobs:
129
129
  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>`;
130
130
  const { data: comments } = await github.rest.issues.listComments({
131
131
  issue_number: context.issue.number,
132
+ per_page: 100,
132
133
  owner: context.repo.owner,
133
134
  repo: context.repo.repo,
134
135
  });
@@ -159,6 +160,7 @@ jobs:
159
160
  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.`;
160
161
  const { data: comments } = await github.rest.issues.listComments({
161
162
  issue_number: context.issue.number,
163
+ per_page: 100,
162
164
  owner: context.repo.owner,
163
165
  repo: context.repo.repo,
164
166
  });
@@ -178,6 +178,22 @@ resource "aws_iam_role_policy" "preview_guardrails" {
178
178
  Action = ["iam:CreateUser", "iam:CreateAccessKey"]
179
179
  Resource = "*"
180
180
  },
181
+ {
182
+ # BUG-207: the preview role carries IAMFullAccess, so without this
183
+ # statement it can delete its own guardrails, delete the deploy
184
+ # role, or widen trust in one call. Scoped to the CI role ARNs
185
+ # (not *): preview stacks legitimately manage their own
186
+ # pr-suffixed IAM roles. The deploy role keeps full IAM power on
187
+ # purpose — it runs on the trusted branch and needs it for the
188
+ # re-init trust migration.
189
+ Sid = "DenyCIRoleMutation"
190
+ Effect = "Deny"
191
+ Action = ["iam:DeleteRole", "iam:UpdateAssumeRolePolicy", "iam:PutRolePolicy", "iam:DeleteRolePolicy", "iam:AttachRolePolicy", "iam:DetachRolePolicy"]
192
+ Resource = [
193
+ aws_iam_role.github_actions_deploy[0].arn,
194
+ aws_iam_role.github_actions_preview[0].arn,
195
+ ]
196
+ },
181
197
  {
182
198
  Sid = "DenySnapshotSharing"
183
199
  Effect = "Deny"
@@ -200,7 +216,7 @@ resource "aws_iam_role_policy" "preview_guardrails" {
200
216
  Resource = [
201
217
  "arn:aws:ecs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:cluster/${local.prod_prefix}-cluster",
202
218
  "arn:aws:ecs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:service/${local.prod_prefix}-cluster/${local.prod_prefix}-service",
203
- "arn:aws:ecs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:service/${local.prod_prefix}-service",
219
+ "arn:aws:ecs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:service/${local.prod_prefix}-cluster/${local.prod_prefix}-worker-service",
204
220
  ]
205
221
  },
206
222
  {
@@ -253,6 +269,40 @@ resource "aws_iam_role_policy" "preview_guardrails" {
253
269
  "arn:aws:dynamodb:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:table/${local.prod_prefix}-table",
254
270
  ]
255
271
  },
272
+ {
273
+ # BUG-208: manual snapshots (grada names them
274
+ # <db-identifier>-manual-<stamp>) are directly deletable;
275
+ # automated snapshots can only go away via retention changes or
276
+ # instance deletion, both already denied above.
277
+ Sid = "DenyProdSnapshotDeletion"
278
+ Effect = "Deny"
279
+ Action = ["rds:DeleteDBSnapshot", "rds:DeleteDBClusterSnapshot"]
280
+ Resource = [
281
+ "arn:aws:rds:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:snapshot:${local.prod_prefix}-db-*",
282
+ "arn:aws:rds:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:cluster-snapshot:${local.prod_prefix}-db-cluster-*",
283
+ ]
284
+ },
285
+ {
286
+ # The vault ARN carries a random suffix and static trees have no
287
+ # vault at all (no secrets.tf), so match the tight name prefix —
288
+ # on static it simply matches nothing.
289
+ Sid = "DenyProdSecretsDeletion"
290
+ Effect = "Deny"
291
+ Action = ["secretsmanager:DeleteSecret"]
292
+ Resource = [
293
+ "arn:aws:secretsmanager:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:secret:${local.prod_prefix}-secrets-*",
294
+ ]
295
+ },
296
+ {
297
+ # Web and worker containers share one log group; deleting it
298
+ # wipes the audit trail for both.
299
+ Sid = "DenyProdLogDeletion"
300
+ Effect = "Deny"
301
+ Action = ["logs:DeleteLogGroup"]
302
+ Resource = [
303
+ "arn:aws:logs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:log-group:/ecs/${local.prod_prefix}",
304
+ ]
305
+ },
256
306
  ]
257
307
  })
258
308
  }