cdk-real-drift 0.7.5 → 0.7.6
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 +106 -4
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -4899,6 +4899,37 @@ function subtractSiblingSgRules(live, prop, siblingRules) {
|
|
|
4899
4899
|
}
|
|
4900
4900
|
if (arr.length === 0) delete live[prop];
|
|
4901
4901
|
}
|
|
4902
|
+
const IAM_ATTACHMENT_REFLECTION_TYPES = new Set([
|
|
4903
|
+
"AWS::IAM::Role",
|
|
4904
|
+
"AWS::IAM::User",
|
|
4905
|
+
"AWS::IAM::Group"
|
|
4906
|
+
]);
|
|
4907
|
+
const MANAGED_POLICY_ARNS_PROP = "ManagedPolicyArns";
|
|
4908
|
+
function managedPolicyRefMatches(liveVal, sibVal) {
|
|
4909
|
+
if (typeof liveVal !== "string" || typeof sibVal !== "string") return false;
|
|
4910
|
+
if (liveVal === sibVal) return true;
|
|
4911
|
+
const tail = (s) => s.startsWith("arn:") ? s.split("/").pop() ?? s : s;
|
|
4912
|
+
return tail(liveVal) === tail(sibVal);
|
|
4913
|
+
}
|
|
4914
|
+
function subtractSiblingManagedPolicyArns(live, siblingArns) {
|
|
4915
|
+
const arr = live[MANAGED_POLICY_ARNS_PROP];
|
|
4916
|
+
if (!Array.isArray(arr) || siblingArns.length === 0) return;
|
|
4917
|
+
for (const sib of siblingArns) {
|
|
4918
|
+
const i = arr.findIndex((el) => managedPolicyRefMatches(el, sib));
|
|
4919
|
+
if (i >= 0) arr.splice(i, 1);
|
|
4920
|
+
}
|
|
4921
|
+
if (arr.length === 0) delete live[MANAGED_POLICY_ARNS_PROP];
|
|
4922
|
+
}
|
|
4923
|
+
const USER_GROUPS_PROP = "Groups";
|
|
4924
|
+
function subtractSiblingUserGroups(live, siblingGroups) {
|
|
4925
|
+
const arr = live[USER_GROUPS_PROP];
|
|
4926
|
+
if (!Array.isArray(arr) || siblingGroups.length === 0) return;
|
|
4927
|
+
for (const sib of siblingGroups) {
|
|
4928
|
+
const i = arr.findIndex((el) => el === sib);
|
|
4929
|
+
if (i >= 0) arr.splice(i, 1);
|
|
4930
|
+
}
|
|
4931
|
+
if (arr.length === 0) delete live[USER_GROUPS_PROP];
|
|
4932
|
+
}
|
|
4902
4933
|
const CC_ALT_REPRESENTATION = {
|
|
4903
4934
|
"AWS::EC2::Subnet": {
|
|
4904
4935
|
AvailabilityZoneId: "AvailabilityZone",
|
|
@@ -5281,6 +5312,14 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
|
|
|
5281
5312
|
const sib = physicalId ? opts.siblingSgRules?.[physicalId] : void 0;
|
|
5282
5313
|
if (sib) for (const [prop, side] of Object.entries(SG_RULE_REFLECTION)) subtractSiblingSgRules(live, prop, sib[side]);
|
|
5283
5314
|
}
|
|
5315
|
+
if (IAM_ATTACHMENT_REFLECTION_TYPES.has(resourceType)) {
|
|
5316
|
+
const sibArns = physicalId ? opts.siblingManagedPolicyAttachments?.[physicalId] : void 0;
|
|
5317
|
+
if (sibArns) subtractSiblingManagedPolicyArns(live, sibArns);
|
|
5318
|
+
if (resourceType === "AWS::IAM::User") {
|
|
5319
|
+
const sibGroups = physicalId ? opts.siblingUserGroups?.[physicalId] : void 0;
|
|
5320
|
+
if (sibGroups) subtractSiblingUserGroups(live, sibGroups);
|
|
5321
|
+
}
|
|
5322
|
+
}
|
|
5284
5323
|
if (resourceType === "AWS::S3::Bucket" && physicalId && opts.bucketNotificationManaged?.has(physicalId) && !("NotificationConfiguration" in declared)) delete live.NotificationConfiguration;
|
|
5285
5324
|
const echoSpec = CLUSTER_ECHO_CHILD[resourceType];
|
|
5286
5325
|
const echoModel = echoSpec && physicalId ? opts.clusterEchoModel?.[physicalId] : void 0;
|
|
@@ -10299,6 +10338,62 @@ function buildBucketNotificationManaged(desired) {
|
|
|
10299
10338
|
}
|
|
10300
10339
|
return managed;
|
|
10301
10340
|
}
|
|
10341
|
+
const MANAGED_POLICY_TYPE = "AWS::IAM::ManagedPolicy";
|
|
10342
|
+
const MANAGED_POLICY_ATTACH_SIDES = [
|
|
10343
|
+
"Roles",
|
|
10344
|
+
"Users",
|
|
10345
|
+
"Groups"
|
|
10346
|
+
];
|
|
10347
|
+
function buildSiblingManagedPolicyAttachments(desired) {
|
|
10348
|
+
const byLogicalId = /* @__PURE__ */ new Map();
|
|
10349
|
+
for (const r of desired.resources) if (r.physicalId) byLogicalId.set(r.logicalId, r.physicalId);
|
|
10350
|
+
const map = {};
|
|
10351
|
+
for (const r of desired.resources) {
|
|
10352
|
+
if (r.resourceType !== MANAGED_POLICY_TYPE) continue;
|
|
10353
|
+
const decl = r.declared;
|
|
10354
|
+
if (!decl || typeof decl !== "object") continue;
|
|
10355
|
+
const d = decl;
|
|
10356
|
+
const attached = r.physicalId ?? (typeof d.ManagedPolicyName === "string" && d.ManagedPolicyName ? d.ManagedPolicyName : void 0);
|
|
10357
|
+
if (!attached) continue;
|
|
10358
|
+
for (const side of MANAGED_POLICY_ATTACH_SIDES) {
|
|
10359
|
+
const list = d[side];
|
|
10360
|
+
if (!Array.isArray(list)) continue;
|
|
10361
|
+
for (const principal of list) {
|
|
10362
|
+
const key = resolvePrincipalKey(principal, byLogicalId);
|
|
10363
|
+
if (key) (map[key] ??= []).push(attached);
|
|
10364
|
+
}
|
|
10365
|
+
}
|
|
10366
|
+
}
|
|
10367
|
+
return map;
|
|
10368
|
+
}
|
|
10369
|
+
const USER_TO_GROUP_TYPE = "AWS::IAM::UserToGroupAddition";
|
|
10370
|
+
function buildSiblingUserGroups(desired) {
|
|
10371
|
+
const byLogicalId = /* @__PURE__ */ new Map();
|
|
10372
|
+
for (const r of desired.resources) if (r.physicalId) byLogicalId.set(r.logicalId, r.physicalId);
|
|
10373
|
+
const map = {};
|
|
10374
|
+
for (const r of desired.resources) {
|
|
10375
|
+
if (r.resourceType !== USER_TO_GROUP_TYPE) continue;
|
|
10376
|
+
const decl = r.declared;
|
|
10377
|
+
if (!decl || typeof decl !== "object") continue;
|
|
10378
|
+
const d = decl;
|
|
10379
|
+
const group = resolvePrincipalKey(d.GroupName, byLogicalId);
|
|
10380
|
+
if (!group) continue;
|
|
10381
|
+
const users = d.Users;
|
|
10382
|
+
if (!Array.isArray(users)) continue;
|
|
10383
|
+
for (const user of users) {
|
|
10384
|
+
const key = resolvePrincipalKey(user, byLogicalId);
|
|
10385
|
+
if (key) (map[key] ??= []).push(group);
|
|
10386
|
+
}
|
|
10387
|
+
}
|
|
10388
|
+
return map;
|
|
10389
|
+
}
|
|
10390
|
+
function resolvePrincipalKey(ref, byLogicalId) {
|
|
10391
|
+
if (typeof ref === "string" && ref) return ref;
|
|
10392
|
+
if (ref && typeof ref === "object" && "Ref" in ref) {
|
|
10393
|
+
const logicalId = ref.Ref;
|
|
10394
|
+
if (typeof logicalId === "string") return byLogicalId.get(logicalId);
|
|
10395
|
+
}
|
|
10396
|
+
}
|
|
10302
10397
|
function buildClusterEchoModels(desired) {
|
|
10303
10398
|
const parentTypes = new Set(Object.values(CLUSTER_ECHO_CHILD).map((s) => s.parentType));
|
|
10304
10399
|
const clusterByPhys = {};
|
|
@@ -10452,6 +10547,8 @@ async function gatherFindings(stackName, region, templateOverride, recoveryTempl
|
|
|
10452
10547
|
oaiCanonicalIds,
|
|
10453
10548
|
siblingSgRules: buildSiblingSgRules(desired),
|
|
10454
10549
|
siblingEventBusPolicies: buildSiblingEventBusPolicies(desired),
|
|
10550
|
+
siblingManagedPolicyAttachments: buildSiblingManagedPolicyAttachments(desired),
|
|
10551
|
+
siblingUserGroups: buildSiblingUserGroups(desired),
|
|
10455
10552
|
bucketNotificationManaged: buildBucketNotificationManaged(desired),
|
|
10456
10553
|
clusterEchoModel: buildClusterEchoModels(desired)
|
|
10457
10554
|
};
|
|
@@ -10511,6 +10608,8 @@ async function regatherTouched(gathered, touched, region) {
|
|
|
10511
10608
|
oaiCanonicalIds,
|
|
10512
10609
|
siblingSgRules: buildSiblingSgRules(desired),
|
|
10513
10610
|
siblingEventBusPolicies: buildSiblingEventBusPolicies(desired),
|
|
10611
|
+
siblingManagedPolicyAttachments: buildSiblingManagedPolicyAttachments(desired),
|
|
10612
|
+
siblingUserGroups: buildSiblingUserGroups(desired),
|
|
10514
10613
|
bucketNotificationManaged: buildBucketNotificationManaged(desired),
|
|
10515
10614
|
clusterEchoModel: buildClusterEchoModels(desired)
|
|
10516
10615
|
};
|
|
@@ -14773,21 +14872,24 @@ async function revertStack(p) {
|
|
|
14773
14872
|
for (const item of plan.items) {
|
|
14774
14873
|
if (item.kind === "delete" || !okIds.has(item.logicalId)) continue;
|
|
14775
14874
|
for (const op of item.ops) {
|
|
14776
|
-
if (op.op !== "remove") continue;
|
|
14875
|
+
if (op.op !== "remove" && op.op !== "add") continue;
|
|
14777
14876
|
const dotted = op.path.replace(/^\//, "").replace(/\//g, ".");
|
|
14778
14877
|
const key = `${item.logicalId}\0${dotted}`;
|
|
14779
14878
|
if (!preActual.has(key)) continue;
|
|
14780
14879
|
const pre = preActual.get(key);
|
|
14781
|
-
|
|
14880
|
+
const post0 = post.find((f) => f.logicalId === item.logicalId && f.path === dotted && !isDrift(f));
|
|
14881
|
+
const persisted = post0 !== void 0 && deepEqual(post0.actual, pre);
|
|
14882
|
+
if (op.op === "remove" ? persisted : persisted && !deepEqual(post0.actual, op.value)) noOpRemovals.push({
|
|
14782
14883
|
displayId: item.displayId,
|
|
14783
|
-
path: dotted
|
|
14884
|
+
path: dotted,
|
|
14885
|
+
kind: op.op
|
|
14784
14886
|
});
|
|
14785
14887
|
}
|
|
14786
14888
|
}
|
|
14787
14889
|
const unverified = post.filter((f) => touched.has(f.logicalId) && f.tier === "skipped").length;
|
|
14788
14890
|
const unconfirmed = unverified + failedDeleteIds.size + failedUpdateIds.size;
|
|
14789
14891
|
const converged = remaining === 0 && unconfirmed === 0 && noOpRemovals.length === 0;
|
|
14790
|
-
for (const n of noOpRemovals) out(style.fail(` NOT reverted: ${n.displayId}.${n.path} — removal was a no-op (the provider ignored the omitted property; it needs an explicit default write — see #597 / REVERT_SET_DEFAULT_PATHS)`));
|
|
14892
|
+
for (const n of noOpRemovals) out(style.fail(n.kind === "remove" ? ` NOT reverted: ${n.displayId}.${n.path} — removal was a no-op (the provider ignored the omitted property; it needs an explicit default write — see #597 / REVERT_SET_DEFAULT_PATHS)` : ` NOT reverted: ${n.displayId}.${n.path} — the default-value write was a no-op (the provider accepted but ignored it; the out-of-band value persists — see #763 / REVERT_SET_DEFAULT_PATHS)`));
|
|
14791
14893
|
const notConverged = unconfirmed + noOpRemovals.length;
|
|
14792
14894
|
out(converged ? style.clean(`${stackName}: CLEAN after revert.`) : remaining > 0 ? style.drift(`${stackName}: ${remaining} drift(s) remain.`) : style.drift(`${stackName}: revert applied, but ${notConverged} value(s) could not be confirmed converged (see above).`));
|
|
14793
14895
|
const unrecordedLeft = unrecordedCount(post);
|