grada-run 0.40.16 → 0.41.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.
- package/bin/cli.js +22 -18
- package/package.json +1 -1
- package/src/commands/add.js +25 -8
- package/src/commands/alerts.js +6 -3
- package/src/commands/apply.js +119 -8
- package/src/commands/db/backup.js +5 -2
- package/src/commands/db/connect.js +6 -3
- package/src/commands/db/enable-vector.js +5 -2
- package/src/commands/db/import.js +5 -2
- package/src/commands/db/migrate.js +5 -2
- package/src/commands/db/restore.js +5 -2
- package/src/commands/destroy.js +6 -3
- package/src/commands/doctor.js +44 -25
- package/src/commands/domain.js +5 -2
- package/src/commands/drift.js +19 -3
- package/src/commands/eject.js +5 -2
- package/src/commands/exec.js +6 -2
- package/src/commands/gc.js +87 -17
- package/src/commands/init.js +8 -3
- package/src/commands/logs.js +6 -2
- package/src/commands/mcp.js +5 -2
- package/src/commands/rollback.js +6 -3
- package/src/commands/sleep.js +5 -2
- package/src/commands/status.js +6 -2
- package/src/commands/wake.js +6 -3
- package/src/core/parser.js +25 -7
- package/src/utils/args.js +11 -5
- package/src/utils/aws.js +38 -26
- package/src/utils/command.js +20 -0
- package/src/utils/file-lock.js +0 -22
- package/src/utils/hcl.js +27 -2
- package/src/utils/reconcile.js +40 -0
- package/templates/github/preview.yml +4 -3
- package/templates/github/teardown.yml +5 -2
package/src/commands/doctor.js
CHANGED
|
@@ -6,6 +6,7 @@ import { S3Client, ListObjectsV2Command, GetObjectCommand } from '@aws-sdk/clien
|
|
|
6
6
|
import { checkDependency } from '../utils/system.js';
|
|
7
7
|
import { checkAwsCredentials, TROUBLESHOOTING_URL } from '../utils/aws.js';
|
|
8
8
|
import { readLastRunMarker, isInterruptedMarker } from '../utils/terraform.js';
|
|
9
|
+
import { refuseUnknownFlags } from '../utils/command.js';
|
|
9
10
|
import { readTerraformOidcTrust } from '../utils/resolvers.js';
|
|
10
11
|
import { parseStateBucketBackend } from '../utils/terraform-metadata.js';
|
|
11
12
|
import { normalizeOptions, parseFlags, normalizeArgv } from '../utils/args.js';
|
|
@@ -154,40 +155,52 @@ async function checkStateLock({ cwd, s3Client, deep }) {
|
|
|
154
155
|
const keyMatch = backend.match(/key\s*=\s*"([^"]+)"/);
|
|
155
156
|
const stateKey = keyMatch ? keyMatch[1] : 'terraform.tfstate';
|
|
156
157
|
const client = s3Client ?? new S3Client({ region: region ?? 'us-east-2' });
|
|
157
|
-
|
|
158
|
+
// Workspace states live under `env:/<name>/`, outside the default key
|
|
159
|
+
// prefix — list both so a stuck preview lock surfaces with its
|
|
160
|
+
// workspace instead of reporting a false "no lock".
|
|
161
|
+
const lockKeys = [];
|
|
158
162
|
try {
|
|
159
|
-
|
|
160
|
-
|
|
163
|
+
for (const prefix of [stateKey, 'env:/']) {
|
|
164
|
+
const resp = await client.send(new ListObjectsV2Command({ Bucket: bucket, Prefix: prefix }));
|
|
165
|
+
for (const entry of resp.Contents || []) {
|
|
166
|
+
if (typeof entry.Key === 'string' && entry.Key.endsWith('.tflock')) lockKeys.push(entry.Key);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
161
169
|
} catch (error) {
|
|
162
170
|
if (error?.name === 'NoSuchBucket') return { ok: true, note: 'state bucket absent' };
|
|
163
171
|
return { ok: true, skipped: 'state bucket unreachable' };
|
|
164
172
|
}
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
173
|
+
const uniqueLocks = [...new Set(lockKeys)];
|
|
174
|
+
if (uniqueLocks.length === 0) return { ok: true };
|
|
175
|
+
const detailLines = [];
|
|
176
|
+
for (const lockKey of uniqueLocks) {
|
|
177
|
+
detailLines.push(`Lock file ${lockKey} is present in the state bucket${workspaceSuffix(lockKey)}.`);
|
|
178
|
+
if (deep) {
|
|
179
|
+
try {
|
|
180
|
+
const obj = await client.send(new GetObjectCommand({ Bucket: bucket, Key: lockKey }));
|
|
181
|
+
const text = typeof obj.Body?.transformToString === 'function'
|
|
182
|
+
? await obj.Body.transformToString()
|
|
183
|
+
: '';
|
|
184
|
+
const info = JSON.parse(text);
|
|
185
|
+
const who = info.Who ?? info.who ?? 'unknown holder';
|
|
186
|
+
const operation = info.Operation ?? info.operation ?? 'unknown operation';
|
|
187
|
+
const created = info.Created ?? info.created ?? 'unknown time';
|
|
188
|
+
detailLines.push(`Held by ${who} (${operation}, since ${created}).`);
|
|
189
|
+
} catch {
|
|
190
|
+
// The lock itself is the finding; holder detail is best-effort.
|
|
191
|
+
}
|
|
183
192
|
}
|
|
184
193
|
}
|
|
185
194
|
return { ok: false, detailLines };
|
|
186
195
|
}
|
|
187
196
|
|
|
188
|
-
//
|
|
189
|
-
//
|
|
190
|
-
|
|
197
|
+
// `env:/pr-12/terraform.tfstate.tflock` → ` (workspace pr-12)`; the
|
|
198
|
+
// default key reports bare, as before.
|
|
199
|
+
function workspaceSuffix(lockKey) {
|
|
200
|
+
const match = /^env:\/([^/]+)\//.exec(lockKey);
|
|
201
|
+
return match ? ` (workspace ${match[1]})` : '';
|
|
202
|
+
}
|
|
203
|
+
|
|
191
204
|
// Project check: an open `repo:*` OIDC trust lets any GitHub repo's
|
|
192
205
|
// Actions assume the deploy role. Warning-grade (pre-fix trees render it
|
|
193
206
|
// by default): surfaces yellow without flipping the verdict red. List
|
|
@@ -207,6 +220,9 @@ function checkOidcTrustScope({ cwd }) {
|
|
|
207
220
|
};
|
|
208
221
|
}
|
|
209
222
|
|
|
223
|
+
// Project check: a leftover interrupted/running marker means the last
|
|
224
|
+
// Terraform run never settled. Warning-grade (apply proceeds with its own
|
|
225
|
+
// warning): surfaces yellow without flipping the verdict red.
|
|
210
226
|
function checkInterruptedRun({ cwd }) {
|
|
211
227
|
const marker = readLastRunMarker(cwd);
|
|
212
228
|
if (!isInterruptedMarker(marker)) return { ok: true };
|
|
@@ -221,7 +237,8 @@ function checkInterruptedRun({ cwd }) {
|
|
|
221
237
|
export function parseDoctorArgs(argv = []) {
|
|
222
238
|
const args = normalizeArgv(argv);
|
|
223
239
|
if (args[0] === 'doctor') args.shift();
|
|
224
|
-
const { options } = parseFlags(args, { boolean: ['deep'] });
|
|
240
|
+
const { options, unknown } = parseFlags(args, { boolean: ['deep', 'headless'] });
|
|
241
|
+
if (unknown.length > 0) options.unknownFlags = unknown;
|
|
225
242
|
return { deep: false, ...options };
|
|
226
243
|
}
|
|
227
244
|
|
|
@@ -278,6 +295,8 @@ export async function runDoctor(input = {}) {
|
|
|
278
295
|
|
|
279
296
|
async function runDoctorMain(input = {}) {
|
|
280
297
|
const options = normalizeOptions(input);
|
|
298
|
+
const unknownRefusal = await refuseUnknownFlags(options, { command: 'doctor', event: 'doctor_run' });
|
|
299
|
+
if (unknownRefusal) return unknownRefusal;
|
|
281
300
|
const cwd = options.cwd ? path.resolve(String(options.cwd)) : process.cwd();
|
|
282
301
|
const deep = options.deep === true || options.deep === 'true';
|
|
283
302
|
const ctx = { cwd, s3Client: options.s3Client ?? null, deep };
|
package/src/commands/domain.js
CHANGED
|
@@ -6,7 +6,7 @@ import { intro, outro, confirm, cancel, isCancel } from '@clack/prompts';
|
|
|
6
6
|
import { trackSuccess, setActiveCommandName, resetActiveCommandName } from '../core/telemetry.js';
|
|
7
7
|
import { resolveProjectName, resolveHeadless, resolveCwd } from '../utils/resolvers.js';
|
|
8
8
|
import { parseFlags, normalizeOptions, normalizeArgv } from '../utils/args.js';
|
|
9
|
-
import { failCommand, failProjectNotInitialized, isProgrammaticCall, refuseIfNonInteractive } from '../utils/command.js';
|
|
9
|
+
import { failCommand, failProjectNotInitialized, isProgrammaticCall, refuseIfNonInteractive, refuseUnknownFlags } from '../utils/command.js';
|
|
10
10
|
import { getTerraformOutputs } from '../utils/terraform.js';
|
|
11
11
|
import {
|
|
12
12
|
findResourceBlock,
|
|
@@ -319,7 +319,7 @@ export function isCloudFrontWired(cloudfrontTfContent, domain) {
|
|
|
319
319
|
export function parseDomainArgs(argv = []) {
|
|
320
320
|
const args = normalizeArgv(argv);
|
|
321
321
|
if (args[0] === 'domain') args.shift();
|
|
322
|
-
const { options: parsed, rest } = parseFlags(args, {
|
|
322
|
+
const { options: parsed, rest, unknown } = parseFlags(args, {
|
|
323
323
|
string: ['zone-id'],
|
|
324
324
|
boolean: ['force', 'activate', 'yes', { name: 'headless', key: 'isHeadless' }],
|
|
325
325
|
});
|
|
@@ -332,6 +332,7 @@ export function parseDomainArgs(argv = []) {
|
|
|
332
332
|
force: parsed.force === true,
|
|
333
333
|
yes: parsed.yes === true,
|
|
334
334
|
isHeadless: parsed.isHeadless === true,
|
|
335
|
+
...(unknown.length > 0 ? { unknownFlags: unknown } : {}),
|
|
335
336
|
};
|
|
336
337
|
}
|
|
337
338
|
|
|
@@ -377,6 +378,8 @@ export async function runDomain(input = {}) {
|
|
|
377
378
|
|
|
378
379
|
async function runDomainMain(input = {}) {
|
|
379
380
|
const options = normalizeOptions(input);
|
|
381
|
+
const unknownRefusal = await refuseUnknownFlags(options, { command: 'domain', event: 'domain_run' });
|
|
382
|
+
if (unknownRefusal) return unknownRefusal;
|
|
380
383
|
const noExit = isProgrammaticCall(options);
|
|
381
384
|
const subcommand = typeof options.subcommand === 'string' ? options.subcommand.trim().toLowerCase() : undefined;
|
|
382
385
|
|
package/src/commands/drift.js
CHANGED
|
@@ -5,7 +5,7 @@ import { fileURLToPath } from 'url';
|
|
|
5
5
|
import color from 'picocolors';
|
|
6
6
|
import { intro, outro, spinner } from '@clack/prompts';
|
|
7
7
|
import { trackSuccess, setActiveCommandName, resetActiveCommandName } from '../core/telemetry.js';
|
|
8
|
-
import { failCommand, failAwsError, failProjectNotInitialized, isProgrammaticCall } from '../utils/command.js';
|
|
8
|
+
import { failCommand, failAwsError, failProjectNotInitialized, isProgrammaticCall, refuseUnknownFlags } from '../utils/command.js';
|
|
9
9
|
import { parseFlags, normalizeOptions, normalizeArgv } from '../utils/args.js';
|
|
10
10
|
import { resolveRegion, resolveProjectName, resolveCwd, readFileSafe } from '../utils/resolvers.js';
|
|
11
11
|
|
|
@@ -20,15 +20,16 @@ export const MAX_SUMMARY_LINES = 60;
|
|
|
20
20
|
export function parseDriftArgs(argv = []) {
|
|
21
21
|
const args = normalizeArgv(argv);
|
|
22
22
|
if (args[0] === 'drift') args.shift();
|
|
23
|
-
const { options, rest } = parseFlags(args, {
|
|
23
|
+
const { options, rest, unknown } = parseFlags(args, {
|
|
24
24
|
string: ['region', 'project-name'],
|
|
25
|
-
boolean: ['setup', 'force'],
|
|
25
|
+
boolean: ['setup', 'force', 'headless'],
|
|
26
26
|
});
|
|
27
27
|
const positionals = rest.filter((arg) => typeof arg === 'string' && !arg.startsWith('-'));
|
|
28
28
|
// `drift init` is an alias for `drift --setup`.
|
|
29
29
|
if (positionals.includes('init') || positionals.includes('setup')) options.setup = true;
|
|
30
30
|
const others = positionals.filter((positional) => positional !== 'init' && positional !== 'setup');
|
|
31
31
|
if (others.length > 0) options.unexpectedPositionals = others;
|
|
32
|
+
if (unknown.length > 0) options.unknownFlags = unknown;
|
|
32
33
|
return options;
|
|
33
34
|
}
|
|
34
35
|
|
|
@@ -84,6 +85,8 @@ export async function runDrift(input = {}) {
|
|
|
84
85
|
|
|
85
86
|
async function runDriftMain(input = {}) {
|
|
86
87
|
const options = normalizeOptions(input);
|
|
88
|
+
const unknownRefusal = await refuseUnknownFlags(options, { command: 'drift', event: 'drift_run' });
|
|
89
|
+
if (unknownRefusal) return unknownRefusal;
|
|
87
90
|
const noExit = isProgrammaticCall(options);
|
|
88
91
|
let cwd;
|
|
89
92
|
let region;
|
|
@@ -206,6 +209,19 @@ async function runDriftMain(input = {}) {
|
|
|
206
209
|
encoding: 'utf8',
|
|
207
210
|
maxBuffer: 32 * 1024 * 1024,
|
|
208
211
|
});
|
|
212
|
+
if (planResult?.error?.code === 'ENOBUFS') {
|
|
213
|
+
s.stop(color.red('Terraform plan output too large.'));
|
|
214
|
+
return failCommand({
|
|
215
|
+
noExit,
|
|
216
|
+
message: '\n✖ terraform plan output exceeded the 32MB buffer.\n',
|
|
217
|
+
hint: ' Narrow the plan with -target, or run terraform plan directly for the full output.\n',
|
|
218
|
+
event: 'drift_run',
|
|
219
|
+
telemetry: { projectName, action: 'check' },
|
|
220
|
+
errorCode: 'TERRAFORM_PLAN_TOO_LARGE',
|
|
221
|
+
reason: 'terraform-plan-too-large',
|
|
222
|
+
resultExtra: { region },
|
|
223
|
+
});
|
|
224
|
+
}
|
|
209
225
|
const status = planResult?.status;
|
|
210
226
|
if (status === 0) {
|
|
211
227
|
s.stop(color.green('No drift.'));
|
package/src/commands/eject.js
CHANGED
|
@@ -3,7 +3,7 @@ import path from 'path';
|
|
|
3
3
|
import { intro, outro, confirm, spinner, cancel } from '@clack/prompts';
|
|
4
4
|
import color from 'picocolors';
|
|
5
5
|
import { trackEvent, flushTelemetry, setActiveCommandName, resetActiveCommandName } from '../core/telemetry.js';
|
|
6
|
-
import { failCommand, refuseIfNonInteractive, shouldAutoApprove } from '../utils/command.js';
|
|
6
|
+
import { failCommand, refuseIfNonInteractive, refuseUnknownFlags, shouldAutoApprove } from '../utils/command.js';
|
|
7
7
|
import { parseFlags, normalizeOptions, normalizeArgv } from '../utils/args.js';
|
|
8
8
|
import {
|
|
9
9
|
stripTerraformMetadata,
|
|
@@ -21,7 +21,8 @@ import { runWake } from './wake.js';
|
|
|
21
21
|
export function parseEjectArgs(argv = []) {
|
|
22
22
|
const args = normalizeArgv(argv);
|
|
23
23
|
if (args[0] === 'eject') args.shift();
|
|
24
|
-
const { options } = parseFlags(args, { boolean: ['force'] });
|
|
24
|
+
const { options, unknown } = parseFlags(args, { boolean: ['force', 'headless', 'yes'] });
|
|
25
|
+
if (unknown.length > 0) options.unknownFlags = unknown;
|
|
25
26
|
return { force: false, ...options };
|
|
26
27
|
}
|
|
27
28
|
|
|
@@ -57,6 +58,8 @@ export async function ejectStack(input = {}) {
|
|
|
57
58
|
|
|
58
59
|
async function ejectStackMain(input = {}) {
|
|
59
60
|
const options = normalizeOptions(input);
|
|
61
|
+
const unknownRefusal = await refuseUnknownFlags(options, { command: 'eject', event: 'project_ejected' });
|
|
62
|
+
if (unknownRefusal) return unknownRefusal;
|
|
60
63
|
intro(color.bgRed(color.white(' grada eject ⏏️ ')));
|
|
61
64
|
|
|
62
65
|
console.log(color.yellow('This will permanently decouple your infrastructure from the grada CLI.'));
|
package/src/commands/exec.js
CHANGED
|
@@ -4,7 +4,7 @@ import color from 'picocolors';
|
|
|
4
4
|
import { intro, outro, spinner } from '@clack/prompts';
|
|
5
5
|
import { trackEvent, flushTelemetry, trackSuccess, trackFailure, setActiveCommandName, resetActiveCommandName } from '../core/telemetry.js';
|
|
6
6
|
import { hasAwsCli, AWS_CLI_INSTALL_URL, isAuthError, handleAuthErrorBranch, resolveClient } from '../utils/aws.js';
|
|
7
|
-
import { failCommand, failAwsError, trackAwsFailure, failProjectNotInitialized, isProgrammaticCall } from '../utils/command.js';
|
|
7
|
+
import { failCommand, failAwsError, trackAwsFailure, failProjectNotInitialized, isProgrammaticCall, refuseUnknownFlags } from '../utils/command.js';
|
|
8
8
|
import { parseFlags, normalizeOptions, normalizeArgv } from '../utils/args.js';
|
|
9
9
|
import { resolveRegion, resolveProjectName, resolveCluster, resolveService, resolveCwd, guardComputeTarget } from '../utils/resolvers.js';
|
|
10
10
|
import {
|
|
@@ -34,12 +34,14 @@ export function resolveShellCommand(options = {}) {
|
|
|
34
34
|
export function parseExecArgs(argv = []) {
|
|
35
35
|
const args = normalizeArgv(argv);
|
|
36
36
|
if (args[0] === 'exec') args.shift();
|
|
37
|
-
const { options, rest } = parseFlags(args, {
|
|
37
|
+
const { options, rest, unknown } = parseFlags(args, {
|
|
38
38
|
string: ['cluster', 'service', 'container', 'command', 'region'],
|
|
39
|
+
boolean: ['headless'],
|
|
39
40
|
});
|
|
40
41
|
const positionals = rest.filter((arg) => typeof arg === 'string' && !arg.startsWith('-'));
|
|
41
42
|
if (positionals.length > 0 && !options.service) options.service = positionals[0];
|
|
42
43
|
if (positionals.length > 1) options.unexpectedPositionals = positionals.slice(1);
|
|
44
|
+
if (unknown.length > 0) options.unknownFlags = unknown;
|
|
43
45
|
return options;
|
|
44
46
|
}
|
|
45
47
|
|
|
@@ -94,6 +96,8 @@ export async function runExec(input = {}) {
|
|
|
94
96
|
|
|
95
97
|
async function runExecMain(input = {}) {
|
|
96
98
|
const options = normalizeOptions(input);
|
|
99
|
+
const unknownRefusal = await refuseUnknownFlags(options, { command: 'exec', event: 'exec_run' });
|
|
100
|
+
if (unknownRefusal) return unknownRefusal;
|
|
97
101
|
const noExit = isProgrammaticCall(options);
|
|
98
102
|
let cwd;
|
|
99
103
|
let region;
|
package/src/commands/gc.js
CHANGED
|
@@ -3,8 +3,8 @@ import path from 'path';
|
|
|
3
3
|
import { spawnSync } from 'child_process';
|
|
4
4
|
import { ECRClient, DescribeRepositoriesCommand, DescribeImagesCommand, BatchDeleteImageCommand } from '@aws-sdk/client-ecr';
|
|
5
5
|
import { CloudWatchLogsClient, DescribeLogGroupsCommand, DeleteLogGroupCommand } from '@aws-sdk/client-cloudwatch-logs';
|
|
6
|
-
import { ECSClient, ListServicesCommand } from '@aws-sdk/client-ecs';
|
|
7
|
-
import { EC2Client, DescribeAddressesCommand, ReleaseAddressCommand, DescribeVpcsCommand } from '@aws-sdk/client-ec2';
|
|
6
|
+
import { ECSClient, ListServicesCommand, DescribeServicesCommand } from '@aws-sdk/client-ecs';
|
|
7
|
+
import { EC2Client, DescribeAddressesCommand, ReleaseAddressCommand, DescribeVpcsCommand, DescribeSubnetsCommand } from '@aws-sdk/client-ec2';
|
|
8
8
|
import { SecretsManagerClient, ListSecretsCommand } from '@aws-sdk/client-secrets-manager';
|
|
9
9
|
import color from 'picocolors';
|
|
10
10
|
import { intro, outro, confirm, spinner, cancel } from '@clack/prompts';
|
|
@@ -12,7 +12,7 @@ import { trackEvent, flushTelemetry, trackSuccess, trackFailure, setActiveComman
|
|
|
12
12
|
import { parseFlags, normalizeOptions, normalizeArgv } from '../utils/args.js';
|
|
13
13
|
import { resolveRegion, resolveProjectName, resolveCluster, resolveCwd, isComputeTarget, readResourceSuffix } from '../utils/resolvers.js';
|
|
14
14
|
import { resolveClient } from '../utils/aws.js';
|
|
15
|
-
import { failCommand, failProjectNotInitialized, isProgrammaticCall, refuseIfNonInteractive, shouldAutoApprove } from '../utils/command.js';
|
|
15
|
+
import { failCommand, failProjectNotInitialized, isProgrammaticCall, refuseIfNonInteractive, refuseUnknownFlags, shouldAutoApprove } from '../utils/command.js';
|
|
16
16
|
import { parseStateBucketBackend } from '../utils/terraform-metadata.js';
|
|
17
17
|
|
|
18
18
|
export const CONFIRM_MESSAGE = 'Are you sure you want to permanently delete these orphaned resources? (y/N)';
|
|
@@ -22,10 +22,11 @@ export function parseGcArgs(argv = []) {
|
|
|
22
22
|
if (args[0] === 'gc') args.shift();
|
|
23
23
|
// --yes auto-confirms the delete prompt (explicit opt-in; the default
|
|
24
24
|
// path still prompts). --deep adds the report-only deep scan.
|
|
25
|
-
const { options } = parseFlags(args, {
|
|
25
|
+
const { options, unknown } = parseFlags(args, {
|
|
26
26
|
string: ['region', 'project-name'],
|
|
27
|
-
boolean: ['deep', 'yes'],
|
|
27
|
+
boolean: ['deep', 'yes', 'headless'],
|
|
28
28
|
});
|
|
29
|
+
if (unknown.length > 0) options.unknownFlags = unknown;
|
|
29
30
|
return options;
|
|
30
31
|
}
|
|
31
32
|
|
|
@@ -229,26 +230,75 @@ async function discoverUnattachedEips({ ec2Client, projectName }) {
|
|
|
229
230
|
// predicate — exact project tag only. Foreign and untagged VPCs land in
|
|
230
231
|
// reportOnly, never in deletable, so prefix lookalikes (`myapp-evil`)
|
|
231
232
|
// and legacy resources can never enter the deletion set.
|
|
232
|
-
|
|
233
|
+
// Live VPC ids behind running (or desired) ECS services: services →
|
|
234
|
+
// awsvpc subnets → VPCs. Fail-closed like the preview-log-group
|
|
235
|
+
// liveness: any client error resolves `unknown` instead of guessing.
|
|
236
|
+
export async function discoverLiveVpcIds({ ecsClient = null, cluster = null, ec2Client = null } = {}) {
|
|
237
|
+
const vpcIds = new Set();
|
|
238
|
+
try {
|
|
239
|
+
if (!ecsClient || !cluster || !ec2Client) return { vpcIds, unknown: false };
|
|
240
|
+
let nextToken;
|
|
241
|
+
const arns = [];
|
|
242
|
+
do {
|
|
243
|
+
const resp = await ecsClient.send(new ListServicesCommand({ cluster, nextToken, maxResults: 100 }));
|
|
244
|
+
arns.push(...(resp.serviceArns || []));
|
|
245
|
+
nextToken = resp.nextToken;
|
|
246
|
+
} while (nextToken);
|
|
247
|
+
const subnetIds = new Set();
|
|
248
|
+
for (const batch of chunkArray(arns, 10)) {
|
|
249
|
+
const desc = await ecsClient.send(new DescribeServicesCommand({ cluster, services: batch }));
|
|
250
|
+
for (const svc of desc.services || []) {
|
|
251
|
+
// Desired counts: a crash-looping preview runs nothing
|
|
252
|
+
// yet is unambiguously live.
|
|
253
|
+
if ((svc.desiredCount ?? 0) <= 0 && (svc.runningCount ?? 0) <= 0) continue;
|
|
254
|
+
for (const id of svc.networkConfiguration?.awsvpcConfiguration?.subnets || []) subnetIds.add(id);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
if (subnetIds.size > 0) {
|
|
258
|
+
const subs = await ec2Client.send(new DescribeSubnetsCommand({ SubnetIds: [...subnetIds] }));
|
|
259
|
+
for (const sn of subs.Subnets || []) if (sn.VpcId) vpcIds.add(sn.VpcId);
|
|
260
|
+
}
|
|
261
|
+
} catch {
|
|
262
|
+
return { vpcIds, unknown: true };
|
|
263
|
+
}
|
|
264
|
+
return { vpcIds, unknown: false };
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
async function discoverDeepVpcs({ ec2Client, ecsClient = null, cluster = null, projectName, resourceSuffix = '', isLambda = false }) {
|
|
233
268
|
const deletable = [];
|
|
234
269
|
const reportOnly = [];
|
|
270
|
+
// The stack's own default-workspace VPC is live by construction —
|
|
271
|
+
// asleep stacks run nothing, so task liveness alone would propose
|
|
272
|
+
// deleting the slept network. (Lambda trees create no VPCs, so the
|
|
273
|
+
// Name check is the whole liveness story there.)
|
|
274
|
+
const defaultVpcName = `${projectName}${resourceSuffix}-vpc`;
|
|
275
|
+
const live = isLambda
|
|
276
|
+
? { vpcIds: new Set(), unknown: false }
|
|
277
|
+
: await discoverLiveVpcIds({ ecsClient, cluster, ec2Client });
|
|
235
278
|
let nextToken;
|
|
236
279
|
do {
|
|
237
280
|
const resp = await ec2Client.send(new DescribeVpcsCommand({ NextToken: nextToken }));
|
|
238
281
|
for (const vpc of resp.Vpcs || []) {
|
|
239
282
|
const entry = { kind: 'vpc', id: vpc.VpcId };
|
|
240
|
-
if (hasExactProjectTag(vpc.Tags, projectName)) {
|
|
241
|
-
deletable.push(entry);
|
|
242
|
-
} else {
|
|
283
|
+
if (!hasExactProjectTag(vpc.Tags, projectName)) {
|
|
243
284
|
reportOnly.push({
|
|
244
285
|
...entry,
|
|
245
286
|
reason: Array.isArray(vpc.Tags) && vpc.Tags.length > 0 ? 'foreign-project' : 'unscoped',
|
|
246
287
|
});
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
const name = (vpc.Tags || []).find((tag) => tag?.Key === 'Name')?.Value;
|
|
291
|
+
if (name === defaultVpcName || live.vpcIds.has(vpc.VpcId)) {
|
|
292
|
+
reportOnly.push({ ...entry, reason: 'live-excluded' });
|
|
293
|
+
} else if (live.unknown) {
|
|
294
|
+
reportOnly.push({ ...entry, reason: 'liveness-unknown' });
|
|
295
|
+
} else {
|
|
296
|
+
deletable.push(entry);
|
|
247
297
|
}
|
|
248
298
|
}
|
|
249
299
|
nextToken = resp.NextToken;
|
|
250
300
|
} while (nextToken);
|
|
251
|
-
return { deletable, reportOnly };
|
|
301
|
+
return { deletable, reportOnly, unknown: live.unknown };
|
|
252
302
|
}
|
|
253
303
|
|
|
254
304
|
// Deep target discovery: secrets are report-only, never deletable —
|
|
@@ -347,12 +397,14 @@ export async function discoverOrphanedResources(ctx) {
|
|
|
347
397
|
export async function discoverDeepOrphans(ctx) {
|
|
348
398
|
const deletable = [];
|
|
349
399
|
const reportOnly = [];
|
|
400
|
+
let unknown = false;
|
|
350
401
|
for (const target of GC_TARGETS.filter((entry) => entry.scope === 'deep')) {
|
|
351
402
|
const found = await target.discover(ctx);
|
|
352
403
|
deletable.push(...(found.deletable || []));
|
|
353
404
|
reportOnly.push(...(found.reportOnly || []));
|
|
405
|
+
if (found.unknown === true) unknown = true;
|
|
354
406
|
}
|
|
355
|
-
return { deletable, reportOnly };
|
|
407
|
+
return { deletable, reportOnly, unknown };
|
|
356
408
|
}
|
|
357
409
|
|
|
358
410
|
export const ECR_BATCH_DELETE_LIMIT = 100;
|
|
@@ -440,7 +492,11 @@ function printDeepReport(deep, projectName) {
|
|
|
440
492
|
? 'owned — secrets are never auto-deleted'
|
|
441
493
|
: entry.reason === 'prefix-report-only'
|
|
442
494
|
? 'name-prefix match — review before acting'
|
|
443
|
-
:
|
|
495
|
+
: entry.reason === 'live-excluded'
|
|
496
|
+
? 'live — excluded'
|
|
497
|
+
: entry.reason === 'liveness-unknown'
|
|
498
|
+
? 'liveness unverifiable — review before acting'
|
|
499
|
+
: 'never deleted by gc';
|
|
444
500
|
console.log(` ${color.dim('-')} ${entry.kind}/${entry.id} ${color.dim(`(${why})`)}`);
|
|
445
501
|
}
|
|
446
502
|
console.log('');
|
|
@@ -459,6 +515,8 @@ export async function runGc(input = {}) {
|
|
|
459
515
|
|
|
460
516
|
async function runGcMain(input = {}) {
|
|
461
517
|
const options = normalizeOptions(input);
|
|
518
|
+
const unknownRefusal = await refuseUnknownFlags(options, { command: 'gc', event: 'gc_run' });
|
|
519
|
+
if (unknownRefusal) return unknownRefusal;
|
|
462
520
|
let cwd;
|
|
463
521
|
let region;
|
|
464
522
|
let projectName;
|
|
@@ -533,16 +591,24 @@ async function runGcMain(input = {}) {
|
|
|
533
591
|
console.log(color.dim(`Total orphaned resources: ${discovered.totalCount}`));
|
|
534
592
|
|
|
535
593
|
// Deep scan (opt-in): report-only audit of tag-keyed orphans (VPCs,
|
|
536
|
-
// secrets, state bucket). Never prompts, never deletes —
|
|
537
|
-
//
|
|
538
|
-
//
|
|
539
|
-
// any future deletion acts on them.
|
|
594
|
+
// secrets, state bucket). Never prompts, never deletes — VPC
|
|
595
|
+
// candidates additionally pass ECS liveness plus the stack-VPC name
|
|
596
|
+
// check, so live networks land in report-only, never deletable.
|
|
540
597
|
if (deep) {
|
|
541
598
|
const ds = spinner();
|
|
542
599
|
ds.start('Deep scanning tag-keyed orphans...');
|
|
543
600
|
let deepResult;
|
|
544
601
|
try {
|
|
545
|
-
deepResult = await discoverDeepOrphans({
|
|
602
|
+
deepResult = await discoverDeepOrphans({
|
|
603
|
+
ec2Client,
|
|
604
|
+
secretsClient,
|
|
605
|
+
cwd,
|
|
606
|
+
projectName,
|
|
607
|
+
ecsClient,
|
|
608
|
+
cluster: resolveCluster(options, cwd),
|
|
609
|
+
resourceSuffix: readResourceSuffix(cwd),
|
|
610
|
+
isLambda: isComputeTarget(cwd, 'lambda'),
|
|
611
|
+
});
|
|
546
612
|
} catch (error) {
|
|
547
613
|
ds.stop(color.red('❌ Deep discovery failed.'));
|
|
548
614
|
await trackFailure('gc_run', { projectName, deep: true, error_message: error?.message });
|
|
@@ -554,10 +620,14 @@ async function runGcMain(input = {}) {
|
|
|
554
620
|
});
|
|
555
621
|
}
|
|
556
622
|
ds.stop('Deep discovery complete.');
|
|
623
|
+
if (deepResult.unknown === true) {
|
|
624
|
+
console.log(color.yellow('⚠ VPC liveness could not be verified — no VPCs will be proposed. Check credentials (ECS/EC2) and retry.'));
|
|
625
|
+
}
|
|
557
626
|
printDeepReport(deepResult, projectName);
|
|
558
627
|
const deepCounts = {
|
|
559
628
|
vpc_deletable: deepResult.deletable.filter((entry) => entry.kind === 'vpc').length,
|
|
560
629
|
vpc_report_only: deepResult.reportOnly.filter((entry) => entry.kind === 'vpc').length,
|
|
630
|
+
vpc_liveness_unknown: deepResult.unknown === true,
|
|
561
631
|
secret_report_only: deepResult.reportOnly.filter((entry) => entry.kind === 'secret').length,
|
|
562
632
|
state_bucket_report_only: deepResult.reportOnly.filter((entry) => entry.kind === 'state-bucket').length,
|
|
563
633
|
};
|
package/src/commands/init.js
CHANGED
|
@@ -28,7 +28,7 @@ import { scaffoldDriftWorkflow } from './drift.js';
|
|
|
28
28
|
import { trackEvent, flushTelemetry, getCliVersion, setActiveCommandName, resetActiveCommandName } from '../core/telemetry.js';
|
|
29
29
|
import { failCommand } from '../utils/command.js';
|
|
30
30
|
import { getFrameworkWarning } from '../utils/warnings.js';
|
|
31
|
-
import { provisionStateBucket, formatStateBucketName } from '../utils/aws.js';
|
|
31
|
+
import { provisionStateBucket, formatStateBucketName, isAuthError, printAwsAuthGuidance } from '../utils/aws.js';
|
|
32
32
|
import { generateTemplates } from '../utils/generator.js';
|
|
33
33
|
import { planExistingFiles, executeBackup, preserveManagedFiles, restoreManagedFiles, refusalResultForPlan, writeInitManifest } from '../utils/backup.js';
|
|
34
34
|
import { checkStateAdoption } from '../utils/state-adoption.js';
|
|
@@ -41,11 +41,13 @@ import { getBaseRules, getCursorRules, injectManagedBlock } from '../utils/ai-ru
|
|
|
41
41
|
import { readFileSafe, COMPUTE_TARGETS, resolveHeadless, resolveInitSuffix, readTerraformProjectName, readTerraformOidcTrust } from '../utils/resolvers.js';
|
|
42
42
|
import { readGitHubRepoFromRemote, isValidGitHubRepoSlug } from '../utils/git.js';
|
|
43
43
|
import { parseDomainTf } from '../utils/domains.js';
|
|
44
|
+
import { PLACEHOLDER_ACCOUNT_ID } from '../utils/reconcile.js';
|
|
44
45
|
|
|
45
46
|
// Greppable, invalid-as-real placeholder stamped into backend.tf and
|
|
46
47
|
// workflow role ARNs by `init --offline`. Uppercase by design: S3 rejects
|
|
47
|
-
// it, so an unreconciled tree fails loud at `terraform init`.
|
|
48
|
-
|
|
48
|
+
// it, so an unreconciled tree fails loud at `terraform init`. Single
|
|
49
|
+
// source lives in reconcile.js; this alias keeps the init-facing name.
|
|
50
|
+
export const OFFLINE_ACCOUNT_PLACEHOLDER = PLACEHOLDER_ACCOUNT_ID;
|
|
49
51
|
|
|
50
52
|
// Reconciliation checklist for offline scaffolds. console.log (not clack)
|
|
51
53
|
// so it lands in CI logs as well as terminals. Mirrors every call
|
|
@@ -746,6 +748,9 @@ async function mainStackMain(input = {}) {
|
|
|
746
748
|
projectName: dirConfig.actualProjectName,
|
|
747
749
|
plan: existingFilesPlan.decision,
|
|
748
750
|
});
|
|
751
|
+
// Auth failures print the shared credential-recovery guidance;
|
|
752
|
+
// init keeps its own telemetry + exit path through failCommand.
|
|
753
|
+
if (isAuthError(error)) printAwsAuthGuidance(initOptions);
|
|
749
754
|
return failCommand({
|
|
750
755
|
message: `AWS Error: ${error.message}`,
|
|
751
756
|
useErrorStream: true,
|
package/src/commands/logs.js
CHANGED
|
@@ -4,7 +4,7 @@ import { trackEvent, flushTelemetry, trackSuccess, trackFailure, setActiveComman
|
|
|
4
4
|
import { parseFlags, normalizeOptions, normalizeArgv } from '../utils/args.js';
|
|
5
5
|
import { isAuthError, handleAuthErrorBranch, resolveClient } from '../utils/aws.js';
|
|
6
6
|
import { resolveRegion, resolveProjectName, resolveLogGroup, resolveCwd, isComputeTarget } from '../utils/resolvers.js';
|
|
7
|
-
import { failCommand, failProjectNotInitialized, isProgrammaticCall } from '../utils/command.js';
|
|
7
|
+
import { failCommand, failProjectNotInitialized, isProgrammaticCall, refuseUnknownFlags } from '../utils/command.js';
|
|
8
8
|
import { sleep } from '../utils/system.js';
|
|
9
9
|
|
|
10
10
|
export const DEFAULT_TAIL_LINES = 50;
|
|
@@ -85,14 +85,16 @@ export const formatLogEvent = formatLogLine;
|
|
|
85
85
|
export function parseLogsArgs(argv = []) {
|
|
86
86
|
const args = normalizeArgv(argv);
|
|
87
87
|
if (args[0] === 'logs') args.shift();
|
|
88
|
-
const { options, rest } = parseFlags(args, {
|
|
88
|
+
const { options, rest, unknown } = parseFlags(args, {
|
|
89
89
|
string: ['since', 'region'],
|
|
90
90
|
number: ['tail'],
|
|
91
|
+
boolean: ['headless'],
|
|
91
92
|
bareBoolean: ['follow', 'error'],
|
|
92
93
|
alias: { f: 'follow' },
|
|
93
94
|
});
|
|
94
95
|
const positionals = rest.filter((arg) => typeof arg === 'string' && !arg.startsWith('-'));
|
|
95
96
|
if (positionals.length > 0) options.service = positionals[0];
|
|
97
|
+
if (unknown.length > 0) options.unknownFlags = unknown;
|
|
96
98
|
return options;
|
|
97
99
|
}
|
|
98
100
|
|
|
@@ -134,6 +136,8 @@ export async function runLogs(input = {}) {
|
|
|
134
136
|
|
|
135
137
|
async function runLogsMain(input = {}) {
|
|
136
138
|
const options = normalizeOptions(input);
|
|
139
|
+
const unknownRefusal = await refuseUnknownFlags(options, { command: 'logs', event: 'logs_streamed' });
|
|
140
|
+
if (unknownRefusal) return unknownRefusal;
|
|
137
141
|
let cwd;
|
|
138
142
|
let region;
|
|
139
143
|
let service;
|
package/src/commands/mcp.js
CHANGED
|
@@ -10,7 +10,7 @@ import { z } from 'zod';
|
|
|
10
10
|
import { getCliVersion, trackSuccess, setActiveCommandName, resetActiveCommandName } from '../core/telemetry.js';
|
|
11
11
|
import { safeHomedir } from '../core/homedir.js';
|
|
12
12
|
import { parseFlags, normalizeOptions, normalizeArgv } from '../utils/args.js';
|
|
13
|
-
import { failCommand } from '../utils/command.js';
|
|
13
|
+
import { failCommand, refuseUnknownFlags } from '../utils/command.js';
|
|
14
14
|
import { runStatus } from './status.js';
|
|
15
15
|
import { runLogs } from './logs.js';
|
|
16
16
|
import { auditSecrets } from './secrets.js';
|
|
@@ -386,7 +386,8 @@ export function createMcpServer() {
|
|
|
386
386
|
export function parseMcpArgs(argv = []) {
|
|
387
387
|
const args = normalizeArgv(argv);
|
|
388
388
|
if (args[0] === 'mcp') args.shift();
|
|
389
|
-
const { options } = parseFlags(args, { string: ['install', 'transport', 'host'], number: ['port'] });
|
|
389
|
+
const { options, unknown } = parseFlags(args, { string: ['install', 'transport', 'host'], number: ['port'], boolean: ['headless'] });
|
|
390
|
+
if (unknown.length > 0) options.unknownFlags = unknown;
|
|
390
391
|
if (options.install === undefined) {
|
|
391
392
|
// parseFlags drops a trailing valueless `--install`; detect the
|
|
392
393
|
// flag's presence so runMcp reports usage instead of starting
|
|
@@ -651,6 +652,8 @@ export function installMcpConfig(editor, { homeDir = safeHomedir(), platform = o
|
|
|
651
652
|
// until the client disconnects or receives SIGINT/SIGTERM.
|
|
652
653
|
export async function runMcp(input = {}) {
|
|
653
654
|
const options = normalizeOptions(input);
|
|
655
|
+
const unknownRefusal = await refuseUnknownFlags(options, { command: 'mcp', event: 'mcp_install' });
|
|
656
|
+
if (unknownRefusal) return unknownRefusal;
|
|
654
657
|
if (options.install !== undefined) {
|
|
655
658
|
const installed = installMcpConfig(options.install, { homeDir: options.homeDir, platform: options.platform });
|
|
656
659
|
if (!installed.ok) {
|
package/src/commands/rollback.js
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
import color from 'picocolors';
|
|
9
9
|
import { intro, outro, spinner, select, isCancel } from '@clack/prompts';
|
|
10
10
|
import { trackEvent, flushTelemetry, trackSuccess, trackFailure, setActiveCommandName, resetActiveCommandName } from '../core/telemetry.js';
|
|
11
|
-
import { failCommand, failAwsError, failProjectNotInitialized, refuseIfNonInteractive } from '../utils/command.js';
|
|
11
|
+
import { failCommand, failAwsError, failProjectNotInitialized, refuseIfNonInteractive, refuseUnknownFlags } from '../utils/command.js';
|
|
12
12
|
import { parseFlags, normalizeOptions, normalizeArgv } from '../utils/args.js';
|
|
13
13
|
import { isAuthError, handleAwsAuthError, resolveClient } from '../utils/aws.js';
|
|
14
14
|
import { resolveRegion, resolveProjectName, resolveCluster, resolveService, readFileSafe, resolveWorkspaceSuffix, resolveCwd, guardComputeTarget, readResourceSuffix } from '../utils/resolvers.js';
|
|
@@ -28,11 +28,12 @@ export const DEFAULT_TIMEOUT_MS = 300000;
|
|
|
28
28
|
export function parseRollbackArgs(argv = []) {
|
|
29
29
|
const args = normalizeArgv(argv);
|
|
30
30
|
if (args[0] === 'rollback') args.shift();
|
|
31
|
-
const { options: parsed, rest } = parseFlags(args, {
|
|
31
|
+
const { options: parsed, rest, unknown } = parseFlags(args, {
|
|
32
32
|
string: ['cluster', 'service', 'region', 'workspace'],
|
|
33
|
-
boolean: ['skip-wait'],
|
|
33
|
+
boolean: ['skip-wait', 'headless'],
|
|
34
34
|
});
|
|
35
35
|
const options = { skipWait: false, ...parsed };
|
|
36
|
+
if (unknown.length > 0) options.unknownFlags = unknown;
|
|
36
37
|
for (const arg of rest) {
|
|
37
38
|
if (typeof arg === 'string' && !arg.startsWith('-') && options.revision === undefined) {
|
|
38
39
|
options.revision = arg;
|
|
@@ -73,6 +74,8 @@ export async function runRollback(input = {}) {
|
|
|
73
74
|
|
|
74
75
|
async function runRollbackMain(input = {}) {
|
|
75
76
|
const options = normalizeOptions(input);
|
|
77
|
+
const unknownRefusal = await refuseUnknownFlags(options, { command: 'rollback', event: 'rollback_run' });
|
|
78
|
+
if (unknownRefusal) return unknownRefusal;
|
|
76
79
|
let cwd;
|
|
77
80
|
let region;
|
|
78
81
|
let projectName;
|
package/src/commands/sleep.js
CHANGED
|
@@ -5,7 +5,7 @@ import { RDSClient, StopDBInstanceCommand, StopDBClusterCommand } from '@aws-sdk
|
|
|
5
5
|
import color from 'picocolors';
|
|
6
6
|
import { intro, outro, spinner, confirm, cancel } from '@clack/prompts';
|
|
7
7
|
import { trackEvent, trackSuccess, setActiveCommandName, resetActiveCommandName } from '../core/telemetry.js';
|
|
8
|
-
import { failCommand, failAwsError, trackAwsFailure, failProjectNotInitialized, refuseIfNonInteractive, shouldAutoApprove } from '../utils/command.js';
|
|
8
|
+
import { failCommand, failAwsError, trackAwsFailure, failProjectNotInitialized, refuseIfNonInteractive, refuseUnknownFlags, shouldAutoApprove } from '../utils/command.js';
|
|
9
9
|
import { parseFlags, normalizeOptions, normalizeArgv } from '../utils/args.js';
|
|
10
10
|
import { isAuthError, handleAuthErrorBranch, resolveClient } from '../utils/aws.js';
|
|
11
11
|
import { resolveRegion, resolveProjectName, resolveCwd, readTerraformComputeTarget } from '../utils/resolvers.js';
|
|
@@ -41,13 +41,14 @@ export const SLEEP_CONFIRM_MESSAGE = "Put environment to sleep? This will take t
|
|
|
41
41
|
export function parseSleepArgs(argv = []) {
|
|
42
42
|
const args = normalizeArgv(argv);
|
|
43
43
|
if (args[0] === 'sleep') args.shift();
|
|
44
|
-
const { options, rest } = parseFlags(args, {
|
|
44
|
+
const { options, rest, unknown } = parseFlags(args, {
|
|
45
45
|
string: ['project-name', 'cluster', 'service', 'db-identifier', 'region', 'workspace'],
|
|
46
46
|
boolean: ['skip-db', 'wait', 'no-wait', 'yes', 'force', 'headless', 'strict'],
|
|
47
47
|
});
|
|
48
48
|
const positionals = rest.filter((arg) => typeof arg === 'string' && !arg.startsWith('-'));
|
|
49
49
|
if (positionals.length > 0) options.env = positionals[0];
|
|
50
50
|
if (positionals.length > 1) options.unexpectedPositionals = positionals.slice(1);
|
|
51
|
+
if (unknown.length > 0) options.unknownFlags = unknown;
|
|
51
52
|
return options;
|
|
52
53
|
}
|
|
53
54
|
|
|
@@ -68,6 +69,8 @@ export async function runSleep(input = {}) {
|
|
|
68
69
|
|
|
69
70
|
async function runSleepMain(input = {}) {
|
|
70
71
|
const options = normalizeOptions(input);
|
|
72
|
+
const unknownRefusal = await refuseUnknownFlags(options, { command: 'sleep', event: 'sleep_run' });
|
|
73
|
+
if (unknownRefusal) return unknownRefusal;
|
|
71
74
|
let cwd;
|
|
72
75
|
let region;
|
|
73
76
|
let projectName;
|