cdk-real-drift 0.9.4 → 0.9.5
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/dist/cli.js +110 -7
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -3016,7 +3016,11 @@ const VALUE_INDEPENDENT_DEFAULT_TOPLEVEL_PATHS = {
|
|
|
3016
3016
|
"SecurityGroups",
|
|
3017
3017
|
"SubnetIds"
|
|
3018
3018
|
]),
|
|
3019
|
-
"AWS::EC2::Instance": new Set([
|
|
3019
|
+
"AWS::EC2::Instance": new Set([
|
|
3020
|
+
"PrivateIpAddress",
|
|
3021
|
+
"CpuOptions",
|
|
3022
|
+
"SubnetId"
|
|
3023
|
+
]),
|
|
3020
3024
|
"AWS::EC2::NetworkInterface": new Set([
|
|
3021
3025
|
"PrivateIpAddress",
|
|
3022
3026
|
"PrivateIpAddresses",
|
|
@@ -4981,6 +4985,15 @@ function twinOverlapEchoes(source, twin) {
|
|
|
4981
4985
|
}
|
|
4982
4986
|
return true;
|
|
4983
4987
|
}
|
|
4988
|
+
function applyDefinitionSubstitutions(definitionString, substitutions) {
|
|
4989
|
+
let out = definitionString;
|
|
4990
|
+
for (const [key, value] of Object.entries(substitutions)) {
|
|
4991
|
+
if (value === null || typeof value === "object") continue;
|
|
4992
|
+
const token = `\${${key}}`;
|
|
4993
|
+
out = out.split(token).join(String(value));
|
|
4994
|
+
}
|
|
4995
|
+
return out;
|
|
4996
|
+
}
|
|
4984
4997
|
const IAM_ATTACHMENT_SUBSET = { "AWS::IAM::ManagedPolicy": new Set([
|
|
4985
4998
|
"Roles",
|
|
4986
4999
|
"Users",
|
|
@@ -5370,7 +5383,10 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
|
|
|
5370
5383
|
});
|
|
5371
5384
|
const twinSources = {};
|
|
5372
5385
|
for (const src of Object.values(SHAPE_ECHO_TWIN[resourceType] ?? {})) if (isNestedObject(declared[src])) twinSources[src] = declared[src];
|
|
5386
|
+
const sfnDefinitionObject = resourceType === "AWS::StepFunctions::StateMachine" && isNestedObject(declared["Definition"]) ? declared["Definition"] : void 0;
|
|
5387
|
+
const sfnDefinitionSubstitutions = resourceType === "AWS::StepFunctions::StateMachine" && isNestedObject(declared["DefinitionSubstitutions"]) ? declared["DefinitionSubstitutions"] : void 0;
|
|
5373
5388
|
deepStripPaths(declared, schema.writeOnlyPaths);
|
|
5389
|
+
if (sfnDefinitionSubstitutions !== void 0 && typeof declared["DefinitionString"] === "string") declared["DefinitionString"] = applyDefinitionSubstitutions(declared["DefinitionString"], sfnDefinitionSubstitutions);
|
|
5374
5390
|
const sibling = resource.siblingPolicyNames;
|
|
5375
5391
|
if (sibling !== void 0 && sibling !== "unresolved" && Array.isArray(live.Policies)) {
|
|
5376
5392
|
const names = new Set(sibling);
|
|
@@ -5635,6 +5651,26 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
|
|
|
5635
5651
|
});
|
|
5636
5652
|
continue;
|
|
5637
5653
|
}
|
|
5654
|
+
if (resourceType === "AWS::StepFunctions::StateMachine" && k === "DefinitionString" && typeof v === "string" && typeof live[k] === "string") {
|
|
5655
|
+
let declaredParsed;
|
|
5656
|
+
let liveParsed;
|
|
5657
|
+
try {
|
|
5658
|
+
declaredParsed = JSON.parse(v);
|
|
5659
|
+
liveParsed = JSON.parse(live[k]);
|
|
5660
|
+
} catch {
|
|
5661
|
+
declaredParsed = void 0;
|
|
5662
|
+
}
|
|
5663
|
+
if (declaredParsed !== void 0 && deepEqual(declaredParsed, liveParsed)) continue;
|
|
5664
|
+
findings.push({
|
|
5665
|
+
tier: "declared",
|
|
5666
|
+
logicalId,
|
|
5667
|
+
resourceType,
|
|
5668
|
+
path: k,
|
|
5669
|
+
desired: v,
|
|
5670
|
+
actual: live[k]
|
|
5671
|
+
});
|
|
5672
|
+
continue;
|
|
5673
|
+
}
|
|
5638
5674
|
const jsonFills = JSON_STRING_DEFAULT_FILLS[resourceType]?.[k];
|
|
5639
5675
|
if (jsonFills !== void 0 && typeof v === "string" && typeof live[k] === "string") try {
|
|
5640
5676
|
const dvParsed = JSON.parse(v);
|
|
@@ -6110,6 +6146,24 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
|
|
|
6110
6146
|
});
|
|
6111
6147
|
continue;
|
|
6112
6148
|
}
|
|
6149
|
+
if (sfnDefinitionObject !== void 0 && k === "DefinitionString" && typeof v === "string") {
|
|
6150
|
+
let liveDefParsed;
|
|
6151
|
+
try {
|
|
6152
|
+
liveDefParsed = JSON.parse(v);
|
|
6153
|
+
} catch {
|
|
6154
|
+
liveDefParsed = void 0;
|
|
6155
|
+
}
|
|
6156
|
+
if (liveDefParsed !== void 0 && deepEqual(liveDefParsed, sfnDefinitionObject)) {
|
|
6157
|
+
findings.push({
|
|
6158
|
+
tier: "atDefault",
|
|
6159
|
+
logicalId,
|
|
6160
|
+
resourceType,
|
|
6161
|
+
path: k,
|
|
6162
|
+
actual: v
|
|
6163
|
+
});
|
|
6164
|
+
continue;
|
|
6165
|
+
}
|
|
6166
|
+
}
|
|
6113
6167
|
const twinSourceKey = SHAPE_ECHO_TWIN[resourceType]?.[k];
|
|
6114
6168
|
const twinSource = twinSourceKey !== void 0 ? twinSources[twinSourceKey] ?? declared[twinSourceKey] : void 0;
|
|
6115
6169
|
if (isNestedObject(v) && isNestedObject(twinSource) && twinOverlapEchoes(twinSource, v)) {
|
|
@@ -11013,22 +11067,40 @@ async function writeBaselineFile(b) {
|
|
|
11013
11067
|
* be read this run (#795), so undeclared values hidden behind that gap were NOT
|
|
11014
11068
|
* captured — the resource must not claim completeness, else a later cdkrd that
|
|
11015
11069
|
* closes the read gap would surface those newly-visible values as false "appeared
|
|
11016
|
-
* since record" drift.
|
|
11017
|
-
*
|
|
11070
|
+
* since record" drift.
|
|
11071
|
+
*
|
|
11072
|
+
* #1078: an `ignored`-tier value whose path is ABSENT from `recorded` also blocks
|
|
11073
|
+
* completeness (and — unlike the other blocks — DEMOTES a previously-complete
|
|
11074
|
+
* resource, overriding monotonicity). An ignore rule re-tags an undeclared finding
|
|
11075
|
+
* `ignored`, so `buildRecorded` drops it and this value never enters the snapshot;
|
|
11076
|
+
* marking the resource complete anyway would treat that value as "known-absent". But
|
|
11077
|
+
* an ignore rule can be DELETED (the documented un-ignore) — and when it dies the
|
|
11078
|
+
* value (unchanged all along) would then read as false CONFIRMED "appeared since
|
|
11079
|
+
* record" drift against a complete resource, instead of returning to `unrecorded`
|
|
11080
|
+
* `[Potential Drift]`. So an ignored-and-unrecorded path keeps its resource
|
|
11081
|
+
* INCOMPLETE, so un-ignoring lands the untouched value back at `unrecorded`. This
|
|
11082
|
+
* pairs with `carryForwardIgnored` (WRITE side): a value with a PRIOR recorded entry
|
|
11083
|
+
* IS carried into `recorded`, so its path IS present, so it does NOT block here — a
|
|
11084
|
+
* previously-endorsed value survives an ignore-era record and stays complete. Only a
|
|
11085
|
+
* NEVER-recorded ignored path (no entry to carry) demotes completeness.
|
|
11018
11086
|
* Monotonic via `previousComplete`: once complete, a resource stays complete
|
|
11019
11087
|
* (declining to record an appeared-since-record value keeps it drift, instead of
|
|
11020
|
-
* demoting it back to unrecorded) — pruned to ids still in the template.
|
|
11088
|
+
* demoting it back to unrecorded) — pruned to ids still in the template. The #1078
|
|
11089
|
+
* ignored-and-unrecorded demotion is the one deliberate exception (the un-ignore
|
|
11090
|
+
* lifecycle must round-trip).
|
|
11021
11091
|
*/
|
|
11022
11092
|
function computeCompleteResources(allLogicalIds, findings, recorded, previousComplete = []) {
|
|
11023
11093
|
const recordedKeys = new Set(recorded.map(recordedKey));
|
|
11024
11094
|
const blocked = /* @__PURE__ */ new Set();
|
|
11095
|
+
const blockedByIgnore = /* @__PURE__ */ new Set();
|
|
11025
11096
|
for (const f of findings) {
|
|
11026
11097
|
if (f.tier === "skipped" || f.tier === "deleted" || f.tier === "readGap") blocked.add(f.logicalId);
|
|
11027
11098
|
if (f.tier === "undeclared" && !recordedKeys.has(recordedKey(f))) blocked.add(f.logicalId);
|
|
11099
|
+
if (f.tier === "ignored" && !recordedKeys.has(recordedKey(f))) blockedByIgnore.add(f.logicalId);
|
|
11028
11100
|
}
|
|
11029
11101
|
const all = new Set(allLogicalIds);
|
|
11030
|
-
const complete = new Set(previousComplete.filter((id) => all.has(id)));
|
|
11031
|
-
for (const id of allLogicalIds) if (!blocked.has(id)) complete.add(id);
|
|
11102
|
+
const complete = new Set(previousComplete.filter((id) => all.has(id) && !blockedByIgnore.has(id)));
|
|
11103
|
+
for (const id of allLogicalIds) if (!blocked.has(id) && !blockedByIgnore.has(id)) complete.add(id);
|
|
11032
11104
|
return [...complete].sort();
|
|
11033
11105
|
}
|
|
11034
11106
|
/** Write a baseline for a stack from a check run's findings + raw template.
|
|
@@ -11148,6 +11220,37 @@ function carryForwardUnreadable(recorded, existing, findings) {
|
|
|
11148
11220
|
return preserved.length === 0 ? recorded : [...recorded, ...preserved];
|
|
11149
11221
|
}
|
|
11150
11222
|
/**
|
|
11223
|
+
* #1078: carry forward a previously-recorded entry for a path that is CURRENTLY
|
|
11224
|
+
* suppressed by an ignore rule (tier `ignored` this run), so an ignore-era `record`
|
|
11225
|
+
* does not silently PRUNE a value the user already endorsed.
|
|
11226
|
+
*
|
|
11227
|
+
* The `findings` reaching `record` are `applyIgnores`'d first (record.ts /
|
|
11228
|
+
* interactive-resolve.ts), so a value with a live ignore rule arrives tier `ignored`
|
|
11229
|
+
* — and `buildRecorded` keeps only `undeclared`/`added`, so it produces NO entry.
|
|
11230
|
+
* Because `writeBaseline` full-replaces `recorded`, the endorsed entry for that path
|
|
11231
|
+
* would vanish from the git-committed baseline (an unexplained deletion to the PR
|
|
11232
|
+
* reviewer). Then, when the user later DELETES the rule (the documented un-ignore),
|
|
11233
|
+
* the value — unchanged all along — would false-surface as confirmed drift.
|
|
11234
|
+
*
|
|
11235
|
+
* So for every ignored finding whose path already has an entry in the EXISTING
|
|
11236
|
+
* baseline, carry that entry forward. While the rule lives the entry is inert
|
|
11237
|
+
* (`applyIgnores` runs AFTER `applyBaseline` everywhere, so ignore keeps winning — the
|
|
11238
|
+
* value is never reported); when the rule dies, watching resumes against the real,
|
|
11239
|
+
* preserved snapshot (a later genuine change still correctly reports "changed since
|
|
11240
|
+
* record"). Only carries an EXISTING entry — a never-recorded ignored path has none to
|
|
11241
|
+
* carry, and its completeness demotion (see `computeCompleteResources`) makes the
|
|
11242
|
+
* un-ignore land at `unrecorded`, not false "appeared since record".
|
|
11243
|
+
*/
|
|
11244
|
+
function carryForwardIgnored(recorded, existing, findings) {
|
|
11245
|
+
const prior = existing?.recorded;
|
|
11246
|
+
if (!prior || prior.length === 0) return recorded;
|
|
11247
|
+
const ignoredKeys = new Set(findings.filter((f) => f.tier === "ignored").map((f) => recordedKey(f)));
|
|
11248
|
+
if (ignoredKeys.size === 0) return recorded;
|
|
11249
|
+
const present = new Set(recorded.map(recordedKey));
|
|
11250
|
+
const preserved = prior.filter((e) => ignoredKeys.has(recordedKey(e)) && !present.has(recordedKey(e)));
|
|
11251
|
+
return preserved.length === 0 ? recorded : [...recorded, ...preserved];
|
|
11252
|
+
}
|
|
11253
|
+
/**
|
|
11151
11254
|
* The single source of truth for "is this baseline value equal to the current
|
|
11152
11255
|
* value?". `applyBaseline` (suppress vs surface) and `splitRecordedByBaseline`
|
|
11153
11256
|
* (unchanged vs changed) MUST share this exact predicate. BOTH sides are
|
|
@@ -14559,7 +14662,7 @@ async function recordStack(p) {
|
|
|
14559
14662
|
const existing = await loadBaseline(stackName, desired.accountId, region);
|
|
14560
14663
|
if (existing) checkBaselineAccount(existing, desired.accountId, stackName);
|
|
14561
14664
|
if (!yes && existing) console.error(`note: ${stackLabel$1(stackName, region)}: will overwrite the existing baseline file on confirm (nothing written yet; it is git-tracked — review the diff afterwards). Pass --yes to silence.`);
|
|
14562
|
-
let recorded = carryForwardUnreadable(buildRecorded(findings), existing, findings);
|
|
14665
|
+
let recorded = carryForwardIgnored(carryForwardUnreadable(buildRecorded(findings), existing, findings), existing, findings);
|
|
14563
14666
|
const dropCandidates = baselineOnlyEntries(recorded, existing, findings, {
|
|
14564
14667
|
declaredByLogical: declaredKeysByLogical(desired.resources),
|
|
14565
14668
|
allLogicalIds: desired.resources.map((r) => r.logicalId)
|