grada-run 0.49.6 → 0.49.7

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.6",
3
+ "version": "0.49.7",
4
4
  "description": "Provision production-ready AWS infrastructure and CI/CD pipelines in seconds.",
5
5
  "engines": {
6
6
  "node": ">=18.0.0"
@@ -708,6 +708,7 @@ async function applyStackMain(input = {}) {
708
708
  const classified = classifyTerraformError(errString, { postRecovery: options._postRecovery === true });
709
709
  const code = structuredCode || classified?.code || null;
710
710
  const lockId = error.lockId || classified?.lockId || null;
711
+ const secretName = classified?.secretName || null;
711
712
 
712
713
  if (code === 'STATE_BUCKET_MISSING' && options._postRecovery === true) {
713
714
  // The bucket is still missing after a recreate: refuse instead
@@ -943,7 +944,7 @@ async function applyStackMain(input = {}) {
943
944
  }
944
945
  }
945
946
  }
946
- const runbook = getRunbook(code, { headless: shouldAutoApprove(options), lockId });
947
+ const runbook = getRunbook(code, { headless: shouldAutoApprove(options), lockId, secretName });
947
948
  log.error(color.red(`✖ ${runbook.message}`));
948
949
  log.message(` ${runbook.hint}\n`);
949
950
  if (reconfigureError) {
@@ -15,7 +15,7 @@ import { findDbTarget, dbStatusOf, resolveDbIdentifier, resolveDbClusterIdentifi
15
15
  import { requireManagedTree, parseStateBucketBackend } from '../utils/terraform-metadata.js';
16
16
  import { guardSleepingEnv } from '../utils/sleep-state.js';
17
17
  import { normalizeOptions, parseFlags, normalizeArgv } from '../utils/args.js';
18
- import { resolveHeadless } from '../utils/resolvers.js';
18
+ import { resolveHeadless, readTerraformProjectName, readResourceSuffix } from '../utils/resolvers.js';
19
19
  import { truncateSpinnerText } from '../utils/spinner-text.js';
20
20
 
21
21
  export const DEFAULT_DESTROY_DB_TIMEOUT_MS = 600000;
@@ -59,13 +59,18 @@ export function parseDestroyArgs(argv = []) {
59
59
  // Returns `{ retried: true }` when the destroy recovered so the caller
60
60
  // continues to bucket cleanup, else `{ retried: false, result }`.
61
61
  // Exported for unit tests: every branch must honor this contract.
62
- async function describeDependencyBlockers(ec2, projectName) {
63
- const { Vpcs = [] } = await ec2.send(new DescribeVpcsCommand({
64
- Filters: [
65
- { Name: 'tag:ManagedBy', Values: ['grada'] },
66
- { Name: 'tag:GradaProject', Values: [projectName] },
67
- ],
68
- }));
62
+ async function describeDependencyBlockers(ec2, projectName, vpcName) {
63
+ // Preview workspaces share the GradaProject tag, so the project
64
+ // filter alone matches every preview VPC too — the exact prod
65
+ // Name narrows to the destroy target. Without a readable tree
66
+ // there is no Name, and the single-VPC length check below keeps
67
+ // the legacy behavior.
68
+ const filters = [
69
+ { Name: 'tag:ManagedBy', Values: ['grada'] },
70
+ { Name: 'tag:GradaProject', Values: [projectName] },
71
+ ];
72
+ if (vpcName) filters.push({ Name: 'tag:Name', Values: [vpcName] });
73
+ const { Vpcs = [] } = await ec2.send(new DescribeVpcsCommand({ Filters: filters }));
69
74
  if (Vpcs.length !== 1 || !Vpcs[0].VpcId) return null;
70
75
  const vpcId = Vpcs[0].VpcId;
71
76
  const [niResp, sgResp] = await Promise.all([
@@ -181,7 +186,21 @@ export async function handleDestroyTerraformError({ options, tfDirPath, attemptD
181
186
  let ec2 = null;
182
187
  try {
183
188
  ec2 = resolveClient(options.ec2Client, EC2Client, { region: region ?? process.env.AWS_REGION ?? 'us-east-2' });
184
- blockers = await describeDependencyBlockers(ec2, actualProjectName);
189
+ // Rendered names beat the directory basename: the TF
190
+ // project + suffix pin the exact prod VPC Name, and
191
+ // unreadable trees fall back to basename matching.
192
+ let tagProject = actualProjectName;
193
+ let vpcName = null;
194
+ try {
195
+ const tfProject = readTerraformProjectName();
196
+ if (tfProject) {
197
+ tagProject = tfProject;
198
+ vpcName = `${tfProject}${readResourceSuffix()}-vpc`;
199
+ }
200
+ } catch {
201
+ // fall through with basename matching
202
+ }
203
+ blockers = await describeDependencyBlockers(ec2, tagProject, vpcName);
185
204
  } catch {
186
205
  blockers = null;
187
206
  }
@@ -89,7 +89,8 @@ export function classifyTerraformError(stderr, ctx = {}) {
89
89
  // Disjoint from the collision family ("already scheduled for
90
90
  // deletion" carries no AlreadyExists marker).
91
91
  if (/scheduled for deletion/i.test(text)) {
92
- return { code: 'SECRET_PENDING_DELETION', lockId: null };
92
+ const nameMatch = /Secrets Manager Secret \(([^)]+)\)/.exec(text);
93
+ return { code: 'SECRET_PENDING_DELETION', lockId: null, secretName: nameMatch ? nameMatch[1] : null };
93
94
  }
94
95
  if (/NoSuchBucket/i.test(text) || /does not exist/i.test(text)) {
95
96
  return { code: 'STATE_BUCKET_MISSING', lockId: null };
@@ -160,8 +161,8 @@ const RUNBOOKS = {
160
161
  },
161
162
  SECRET_PENDING_DELETION: {
162
163
  message: 'A Secrets Manager secret is scheduled for deletion.',
163
- headless: 'Restore it (aws secretsmanager restore-secret --secret-id <name>, then cd terraform && terraform import <address> <id>) or force-delete without recovery and re-apply + push — grada never force-deletes, the window protects against accidental loss.',
164
- interactive: 'Restore it (aws secretsmanager restore-secret --secret-id <name>, then cd terraform && terraform import <address> <id>) or force-delete without recovery and re-apply + push — grada never force-deletes, the window protects against accidental loss.',
164
+ headless: 'Restore it (aws secretsmanager restore-secret --secret-id <name>, then cd terraform && terraform import aws_secretsmanager_secret.app_secrets <arn>) or force-delete without recovery (aws secretsmanager delete-secret --secret-id <name> --force-delete-without-recovery) and re-apply + push — fetch the ARN via aws secretsmanager describe-secret --secret-id <name> --query ARN --output text. Grada never force-deletes: the window protects against accidental loss.',
165
+ interactive: 'Restore it (aws secretsmanager restore-secret --secret-id <name>, then cd terraform && terraform import aws_secretsmanager_secret.app_secrets <arn>) or force-delete without recovery (aws secretsmanager delete-secret --secret-id <name> --force-delete-without-recovery) and re-apply + push — fetch the ARN via aws secretsmanager describe-secret --secret-id <name> --query ARN --output text. Grada never force-deletes: the window protects against accidental loss.',
165
166
  },
166
167
  };
167
168
 
@@ -169,12 +170,15 @@ const RUNBOOKS = {
169
170
  // codes. `headless` selects the variant; `lockId` fills the interactive
170
171
  // lock runbook. Resource identifiers stay in the rendered hint (stdout),
171
172
  // never in telemetry payloads.
172
- export function getRunbook(code, { headless = false, lockId = null } = {}) {
173
+ export function getRunbook(code, { headless = false, lockId = null, secretName = null } = {}) {
173
174
  const runbook = RUNBOOKS[code];
174
175
  if (!runbook) return null;
175
176
  let hint = headless ? runbook.headless : runbook.interactive;
176
177
  if (code === 'STATE_LOCK_HELD' && lockId) {
177
178
  hint = hint.replace(/<lock-id>/g, String(lockId));
178
179
  }
180
+ if (code === 'SECRET_PENDING_DELETION' && secretName) {
181
+ hint = hint.replace(/<name>/g, String(secretName));
182
+ }
179
183
  return { message: runbook.message, hint };
180
184
  }