cdk-real-drift 0.2.77 → 0.2.79
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 +22 -7
- package/dist/cli.js +44 -8
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -345,7 +345,7 @@ CI (with `--yes`).
|
|
|
345
345
|
|
|
346
346
|
| option | meaning |
|
|
347
347
|
| -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
348
|
-
| `--region <r>` |
|
|
348
|
+
| `--region <r>` | a stack's own `env.region` ALWAYS wins; for an env-AGNOSTIC stack (no `env`) it falls back to `--region` (or `$AWS_REGION` / `$AWS_DEFAULT_REGION`), else the `--profile`'s region |
|
|
349
349
|
| `--profile <p>` | AWS profile (or `$AWS_PROFILE`) |
|
|
350
350
|
| `-a, --app <cmd\|cdk.out>` | CDK app command or pre-synthesized assembly dir (or `$CDKRD_APP` / cdk.json `"app"`); stack auto-discovery + construct paths |
|
|
351
351
|
| `-c, --context key=value` | context for synth (repeatable; cdk.json is the base layer) |
|
|
@@ -353,14 +353,14 @@ CI (with `--yes`).
|
|
|
353
353
|
| `--json` | machine-readable output (see [JSON contract](#json-output-contract)) |
|
|
354
354
|
| `--fail` | (check) exit 1 on drift and never prompt; for scripts/CI. Without it, check reports drift but exits 0 |
|
|
355
355
|
| `--strict` | (check) exit 1 when coverage is incomplete. A coverage gap is always surfaced loudly; `--strict` makes it CI-failing. Orthogonal to `--fail` |
|
|
356
|
-
| `--show-all` | inventory mode: show all current undeclared state, ignoring the baseline
|
|
357
|
-
| `--verbose` / `-v` | (check) expand the `info:` footer tiers / (revert) expand the
|
|
356
|
+
| `--show-all` | (check) inventory mode: show all current undeclared state, ignoring the baseline |
|
|
357
|
+
| `--verbose` / `-v` | (check) expand the `info:` footer tiers / (revert) expand the not-revertable summary to full lists; (record) itemizes nested sub-keys in the multiselect |
|
|
358
358
|
| `--pre-deploy` | (check) compare live vs the LOCAL synth template: the declared drift your next `cdk deploy` would silently overwrite |
|
|
359
359
|
| `--undeclared-only` | (check) undeclared drift only: pair cdkrd with `cdk drift` for the declared side |
|
|
360
360
|
| `--declared-only` | (check) declared drift vs the deployed template only (undeclared tier skipped; baseline untouched). Not `--pre-deploy` |
|
|
361
361
|
| `--dry-run` | (revert) print the plan; make no changes |
|
|
362
362
|
| `--wait[=DURATION]` | (revert) on a transient "resource is mid-update" error (e.g. Route53Resolver `RSLVR-00705`) keep retrying until it settles, up to DURATION (default `10m`; e.g. `--wait=5m`, `--wait=90s`) |
|
|
363
|
-
| `--remove-unrecorded` | (revert) REMOVE unrecorded values + DELETE unrecorded added resources in a no-prompt run (`--yes`/CI); an interactive revert already lists them
|
|
363
|
+
| `--remove-unrecorded` | (revert, and check for its inline revert) REMOVE unrecorded values + DELETE unrecorded added resources in a no-prompt run (`--yes`/CI); an interactive revert already lists them |
|
|
364
364
|
| `--yes` / `-y` | skip confirmations (revert apply; record records all without the multiselect) |
|
|
365
365
|
|
|
366
366
|
Unknown options (`--apq`) and options missing their value (`--app` at the end of
|
|
@@ -371,8 +371,10 @@ the line) are errors (exit `2`): a typo'd flag never silently becomes a stack na
|
|
|
371
371
|
Every option runs exactly the same code as the standalone commands. Prompts are
|
|
372
372
|
skipped under `--json`, `--show-all`, `--pre-deploy`, and `--fail`. A non-TTY run
|
|
373
373
|
never prompts: a required write decision without `--yes` errors with exit 2 (the
|
|
374
|
-
safe side); `--yes`
|
|
375
|
-
|
|
374
|
+
safe side); `--yes` in a TTY skips the write confirmation AND each verb's selection
|
|
375
|
+
multiselect — `record` records ALL, `ignore` ignores ALL, `revert` applies the full
|
|
376
|
+
plan. Only `check`'s action menu (Record / Revert / Ignore / …) still shows under
|
|
377
|
+
`--yes`.
|
|
376
378
|
|
|
377
379
|
- **`check` with drift** offers `Record / Revert / Ignore / Decide per finding /
|
|
378
380
|
Nothing` (see [The model](#the-model-one-verb-you-run-three-it-offers)). Each
|
|
@@ -577,7 +579,9 @@ valid JSON value nor JSONL; multi-stack `--json` was unparseable — issue #755.
|
|
|
577
579
|
A **stack that errored or was skipped** before it could be checked still appears as an
|
|
578
580
|
element so a consumer sees which stacks ran: it carries `"error": "<reason>"` alongside
|
|
579
581
|
`"drifted": 0` and an empty `"findings": []`. (`error` is absent on a
|
|
580
|
-
successfully-checked stack.)
|
|
582
|
+
successfully-checked stack.) Its `stack` is `"<name> (<region>)"` as usual, EXCEPT
|
|
583
|
+
when the failure is that no region could be resolved for the stack — then `stack`
|
|
584
|
+
is the bare `"<name>"` (no ` (<region>)` suffix), since there is no region to name.
|
|
581
585
|
|
|
582
586
|
A **stack deleted out of band** — its committed baseline proves it was once deployed but
|
|
583
587
|
it is now gone from CloudFormation — is the strongest drift, so it carries
|
|
@@ -625,6 +629,17 @@ Optional per-finding fields, present only when they apply:
|
|
|
625
629
|
- `modelReadFailed` (`true`) — an `added` resource whose full live model could not be
|
|
626
630
|
read this run (`actual` is only the enumerator's identity snippet); it exists but is
|
|
627
631
|
not change-watchable until the next check.
|
|
632
|
+
- `wholeArrayRevert` (`{ path, value }`) — **internal, revert-only** metadata on a
|
|
633
|
+
`declared` per-element finding inside an unordered object-array (a set the
|
|
634
|
+
service reorders — SecurityGroup rules, PrefixList entries, …): it carries the
|
|
635
|
+
WHOLE declared array so `revert` replaces the array as a unit instead of
|
|
636
|
+
index-patching a sorted position that does not map to the live index.
|
|
637
|
+
Display-only for the report; a consumer can ignore it.
|
|
638
|
+
- `siblingPolicyNames` (`"unresolved"`) — **internal, revert-only** sentinel on a
|
|
639
|
+
`declared` IAM Role `Policies` finding whose sibling `AWS::IAM::Policy` names
|
|
640
|
+
could not be resolved; `revert` reads it and refuses to act (a per-entry revert
|
|
641
|
+
could delete a managed inline policy). The only emitted value is the
|
|
642
|
+
`"unresolved"` string; a consumer can ignore it.
|
|
628
643
|
- On an `added` finding, `desired` carries the **recorded baseline model** and `actual`
|
|
629
644
|
the live one (so a recorded `added` resource that changed shows the delta), and
|
|
630
645
|
`unrecorded` marks a never-recorded one as potential drift.
|
package/dist/cli.js
CHANGED
|
@@ -55,6 +55,22 @@ import { DescribeDomainConfigCommand, OpenSearchClient, UpdateDomainConfigComman
|
|
|
55
55
|
import { GetWebACLCommand, UpdateWebACLCommand, WAFV2Client } from "@aws-sdk/client-wafv2";
|
|
56
56
|
import { ConfigServiceClient, DescribeConfigRulesCommand, PutConfigRuleCommand } from "@aws-sdk/client-config-service";
|
|
57
57
|
|
|
58
|
+
//#region src/exit.ts
|
|
59
|
+
function drain(stream) {
|
|
60
|
+
return new Promise((resolve) => {
|
|
61
|
+
if (stream.writableLength === 0 || stream.writableEnded) {
|
|
62
|
+
resolve();
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
stream.write("", () => resolve());
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
async function flushAndExit(code) {
|
|
69
|
+
await Promise.all([drain(process.stdout), drain(process.stderr)]);
|
|
70
|
+
process.exit(code);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
//#endregion
|
|
58
74
|
//#region src/aws-errors.ts
|
|
59
75
|
function isStackNotDeployed(e) {
|
|
60
76
|
const msg = e?.message ?? String(e);
|
|
@@ -2981,7 +2997,10 @@ function isPropertiesFileEqual(a, b) {
|
|
|
2981
2997
|
for (const [k, v] of ma) if (mb.get(k) !== v) return false;
|
|
2982
2998
|
return true;
|
|
2983
2999
|
}
|
|
2984
|
-
const CASE_INSENSITIVE_ARRAY_PATHS = {
|
|
3000
|
+
const CASE_INSENSITIVE_ARRAY_PATHS = {
|
|
3001
|
+
"AWS::ApiGatewayV2::Api": new Set(["CorsConfiguration.AllowHeaders", "CorsConfiguration.ExposeHeaders"]),
|
|
3002
|
+
"AWS::Lambda::Url": new Set(["Cors.AllowHeaders", "Cors.ExposeHeaders"])
|
|
3003
|
+
};
|
|
2985
3004
|
function isCaseInsensitiveEqualScalarSet(a, b) {
|
|
2986
3005
|
if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) return false;
|
|
2987
3006
|
if (!a.every((v) => typeof v === "string") || !b.every((v) => typeof v === "string")) return false;
|
|
@@ -4151,7 +4170,8 @@ const MEANINGFUL_WHEN_OFF = {
|
|
|
4151
4170
|
"AWS::EC2::Instance": { SourceDestCheck: () => true },
|
|
4152
4171
|
"AWS::EC2::NetworkInterface": { SourceDestCheck: () => true },
|
|
4153
4172
|
"AWS::Cognito::UserPoolClient": { EnableTokenRevocation: () => true },
|
|
4154
|
-
"AWS::CloudWatch::CompositeAlarm": { ActionsEnabled: () => true }
|
|
4173
|
+
"AWS::CloudWatch::CompositeAlarm": { ActionsEnabled: () => true },
|
|
4174
|
+
"AWS::ApplicationInsights::Application": { CWEMonitorEnabled: () => true }
|
|
4155
4175
|
};
|
|
4156
4176
|
const stripCognitoAttrPrefix = (id) => id.replace(/^(custom|dev):/, "");
|
|
4157
4177
|
const IDENTITY_KEYED_SUBSET_ARRAYS = {
|
|
@@ -4964,7 +4984,10 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
|
|
|
4964
4984
|
if (LATEST_SENTINEL_PATHS[resourceType]?.has(d.path) && isLatestSentinelMatch(d.stateValue, d.awsValue)) continue;
|
|
4965
4985
|
if (INTELLIGENT_TIERING_PATHS[resourceType]?.has(d.path) && isIntelligentTieringMatch(d.stateValue, d.awsValue)) continue;
|
|
4966
4986
|
if ((UNORDERED_ARRAY_PROPS[resourceType]?.has(d.path) || UNORDERED_ARRAY_PROPS[resourceType]?.has(d.path.replace(/\.\d+(?=\.|$)/g, ".*")) || schema.unorderedScalarPaths?.includes(d.path)) && isEqualUnorderedScalarSet(d.stateValue, d.awsValue)) continue;
|
|
4967
|
-
if (isTrivialEmpty(d.stateValue) && d.path in knownDef && deepEqual(d.awsValue, knownDef[d.path])
|
|
4987
|
+
if (isTrivialEmpty(d.stateValue) && d.path in knownDef && deepEqual(d.awsValue, knownDef[d.path]) && !(MEANINGFUL_WHEN_OFF[resourceType]?.[d.path]?.({
|
|
4988
|
+
declared,
|
|
4989
|
+
live
|
|
4990
|
+
}) ?? false)) continue;
|
|
4968
4991
|
const unorderedExtra = unorderedObjArray && Array.isArray(declaredVal) && declaredRemapSource ? {
|
|
4969
4992
|
path: remapSortedIndexToDeclared(d.path, k, declaredVal, declaredRemapSource),
|
|
4970
4993
|
wholeArrayRevert: {
|
|
@@ -8845,6 +8868,7 @@ function parseSchema(schemaJson) {
|
|
|
8845
8868
|
const defaultPaths = collectDefaultPaths(schema.definitions ?? {}, schema.properties ?? {});
|
|
8846
8869
|
const unorderedArrayPaths = collectUnorderedArrayPaths(schema.definitions ?? {}, schema.properties ?? {});
|
|
8847
8870
|
const freeFormMapPaths = collectFreeFormMapPaths(schema.definitions ?? {}, schema.properties ?? {});
|
|
8871
|
+
const updatable = schema.handlers === void 0 ? void 0 : Object.hasOwn(schema.handlers, "update");
|
|
8848
8872
|
return {
|
|
8849
8873
|
readOnly: topLevel(readOnlyPaths),
|
|
8850
8874
|
writeOnly: topLevel(writeOnlyPaths),
|
|
@@ -8856,7 +8880,8 @@ function parseSchema(schemaJson) {
|
|
|
8856
8880
|
defaultPaths,
|
|
8857
8881
|
unorderedScalarPaths: unorderedArrayPaths.scalar,
|
|
8858
8882
|
unorderedObjectArrayPaths: unorderedArrayPaths.object,
|
|
8859
|
-
freeFormMapPaths
|
|
8883
|
+
freeFormMapPaths,
|
|
8884
|
+
updatable
|
|
8860
8885
|
};
|
|
8861
8886
|
}
|
|
8862
8887
|
|
|
@@ -11916,6 +11941,15 @@ function buildRevertPlan(findings, baseline, opts = {}) {
|
|
|
11916
11941
|
});
|
|
11917
11942
|
continue;
|
|
11918
11943
|
}
|
|
11944
|
+
if (schema?.updatable === false && !SDK_WRITERS[f.resourceType] && !propScoped && !nestedScoped) {
|
|
11945
|
+
notRevertable.push({
|
|
11946
|
+
displayId,
|
|
11947
|
+
resourceType: f.resourceType,
|
|
11948
|
+
path: f.path,
|
|
11949
|
+
reason: "type has no update handler — detect/record only"
|
|
11950
|
+
});
|
|
11951
|
+
continue;
|
|
11952
|
+
}
|
|
11919
11953
|
const kind = SDK_WRITERS[f.resourceType] || propScoped || nestedScoped ? "sdk" : "cc";
|
|
11920
11954
|
let toRevert = f;
|
|
11921
11955
|
const sgSide = f.tier === "declared" && f.resourceType === "AWS::EC2::SecurityGroup" ? SG_REVERT_SIDE[f.path] : void 0;
|
|
@@ -14258,8 +14292,10 @@ OPTIONS
|
|
|
14258
14292
|
--remove-unrecorded (revert) REMOVE unrecorded values + DELETE unrecorded
|
|
14259
14293
|
added resources (never recorded; default: refuse —
|
|
14260
14294
|
record the ones that are right)
|
|
14261
|
-
--yes, -y skip
|
|
14262
|
-
|
|
14295
|
+
--yes, -y skip the write confirm AND the op multiselect — apply the
|
|
14296
|
+
FULL plan (revert) / skip the selection multiselect +
|
|
14297
|
+
overwrite notice, record ALL (record) / ignore ALL shown
|
|
14298
|
+
drift without the multiselect (ignore)
|
|
14263
14299
|
--help, -h --version, -v
|
|
14264
14300
|
|
|
14265
14301
|
Automation: check --fail / record --yes / ignore --yes / revert --yes (or
|
|
@@ -14305,13 +14341,13 @@ async function main(argv) {
|
|
|
14305
14341
|
return 2;
|
|
14306
14342
|
}
|
|
14307
14343
|
}
|
|
14308
|
-
main(process.argv.slice(2)).then((code) =>
|
|
14344
|
+
main(process.argv.slice(2)).then((code) => flushAndExit(code)).catch((e) => {
|
|
14309
14345
|
const msg = e?.message ?? String(e);
|
|
14310
14346
|
if (/credential|could not load cred|security token/i.test(msg)) console.error("error: no AWS credentials available. Configure them (aws configure / AWS_PROFILE / env vars) and retry.");
|
|
14311
14347
|
else if (/stack/i.test(msg) && /(does not exist|ValidationError)/i.test(msg)) console.error("error: stack not found in this account/region. Check the stack name and --region.");
|
|
14312
14348
|
else if (/AccessDenied|not authorized/i.test(msg)) console.error(`error: access denied — ${msg}`);
|
|
14313
14349
|
else console.error(`error: ${msg}`);
|
|
14314
|
-
|
|
14350
|
+
return flushAndExit(2);
|
|
14315
14351
|
});
|
|
14316
14352
|
|
|
14317
14353
|
//#endregion
|