cdk-real-drift 0.4.12 → 0.4.14
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/README.md +17 -4
- package/dist/cli.js +226 -36
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -309,6 +309,16 @@ from `--app`: a command (`--app "node bin/app.js"`) or a pre-synthesized assembl
|
|
|
309
309
|
comparison still reads each stack's **deployed** template + live state from AWS;
|
|
310
310
|
synth only tells cdkrd which stacks to look at.
|
|
311
311
|
|
|
312
|
+
**Context lookups.** Resolving a CDK app that uses `fromLookup`
|
|
313
|
+
(`Vpc.fromLookup`, `HostedZone.fromLookup`, …) runs the same live AWS context
|
|
314
|
+
lookups as `cdk synth` and caches the results in `cdk.context.json` in your app
|
|
315
|
+
directory — so an app with uncached lookups will make read-only AWS calls and
|
|
316
|
+
create/update that file (a `git status` change is expected; the cache makes
|
|
317
|
+
subsequent checks reproducible). cdkrd prints a one-liner when it does so. This
|
|
318
|
+
matches `cdk synth` semantics and is the only file `check` writes; it never writes
|
|
319
|
+
to AWS. If every lookup fails (leaving only an empty `{}`), cdkrd removes the file
|
|
320
|
+
it just created rather than leave that noise in your tree.
|
|
321
|
+
|
|
312
322
|
## Commands & options
|
|
313
323
|
|
|
314
324
|
| command | does |
|
|
@@ -333,10 +343,13 @@ CI (with `--yes`).
|
|
|
333
343
|
is always surfaced regardless (as the `skipped=N` footer line or a loud
|
|
334
344
|
`warning:`); `--strict` only decides whether it fails the build.
|
|
335
345
|
- Errors always exit `2`; `revert` exits `1` when drift remains after it.
|
|
336
|
-
- Interrupting a run with **Ctrl-C** (or **ESC**) during the gather/read
|
|
337
|
-
exits `130` (128 + SIGINT) for every verb
|
|
338
|
-
|
|
339
|
-
never
|
|
346
|
+
- Interrupting a run with **Ctrl-C** (or **ESC** / SIGINT) during the gather/read
|
|
347
|
+
phase exits `130` (128 + SIGINT) for every verb, and a **SIGTERM** (CI
|
|
348
|
+
cancellation, `timeout`, a supervisor) exits `143` promptly on the first signal
|
|
349
|
+
— never `0`, so an aborted `check --fail` can never be mistaken for "no drift"
|
|
350
|
+
and an aborted `record` is never a false "written". An unhandled internal error
|
|
351
|
+
(a stray promise rejection / uncaught exception) always exits `2` (the error
|
|
352
|
+
code), never `0` or `1`.
|
|
340
353
|
|
|
341
354
|
```yaml
|
|
342
355
|
- run: npm ci # cdkrd resolves the CDK app, so its deps must be installed
|
package/dist/cli.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
2
|
+
import { existsSync, readFileSync, readdirSync, rmSync, statSync } from "node:fs";
|
|
3
3
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
4
4
|
import { dirname, join, resolve } from "node:path";
|
|
5
5
|
import { YAMLSeq, isSeq, parse, parseDocument } from "yaml";
|
|
6
6
|
import { CloudControlClient, DeleteResourceCommand, GetResourceCommand, GetResourceRequestStatusCommand, UpdateResourceCommand } from "@aws-sdk/client-cloudcontrol";
|
|
7
7
|
import { homedir } from "node:os";
|
|
8
|
-
import { BaseCredentials, CdkAppMultiContext, NonInteractiveIoHost, Toolkit } from "@aws-cdk/toolkit-lib";
|
|
8
|
+
import { BaseCredentials, CdkAppMultiContext, NonInteractiveIoHost, StackSelectionStrategy, Toolkit } from "@aws-cdk/toolkit-lib";
|
|
9
9
|
import { CloudFormationClient, DescribeStackResourcesCommand, DescribeStacksCommand, DescribeTypeCommand, GetTemplateCommand, ListExportsCommand, ListStackResourcesCommand } from "@aws-sdk/client-cloudformation";
|
|
10
10
|
import { KMSClient, ListAliasesCommand } from "@aws-sdk/client-kms";
|
|
11
11
|
import { APIGatewayClient, GetAuthorizersCommand, GetGatewayResponsesCommand, GetModelsCommand, GetRequestValidatorsCommand, GetResourcesCommand, UpdateIntegrationCommand, UpdateIntegrationResponseCommand, UpdateMethodResponseCommand, UpdateRestApiCommand } from "@aws-sdk/client-api-gateway";
|
|
@@ -87,12 +87,20 @@ function installInterruptGuard() {
|
|
|
87
87
|
installed = true;
|
|
88
88
|
const realExit = process.exit.bind(process);
|
|
89
89
|
process.exit = (code) => realExit(interruptExitCode(code, gatherActive));
|
|
90
|
-
const onSignal = () => {
|
|
90
|
+
const onSignal = (code) => () => {
|
|
91
91
|
process.stderr.write("\x1B[?25h");
|
|
92
|
-
return realExit(
|
|
92
|
+
return realExit(code);
|
|
93
93
|
};
|
|
94
|
-
process.on("SIGINT", onSignal);
|
|
95
|
-
process.on("SIGTERM", onSignal);
|
|
94
|
+
process.on("SIGINT", onSignal(130));
|
|
95
|
+
process.on("SIGTERM", onSignal(143));
|
|
96
|
+
const onFatal = (kind) => (err) => {
|
|
97
|
+
process.stderr.write("\x1B[?25h");
|
|
98
|
+
const detail = err instanceof Error ? err.stack ?? err.message : String(err);
|
|
99
|
+
console.error(`error: ${kind}: ${detail}`);
|
|
100
|
+
realExit(2);
|
|
101
|
+
};
|
|
102
|
+
process.on("unhandledRejection", onFatal("unhandled rejection"));
|
|
103
|
+
process.on("uncaughtException", onFatal("uncaught exception"));
|
|
96
104
|
}
|
|
97
105
|
|
|
98
106
|
//#endregion
|
|
@@ -842,6 +850,8 @@ function resolveApp(explicit) {
|
|
|
842
850
|
const APP_STDOUT = "CDK_ASSEMBLY_I1001";
|
|
843
851
|
const APP_STDERR = "CDK_ASSEMBLY_E1002";
|
|
844
852
|
const VALIDATION_REPORT = "CDK_TOOLKIT_E9600";
|
|
853
|
+
const CONTEXT_FETCHING = "CDK_ASSEMBLY_I0241";
|
|
854
|
+
const CONTEXT_WRITING = "CDK_ASSEMBLY_I0042";
|
|
845
855
|
/**
|
|
846
856
|
* Decide what QuietIoHost does with a message (pure, so it is unit-testable):
|
|
847
857
|
* - the CDK app's own stdout/stderr passthrough -> emit at INFO (default color, like
|
|
@@ -849,6 +859,9 @@ const VALIDATION_REPORT = "CDK_TOOLKIT_E9600";
|
|
|
849
859
|
* - the construct-annotation validation report -> emit at WARN so the whole block is
|
|
850
860
|
* yellow (matching its WARNING label) instead of the misleading ERROR-level red
|
|
851
861
|
* wrap; per-severity labels still survive (see file header);
|
|
862
|
+
* - the context-lookup fetch / write codes -> `note` a fixed one-liner (replacing
|
|
863
|
+
* toolkit-lib's verbose debug text) so the otherwise-silent live lookup + the
|
|
864
|
+
* cdk.context.json write are visible (#906);
|
|
852
865
|
* - a real toolkit warning / error -> emit unchanged (still yellow / red);
|
|
853
866
|
* - everything else (toolkit info/debug/trace chatter) -> drop.
|
|
854
867
|
*/
|
|
@@ -861,6 +874,16 @@ function planIoMessage(msg) {
|
|
|
861
874
|
action: "emit",
|
|
862
875
|
level: "warn"
|
|
863
876
|
};
|
|
877
|
+
if (msg.code === CONTEXT_FETCHING) return {
|
|
878
|
+
action: "note",
|
|
879
|
+
level: "info",
|
|
880
|
+
text: "performing context lookups (Vpc.fromLookup, …)…"
|
|
881
|
+
};
|
|
882
|
+
if (msg.code === CONTEXT_WRITING) return {
|
|
883
|
+
action: "note",
|
|
884
|
+
level: "info",
|
|
885
|
+
text: "wrote cdk.context.json (cached context lookups)"
|
|
886
|
+
};
|
|
864
887
|
if (msg.level === "warn" || msg.level === "error") return {
|
|
865
888
|
action: "emit",
|
|
866
889
|
level: msg.level
|
|
@@ -871,9 +894,19 @@ var QuietIoHost = class extends NonInteractiveIoHost {
|
|
|
871
894
|
constructor() {
|
|
872
895
|
super({ isCI: false });
|
|
873
896
|
}
|
|
897
|
+
seenNotes = /* @__PURE__ */ new Set();
|
|
874
898
|
async notify(msg) {
|
|
875
899
|
const plan = planIoMessage(msg);
|
|
876
900
|
if (plan.action === "drop") return;
|
|
901
|
+
if (plan.action === "note") {
|
|
902
|
+
if (this.seenNotes.has(plan.text)) return;
|
|
903
|
+
this.seenNotes.add(plan.text);
|
|
904
|
+
return super.notify({
|
|
905
|
+
...msg,
|
|
906
|
+
level: plan.level,
|
|
907
|
+
message: `info: ${plan.text}`
|
|
908
|
+
});
|
|
909
|
+
}
|
|
877
910
|
return super.notify(plan.level === msg.level ? msg : {
|
|
878
911
|
...msg,
|
|
879
912
|
level: plan.level
|
|
@@ -918,6 +951,31 @@ function missingContextWarning(keys, opts = {}) {
|
|
|
918
951
|
|
|
919
952
|
//#endregion
|
|
920
953
|
//#region src/synth/synth.ts
|
|
954
|
+
/**
|
|
955
|
+
* Map the requested stack name(s)/glob(s) to the toolkit-lib `StackSelector` that scopes
|
|
956
|
+
* `toolkit.synth`'s metadata validation (#905).
|
|
957
|
+
*
|
|
958
|
+
* - No patterns (`undefined` / empty) → `undefined`: the caller wants EVERY stack (no-args
|
|
959
|
+
* discovery or `--all`), so we pass no selector and toolkit-lib defaults to `ALL_STACKS` —
|
|
960
|
+
* the pre-#905 behavior, unchanged. Everything is validated because the user asked for it.
|
|
961
|
+
* - One or more patterns → a `PATTERN_MATCH` selector over those patterns. toolkit-lib then
|
|
962
|
+
* validates ONLY the matched stacks, so a sibling stack the user did NOT target can fail a
|
|
963
|
+
* context lookup without aborting synth. `PATTERN_MATCH` (NOT `PATTERN_MUST_MATCH`) is
|
|
964
|
+
* deliberate: it halts successfully — never throws — when the patterns match zero stacks.
|
|
965
|
+
* The selector matches on the toolkit's HIERARCHICAL id (`Stage/Stack` for a staged stack)
|
|
966
|
+
* via picomatch, which can differ from the deployed stackName resolveStacks filters on, so
|
|
967
|
+
* a staged-stack pattern may legitimately match nothing here; that must not error. The
|
|
968
|
+
* real "unknown stack / no-match glob" errors stay in resolveStacks, checked against the
|
|
969
|
+
* FULL discovered stack list (this selector only narrows what gets VALIDATED, never what
|
|
970
|
+
* gets discovered — the returned assembly still carries every stack).
|
|
971
|
+
*/
|
|
972
|
+
function buildStackSelector(patterns) {
|
|
973
|
+
if (!patterns || patterns.length === 0) return void 0;
|
|
974
|
+
return {
|
|
975
|
+
strategy: StackSelectionStrategy.PATTERN_MATCH,
|
|
976
|
+
patterns
|
|
977
|
+
};
|
|
978
|
+
}
|
|
921
979
|
const CONCRETE_REGION = /^[a-z]{2}(-[a-z]+)+-\d+$/;
|
|
922
980
|
/**
|
|
923
981
|
* Build the stderr message body (no `warning:` prefix — the caller adds it) for the case where
|
|
@@ -933,8 +991,45 @@ function contextIgnoredWarning(isDir, context) {
|
|
|
933
991
|
if (!isDir || keys.length === 0) return null;
|
|
934
992
|
return `ignoring -c/--context (${keys.join(", ")}): --app points at a pre-synthesized cloud-assembly directory, whose context was baked in at synth time — there is no CDK app to re-run with new context. To apply new context, point --app at the CDK app itself (not its cdk.out).`;
|
|
935
993
|
}
|
|
994
|
+
/**
|
|
995
|
+
* Decide whether to remove a `cdk.context.json` that synth may have written (#906).
|
|
996
|
+
*
|
|
997
|
+
* For an app with context lookups but no cached context, toolkit-lib's default
|
|
998
|
+
* `CdkAppMultiContext` persists the resolved lookups into `<cwd>/cdk.context.json` — even
|
|
999
|
+
* when EVERY lookup FAILED, in which case it writes an empty `{}`. That empty file dirties
|
|
1000
|
+
* the user's git tree for no benefit (it caches nothing). We remove it, but ONLY when it is
|
|
1001
|
+
* safe: the file must NOT have pre-existed (so we never touch a user's committed context),
|
|
1002
|
+
* AND it must be empty (`{}` / whitespace-only) now (so we never delete a file that captured
|
|
1003
|
+
* real lookup results). Returns true iff the file at `file` should be deleted.
|
|
1004
|
+
*/
|
|
1005
|
+
function shouldRemoveEmptyContextFile(existedBefore, existsNow) {
|
|
1006
|
+
return !existedBefore && existsNow;
|
|
1007
|
+
}
|
|
1008
|
+
/** An object with no own enumerable keys — a persisted `{}` context (an all-failed lookup). */
|
|
1009
|
+
function isEmptyContextJson(raw) {
|
|
1010
|
+
const trimmed = raw.trim();
|
|
1011
|
+
if (trimmed === "" || trimmed === "{}") return true;
|
|
1012
|
+
try {
|
|
1013
|
+
const parsed = JSON.parse(trimmed);
|
|
1014
|
+
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) && Object.keys(parsed).length === 0;
|
|
1015
|
+
} catch {
|
|
1016
|
+
return false;
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
/**
|
|
1020
|
+
* Remove a `cdk.context.json` at `file` iff synth JUST created it AND it is empty (an
|
|
1021
|
+
* all-failed lookup that persisted `{}`). Guarded so a pre-existing or non-empty user file
|
|
1022
|
+
* is NEVER touched (#906). No-op on any read/remove error — cleanup is best-effort.
|
|
1023
|
+
*/
|
|
1024
|
+
function cleanupEmptyContextFile(file, existedBefore) {
|
|
1025
|
+
if (!shouldRemoveEmptyContextFile(existedBefore, existsSync(file))) return;
|
|
1026
|
+
try {
|
|
1027
|
+
if (isEmptyContextJson(readFileSync(file, "utf-8"))) rmSync(file);
|
|
1028
|
+
} catch {}
|
|
1029
|
+
}
|
|
936
1030
|
async function synthApp(app, opts = {}) {
|
|
937
1031
|
const { region, profile, context = {} } = opts;
|
|
1032
|
+
const stackSelector = buildStackSelector(opts.stackPatterns);
|
|
938
1033
|
const toolkit = new Toolkit({
|
|
939
1034
|
ioHost: new QuietIoHost(),
|
|
940
1035
|
sdkConfig: { baseCredentials: BaseCredentials.awsCliCompatible({
|
|
@@ -944,6 +1039,8 @@ async function synthApp(app, opts = {}) {
|
|
|
944
1039
|
});
|
|
945
1040
|
const p = resolve(app);
|
|
946
1041
|
const isDir = existsSync(p) && statSync(p).isDirectory();
|
|
1042
|
+
const contextFile = resolve(process.cwd(), "cdk.context.json");
|
|
1043
|
+
const contextFileExistedBefore = !isDir && existsSync(contextFile);
|
|
947
1044
|
let source;
|
|
948
1045
|
if (isDir) {
|
|
949
1046
|
const ignored = contextIgnoredWarning(isDir, context);
|
|
@@ -962,7 +1059,8 @@ async function synthApp(app, opts = {}) {
|
|
|
962
1059
|
...hasOverrides && { contextStore: new CdkAppMultiContext(process.cwd(), context) }
|
|
963
1060
|
});
|
|
964
1061
|
}
|
|
965
|
-
const cached = await toolkit.synth(source);
|
|
1062
|
+
const cached = await toolkit.synth(source, stackSelector ? { stacks: stackSelector } : void 0);
|
|
1063
|
+
if (!isDir) cleanupEmptyContextFile(contextFile, contextFileExistedBefore);
|
|
966
1064
|
try {
|
|
967
1065
|
const missingKeys = missingContextKeys(collectMissingRecursively(cached.cloudAssembly));
|
|
968
1066
|
if (missingKeys.length > 0) {
|
|
@@ -1056,10 +1154,12 @@ async function resolveProfileRegion(profile) {
|
|
|
1056
1154
|
async function resolveStacks(a) {
|
|
1057
1155
|
const app = resolveApp(a.app);
|
|
1058
1156
|
if (!app) throw new Error("cdkrd needs a CDK app: run in a directory with cdk.json, pass --app \"<cmd>\" or --app <cdk.out> (a pre-synthesized assembly), or set $CDKRD_APP");
|
|
1157
|
+
const scopePatterns = !a.all && a.stackNames.length > 0 ? a.stackNames : void 0;
|
|
1059
1158
|
const discovered = await discoverStacks(app, {
|
|
1060
1159
|
region: a.region,
|
|
1061
1160
|
profile: a.profile,
|
|
1062
|
-
context: a.context
|
|
1161
|
+
context: a.context,
|
|
1162
|
+
stackPatterns: scopePatterns
|
|
1063
1163
|
});
|
|
1064
1164
|
let fallbackRegion = a.region;
|
|
1065
1165
|
if (!fallbackRegion && discovered.some((s) => !s.region)) {
|
|
@@ -1112,8 +1212,8 @@ function isScalarInterpolant(v) {
|
|
|
1112
1212
|
const t = typeof v;
|
|
1113
1213
|
return t === "string" || t === "number" || t === "boolean";
|
|
1114
1214
|
}
|
|
1115
|
-
function resolve$1(node, ctx) {
|
|
1116
|
-
if (Array.isArray(node)) return node.map((n) => resolve$1(n, ctx));
|
|
1215
|
+
function resolve$1(node, ctx, inCondition = false) {
|
|
1216
|
+
if (Array.isArray(node)) return node.map((n) => resolve$1(n, ctx, inCondition));
|
|
1117
1217
|
if (typeof node === "string" && isDynamicReference(node)) return UNRESOLVED;
|
|
1118
1218
|
if (node === null || typeof node !== "object") return node;
|
|
1119
1219
|
const obj = node;
|
|
@@ -1214,14 +1314,16 @@ function resolve$1(node, ctx) {
|
|
|
1214
1314
|
const r = condVal(v[0], ctx);
|
|
1215
1315
|
return r === UNRESOLVED ? UNRESOLVED : !r;
|
|
1216
1316
|
}
|
|
1217
|
-
case "Condition":
|
|
1317
|
+
case "Condition":
|
|
1318
|
+
if (inCondition) return evalCondition(String(v), ctx);
|
|
1319
|
+
break;
|
|
1218
1320
|
default:
|
|
1219
1321
|
if (k.startsWith("Fn::")) return UNRESOLVED;
|
|
1220
1322
|
break;
|
|
1221
1323
|
}
|
|
1222
1324
|
}
|
|
1223
1325
|
const out = {};
|
|
1224
|
-
for (const [kk, vv] of Object.entries(obj)) out[kk] = resolve$1(vv, ctx);
|
|
1326
|
+
for (const [kk, vv] of Object.entries(obj)) out[kk] = resolve$1(vv, ctx, inCondition);
|
|
1225
1327
|
return out;
|
|
1226
1328
|
}
|
|
1227
1329
|
function scalarEqual(a, b) {
|
|
@@ -1236,7 +1338,7 @@ function condVal(node, ctx) {
|
|
|
1236
1338
|
const r = evalCondition(String(node["Condition"]), ctx);
|
|
1237
1339
|
return r === UNRESOLVED ? UNRESOLVED : r === true;
|
|
1238
1340
|
}
|
|
1239
|
-
const r = resolve$1(node, ctx);
|
|
1341
|
+
const r = resolve$1(node, ctx, true);
|
|
1240
1342
|
if (r === true) return true;
|
|
1241
1343
|
if (r === false) return false;
|
|
1242
1344
|
return UNRESOLVED;
|
|
@@ -1244,7 +1346,7 @@ function condVal(node, ctx) {
|
|
|
1244
1346
|
function evalCondition(name, ctx) {
|
|
1245
1347
|
if (ctx.condCache.has(name)) return ctx.condCache.get(name);
|
|
1246
1348
|
ctx.condCache.set(name, UNRESOLVED);
|
|
1247
|
-
const r = resolve$1(ctx.conditions[name], ctx);
|
|
1349
|
+
const r = resolve$1(ctx.conditions[name], ctx, true);
|
|
1248
1350
|
const val = r === true ? true : r === false ? false : UNRESOLVED;
|
|
1249
1351
|
ctx.condCache.set(name, val);
|
|
1250
1352
|
return val;
|
|
@@ -1498,6 +1600,7 @@ const KNOWN_DEFAULTS = {
|
|
|
1498
1600
|
Description: ""
|
|
1499
1601
|
},
|
|
1500
1602
|
"AWS::IAM::ServerCertificate": { Path: "/" },
|
|
1603
|
+
"AWS::CertificateManager::Certificate": { KeyAlgorithm: "RSA_2048" },
|
|
1501
1604
|
"AWS::AppRunner::Service": {
|
|
1502
1605
|
HealthCheckConfiguration: {
|
|
1503
1606
|
Protocol: "TCP",
|
|
@@ -3398,7 +3501,8 @@ const READGAP_COLLECTION_PATHS = {
|
|
|
3398
3501
|
"AWS::Batch::JobDefinition": new Set(["Timeout"]),
|
|
3399
3502
|
"AWS::Budgets::Budget": new Set(["NotificationsWithSubscribers"]),
|
|
3400
3503
|
"AWS::DynamoDB::GlobalTable": new Set(["SSESpecification"]),
|
|
3401
|
-
"AWS::DynamoDB::Table": new Set(["SSESpecification"])
|
|
3504
|
+
"AWS::DynamoDB::Table": new Set(["SSESpecification"]),
|
|
3505
|
+
"AWS::CertificateManager::Certificate": new Set(["DomainValidationOptions"])
|
|
3402
3506
|
};
|
|
3403
3507
|
const SCALAR_RETURNED_WHEN_SET = {
|
|
3404
3508
|
"AWS::NetworkFirewall::RuleGroup": new Set(["Description"]),
|
|
@@ -3719,6 +3823,14 @@ function parseCfnTemplate(text) {
|
|
|
3719
3823
|
function parseTemplateBody(body) {
|
|
3720
3824
|
return parseCfnTemplate(body);
|
|
3721
3825
|
}
|
|
3826
|
+
function deletedResourceInfo(physIds, template, stackName) {
|
|
3827
|
+
const templateIds = new Set(Object.keys(template.Resources ?? {}));
|
|
3828
|
+
const deleted = Object.keys(physIds).filter((id) => !templateIds.has(id)).sort();
|
|
3829
|
+
if (deleted.length === 0) return null;
|
|
3830
|
+
const shown = deleted.slice(0, 10);
|
|
3831
|
+
const more = deleted.length > shown.length ? `, …(+${deleted.length - shown.length} more)` : "";
|
|
3832
|
+
return `info: ${stackName}: ${deleted.length} deployed resource(s) absent from the local template — the next deploy will DELETE them: ${shown.join(", ")}${more}`;
|
|
3833
|
+
}
|
|
3722
3834
|
function partitionForRegion(region) {
|
|
3723
3835
|
if (region.startsWith("us-gov-")) return {
|
|
3724
3836
|
partition: "aws-us-gov",
|
|
@@ -3850,6 +3962,10 @@ async function loadDesired(client, stackName, region, templateOverride, recovery
|
|
|
3850
3962
|
if (value === "****") continue;
|
|
3851
3963
|
stackParams[p.ParameterKey] = value;
|
|
3852
3964
|
}
|
|
3965
|
+
if (templateOverride) {
|
|
3966
|
+
const deletedInfo = deletedResourceInfo(physIds, template, stackName);
|
|
3967
|
+
if (deletedInfo) console.error(deletedInfo);
|
|
3968
|
+
}
|
|
3853
3969
|
const ctx = buildResolverContext(template, stackParams, physIds, region, accountId, stackName, stackId);
|
|
3854
3970
|
const notificationArns = stack?.NotificationARNs ?? [];
|
|
3855
3971
|
if (notificationArns.length > 0) ctx.params["AWS::NotificationARNs"] = notificationArns;
|
|
@@ -4646,21 +4762,37 @@ function collectNestedUndeclared(declaredVal, liveVal, path, emit, nestedArrayId
|
|
|
4646
4762
|
}
|
|
4647
4763
|
}
|
|
4648
4764
|
const PATH_UNSAFE_KEY = /[.[\]]/;
|
|
4649
|
-
function
|
|
4765
|
+
function sortScalarSet(v) {
|
|
4766
|
+
if (Array.isArray(v) && v.every((e) => typeof e === "string" || typeof e === "number" || typeof e === "boolean")) return [...v].sort((a, b) => `${typeof a}:${String(a)}` < `${typeof b}:${String(b)}` ? -1 : 1);
|
|
4767
|
+
return v;
|
|
4768
|
+
}
|
|
4769
|
+
function sortScalarSetAtNestedPath(model, segs) {
|
|
4770
|
+
if (segs.length === 0 || model === null || typeof model !== "object") return;
|
|
4771
|
+
const [head, ...rest] = segs;
|
|
4772
|
+
if (head === "*") {
|
|
4773
|
+
const children = Array.isArray(model) ? model : Object.values(model);
|
|
4774
|
+
for (const child of children) sortScalarSetAtNestedPath(child, rest);
|
|
4775
|
+
return;
|
|
4776
|
+
}
|
|
4777
|
+
if (Array.isArray(model)) return;
|
|
4778
|
+
const obj = model;
|
|
4779
|
+
if (!(head in obj)) return;
|
|
4780
|
+
if (rest.length === 0) obj[head] = sortScalarSet(obj[head]);
|
|
4781
|
+
else sortScalarSetAtNestedPath(obj[head], rest);
|
|
4782
|
+
}
|
|
4783
|
+
function sortUnorderedSetProps(model, resourceType, schemaObjectArrayKeys = [], schemaScalarPaths = []) {
|
|
4650
4784
|
const objKeys = new Set([...UNORDERED_OBJECT_ARRAY_PROPS[resourceType] ?? [], ...schemaObjectArrayKeys]);
|
|
4651
4785
|
const orderSig = ORDER_SIGNIFICANT_ARRAY_KEYS[resourceType];
|
|
4652
4786
|
for (const k of objKeys) if (!orderSig?.has(k) && Array.isArray(model[k])) model[k] = sortUnorderedObjectArray(model[k]);
|
|
4653
|
-
for (const
|
|
4654
|
-
|
|
4655
|
-
if (Array.isArray(v) && v.every((e) => typeof e === "string" || typeof e === "number" || typeof e === "boolean")) model[k] = [...v].sort((a, b) => `${typeof a}:${String(a)}` < `${typeof b}:${String(b)}` ? -1 : 1);
|
|
4656
|
-
}
|
|
4787
|
+
for (const path of [...UNORDERED_ARRAY_PROPS[resourceType] ?? [], ...schemaScalarPaths]) if (path.includes(".")) sortScalarSetAtNestedPath(model, path.split("."));
|
|
4788
|
+
else if (path in model) model[path] = sortScalarSet(model[path]);
|
|
4657
4789
|
}
|
|
4658
4790
|
function normalizeLiveModel(liveRaw, schema, opts = {}) {
|
|
4659
4791
|
const oaiMap = opts.oaiCanonicalIds ?? {};
|
|
4660
4792
|
const live = canonicalizeForCompare(rewriteOaiPrincipalsDeep(stripAwsTagsDeep(stripCcApiAwsManagedFields(liveRaw)), oaiMap), opts.resourceType);
|
|
4661
4793
|
deepStripPaths(live, schema.readOnlyPaths);
|
|
4662
4794
|
deepStripPaths(live, schema.writeOnlyPaths);
|
|
4663
|
-
if (opts.resourceType) sortUnorderedSetProps(live, opts.resourceType, (schema.unorderedObjectArrayPaths ?? []).filter((p) => !p.includes(".")));
|
|
4795
|
+
if (opts.resourceType) sortUnorderedSetProps(live, opts.resourceType, (schema.unorderedObjectArrayPaths ?? []).filter((p) => !p.includes(".")), schema.unorderedScalarPaths ?? []);
|
|
4664
4796
|
return live;
|
|
4665
4797
|
}
|
|
4666
4798
|
function remapSortedIndexToDeclared(path, arrayKey, sortedDeclared, rawDeclared) {
|
|
@@ -4793,9 +4925,10 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
|
|
|
4793
4925
|
}
|
|
4794
4926
|
if (resourceType === "AWS::CodeBuild::Project") {
|
|
4795
4927
|
const name = declared["Name"];
|
|
4796
|
-
|
|
4928
|
+
const artifactName = typeof name === "string" ? name : physicalId;
|
|
4929
|
+
if (typeof artifactName === "string") knownDefPaths = {
|
|
4797
4930
|
...knownDefPaths,
|
|
4798
|
-
"Artifacts.Name":
|
|
4931
|
+
"Artifacts.Name": artifactName
|
|
4799
4932
|
};
|
|
4800
4933
|
}
|
|
4801
4934
|
if (resourceType === "AWS::SecretsManager::RotationSchedule") {
|
|
@@ -4808,9 +4941,13 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
|
|
|
4808
4941
|
}
|
|
4809
4942
|
if (resourceType === "AWS::AmazonMQ::Broker") {
|
|
4810
4943
|
const engineType = declared["EngineType"];
|
|
4811
|
-
|
|
4944
|
+
const storageDefault = typeof engineType === "string" ? {
|
|
4945
|
+
ACTIVEMQ: "EFS",
|
|
4946
|
+
RABBITMQ: "EBS"
|
|
4947
|
+
}[engineType.toUpperCase()] : void 0;
|
|
4948
|
+
if (storageDefault !== void 0) knownDef = {
|
|
4812
4949
|
...knownDef,
|
|
4813
|
-
StorageType:
|
|
4950
|
+
StorageType: storageDefault
|
|
4814
4951
|
};
|
|
4815
4952
|
}
|
|
4816
4953
|
if (resourceType === "AWS::Lambda::EventSourceMapping") {
|
|
@@ -7182,6 +7319,10 @@ function diffRdsClusterChildren(input) {
|
|
|
7182
7319
|
}
|
|
7183
7320
|
return added;
|
|
7184
7321
|
}
|
|
7322
|
+
const AAS_MANAGED_READER_PREFIX = "application-autoscaling-";
|
|
7323
|
+
function isAasManagedReader(dbInstanceIdentifier) {
|
|
7324
|
+
return dbInstanceIdentifier.startsWith(AAS_MANAGED_READER_PREFIX);
|
|
7325
|
+
}
|
|
7185
7326
|
async function pageDbInstances(client, clusterId) {
|
|
7186
7327
|
const out = [];
|
|
7187
7328
|
let marker;
|
|
@@ -7214,7 +7355,7 @@ async function enumerateRdsClusterChildren(ctx) {
|
|
|
7214
7355
|
const [instances, clusterMemberIds] = await Promise.all([pageDbInstances(client, clusterId), describeClusterMemberIds(client, clusterId)]);
|
|
7215
7356
|
return diffRdsClusterChildren({
|
|
7216
7357
|
declaredInstanceIds,
|
|
7217
|
-
liveInstances: instances.filter((i) => typeof i.DBInstanceIdentifier === "string").map((i) => ({
|
|
7358
|
+
liveInstances: instances.filter((i) => typeof i.DBInstanceIdentifier === "string" && !isAasManagedReader(i.DBInstanceIdentifier)).map((i) => ({
|
|
7218
7359
|
id: i.DBInstanceIdentifier,
|
|
7219
7360
|
label: i.DBInstanceIdentifier
|
|
7220
7361
|
})),
|
|
@@ -8249,6 +8390,10 @@ const readCodeBuildProject = async ({ physicalId, declared, region }) => {
|
|
|
8249
8390
|
...cache.location !== void 0 && { Location: cache.location },
|
|
8250
8391
|
...cache.modes?.length && { Modes: cache.modes }
|
|
8251
8392
|
};
|
|
8393
|
+
if (Array.isArray(p.tags) && p.tags.length > 0) model.Tags = p.tags.map((t) => ({
|
|
8394
|
+
Key: t.key,
|
|
8395
|
+
Value: t.value
|
|
8396
|
+
}));
|
|
8252
8397
|
return model;
|
|
8253
8398
|
};
|
|
8254
8399
|
const readServiceDiscoveryNamespace = async ({ physicalId, region }) => {
|
|
@@ -8457,8 +8602,20 @@ const readAcmCertificate = async ({ physicalId, declared, region }) => {
|
|
|
8457
8602
|
const model = {};
|
|
8458
8603
|
if (str$1(cert.DomainName)) model.DomainName = cert.DomainName;
|
|
8459
8604
|
if (str$1(cert.KeyAlgorithm)) model.KeyAlgorithm = cert.KeyAlgorithm;
|
|
8460
|
-
const
|
|
8461
|
-
const
|
|
8605
|
+
const declaredSans = Array.isArray(declared.SubjectAlternativeNames) ? declared.SubjectAlternativeNames.filter((s) => str$1(s) !== void 0) : [];
|
|
8606
|
+
const declaresSans = declaredSans.length > 0;
|
|
8607
|
+
let sans = (cert.SubjectAlternativeNames ?? []).filter((s) => str$1(s) !== void 0);
|
|
8608
|
+
const apex = str$1(cert.DomainName);
|
|
8609
|
+
if (declaresSans && apex !== void 0 && !declaredSans.includes(apex)) {
|
|
8610
|
+
let dropped = false;
|
|
8611
|
+
sans = sans.filter((s) => {
|
|
8612
|
+
if (!dropped && s === apex) {
|
|
8613
|
+
dropped = true;
|
|
8614
|
+
return false;
|
|
8615
|
+
}
|
|
8616
|
+
return true;
|
|
8617
|
+
});
|
|
8618
|
+
}
|
|
8462
8619
|
if (declaresSans && sans.length > 0) model.SubjectAlternativeNames = sans;
|
|
8463
8620
|
const pref = str$1(cert.Options?.CertificateTransparencyLoggingPreference);
|
|
8464
8621
|
const declaresOptions = declared.Options !== void 0 && declared.Options !== null && typeof declared.Options === "object";
|
|
@@ -9210,6 +9367,11 @@ const CC_IDENTIFIER_ADAPTERS = {
|
|
|
9210
9367
|
"AWS::ApiGatewayV2::Integration": compositeWith("ApiId"),
|
|
9211
9368
|
"AWS::ApiGatewayV2::Model": compositeWith("ApiId"),
|
|
9212
9369
|
"AWS::ApiGatewayV2::Deployment": compositeWith("ApiId"),
|
|
9370
|
+
"AWS::ApiGatewayV2::ApiMapping": (pid, declared) => {
|
|
9371
|
+
if (pid.includes("|")) return pid;
|
|
9372
|
+
const domainName = declared.DomainName;
|
|
9373
|
+
return typeof domainName === "string" && domainName.length > 0 ? `${pid}|${domainName}` : void 0;
|
|
9374
|
+
},
|
|
9213
9375
|
"AWS::ApiGatewayV2::Authorizer": (pid, declared) => {
|
|
9214
9376
|
if (pid.includes("|")) return pid;
|
|
9215
9377
|
const apiId = declared.ApiId;
|
|
@@ -9255,6 +9417,12 @@ const CC_IDENTIFIER_ADAPTERS = {
|
|
|
9255
9417
|
const restApiId = declared.RestApiId;
|
|
9256
9418
|
return typeof restApiId === "string" && restApiId.length > 0 ? `${pid}|${restApiId}` : void 0;
|
|
9257
9419
|
},
|
|
9420
|
+
"AWS::ApiGateway::BasePathMapping": (pid, declared) => {
|
|
9421
|
+
if (pid.includes("|")) return pid;
|
|
9422
|
+
const domainName = declared.DomainName;
|
|
9423
|
+
if (typeof domainName !== "string" || domainName.length === 0) return void 0;
|
|
9424
|
+
return `${domainName}|${typeof declared.BasePath === "string" ? declared.BasePath : ""}`;
|
|
9425
|
+
},
|
|
9258
9426
|
"AWS::ApplicationAutoScaling::ScalingPolicy": scalingPolicyComposite,
|
|
9259
9427
|
"AWS::ECS::Service": (pid, declared) => {
|
|
9260
9428
|
if (pid.includes("|")) return pid;
|
|
@@ -13676,6 +13844,9 @@ const INFO_TIERS = [
|
|
|
13676
13844
|
"unresolved",
|
|
13677
13845
|
"skipped"
|
|
13678
13846
|
];
|
|
13847
|
+
function isPendingCreationSkip$1(f) {
|
|
13848
|
+
return f.tier === "skipped" && f.note === "no physical id";
|
|
13849
|
+
}
|
|
13679
13850
|
function formatFinding(f, stackName = "") {
|
|
13680
13851
|
const id = f.constructPath ? withinStackPath(f.constructPath, stackName) : f.logicalId;
|
|
13681
13852
|
const pathDisplay = f.attributeKey ? `${f.path}[${sanitizeForTerminal(f.attributeKey)}]` : f.path;
|
|
@@ -13838,9 +14009,20 @@ function report(rawFindings, header, opts = {}) {
|
|
|
13838
14009
|
if (t === "skipped") return `skipped=${items.length} — NOT checked (coverage incomplete: ${groupReasons(items)})`;
|
|
13839
14010
|
return `${t}=${items.length} (${groupReasons(items)})`;
|
|
13840
14011
|
};
|
|
13841
|
-
const
|
|
14012
|
+
const skippedSummaryFor = (items) => {
|
|
14013
|
+
if (!opts.preDeploy) return [summaryFor("skipped", items)];
|
|
14014
|
+
const pending = items.filter(isPendingCreationSkip$1);
|
|
14015
|
+
const gaps = items.filter((f) => !isPendingCreationSkip$1(f));
|
|
14016
|
+
const lines = [];
|
|
14017
|
+
if (gaps.length > 0) lines.push(summaryFor("skipped", gaps));
|
|
14018
|
+
if (pending.length > 0) lines.push(`pending creation=${pending.length} (not yet deployed — the next deploy will create them, not a coverage gap)`);
|
|
14019
|
+
return lines;
|
|
14020
|
+
};
|
|
14021
|
+
const summaries = INFO_TIERS.filter((t) => !isExpanded(t)).flatMap((t) => {
|
|
13842
14022
|
const items = byTier(t);
|
|
13843
|
-
|
|
14023
|
+
if (items.length === 0) return [];
|
|
14024
|
+
if (t === "skipped") return skippedSummaryFor(items);
|
|
14025
|
+
return [summaryFor(t, items)];
|
|
13844
14026
|
}).filter((s) => s !== null);
|
|
13845
14027
|
if (nestedFolded.length > 0) summaries.push(`undeclared-subkey=${nestedFolded.length} (undeclared live-only values inside a declared object — record to record; --show-all to list)`);
|
|
13846
14028
|
if (summaries.length === 1) log(style.note(`info: ${summaries[0]} — run with --verbose for the list`));
|
|
@@ -14128,10 +14310,16 @@ function buildScopeOptions(shownCount, foldedCount) {
|
|
|
14128
14310
|
* to be prompted, so it gets the full set, matching the pre-gate `--yes` behaviour). The
|
|
14129
14311
|
* `--yes` case never reaches the AWS-mutating revert through here (revert has no gate).
|
|
14130
14312
|
*/
|
|
14131
|
-
|
|
14313
|
+
function scopeMessage(stackName, region, foldedCount) {
|
|
14314
|
+
return `${stackLabel$1(stackName, region)}: the report folded ${foldedCount} undeclared value(s) — which to decide on?`;
|
|
14315
|
+
}
|
|
14316
|
+
function perFindingActionMessage(stackName, region) {
|
|
14317
|
+
return `${stackLabel$1(stackName, region)}: assign an action to each finding`;
|
|
14318
|
+
}
|
|
14319
|
+
async function chooseScope(stackName, region, shownCount, foldedCount, yes) {
|
|
14132
14320
|
if (yes || foldedCount === 0 || shownCount === 0) return "all";
|
|
14133
14321
|
const choice = await select({
|
|
14134
|
-
message:
|
|
14322
|
+
message: scopeMessage(stackName, region, foldedCount),
|
|
14135
14323
|
options: buildScopeOptions(shownCount, foldedCount),
|
|
14136
14324
|
initialValue: "shown"
|
|
14137
14325
|
});
|
|
@@ -14287,7 +14475,7 @@ async function recordAll(p) {
|
|
|
14287
14475
|
async function ignoreAll(p) {
|
|
14288
14476
|
const ignorable = p.reconciled.filter((f) => f.tier === "declared" || f.tier === "undeclared" || f.tier === "added");
|
|
14289
14477
|
const foldedCount = ignorable.filter((f) => isFoldedFinding(f, p.verbose)).length;
|
|
14290
|
-
const scope = await chooseScope(p.stackName, ignorable.length - foldedCount, foldedCount, p.yes);
|
|
14478
|
+
const scope = await chooseScope(p.stackName, p.region, ignorable.length - foldedCount, foldedCount, p.yes);
|
|
14291
14479
|
if (scope === null) return null;
|
|
14292
14480
|
const findings = scope === "all" ? ignorable : ignorable.filter((f) => !isFoldedFinding(f, p.verbose));
|
|
14293
14481
|
return (await ignoreStack({
|
|
@@ -14327,14 +14515,14 @@ async function revertAll(p) {
|
|
|
14327
14515
|
}
|
|
14328
14516
|
async function perFinding(p, decidable) {
|
|
14329
14517
|
const foldedCount = decidable.filter((f) => isFoldedFinding(f, p.verbose)).length;
|
|
14330
|
-
const scope = await chooseScope(p.stackName, decidable.length - foldedCount, foldedCount, p.yes);
|
|
14518
|
+
const scope = await chooseScope(p.stackName, p.region, decidable.length - foldedCount, foldedCount, p.yes);
|
|
14331
14519
|
if (scope === null) return null;
|
|
14332
14520
|
const scoped = scope === "all" ? decidable : decidable.filter((f) => !isFoldedFinding(f, p.verbose));
|
|
14333
14521
|
const rows = scoped.map((f) => ({
|
|
14334
14522
|
label: pickerLabel(f, p.stackName),
|
|
14335
14523
|
applicable: applicableActions(f)
|
|
14336
14524
|
}));
|
|
14337
|
-
const chosen = await actionPicker(
|
|
14525
|
+
const chosen = await actionPicker(perFindingActionMessage(p.stackName, p.region), rows);
|
|
14338
14526
|
if (chosen === void 0) return null;
|
|
14339
14527
|
const groups = groupByAction(scoped, chosen);
|
|
14340
14528
|
if (groups.record.length + groups.ignore.length + groups.revert.length === 0) return {
|
|
@@ -14570,6 +14758,7 @@ async function runCheck(args) {
|
|
|
14570
14758
|
if (synthTemplates && !synthTemplates.has(sKey)) {
|
|
14571
14759
|
console.error(`note: ${stackName}: not in the synth output — skipped (--pre-deploy)`);
|
|
14572
14760
|
jsonError(stackName, region, "not in the synth output — skipped (--pre-deploy)");
|
|
14761
|
+
worst = Math.max(worst, a.strict ? 1 : 0);
|
|
14573
14762
|
continue;
|
|
14574
14763
|
}
|
|
14575
14764
|
const gathered = await gatherWithProgress(showProgress, progressLabel(idx, stacks.length, stackName, region), () => gatherFindings(stackName, region, synthTemplates?.get(sKey), template));
|
|
@@ -14684,6 +14873,7 @@ async function runCheck(args) {
|
|
|
14684
14873
|
if (e instanceof StackNotCheckableError) {
|
|
14685
14874
|
console.error(`note: ${stackName}: ${e.message} — skipped`);
|
|
14686
14875
|
jsonError(stackName, region, `${e.message} — skipped`);
|
|
14876
|
+
worst = Math.max(worst, a.strict ? 1 : 0);
|
|
14687
14877
|
continue;
|
|
14688
14878
|
}
|
|
14689
14879
|
console.error(`error: ${stackName}: ${e.message}`);
|
|
@@ -14886,7 +15076,7 @@ EXIT CODES
|
|
|
14886
15076
|
record: 0 = written 2 = error/refused
|
|
14887
15077
|
ignore: 0 = rule(s) written / nothing to ignore 2 = error/refused
|
|
14888
15078
|
revert: 0 = converged/aborted 1 = drift remains 2 = error/apply failure
|
|
14889
|
-
all: 130 = interrupted (Ctrl-C / ESC)
|
|
15079
|
+
all: 130 = interrupted (Ctrl-C / ESC / SIGINT) 143 = terminated (SIGTERM) — never mistaken for clean; an unhandled error always exits 2
|
|
14890
15080
|
|
|
14891
15081
|
The baseline lives at .cdkrd/baselines/<stack>.<accountId>.<region>.json — commit it; review
|
|
14892
15082
|
its diff in PRs. Ignore rules live in .cdkrd/ignore.yaml — also git-committed.`;
|