cdk-real-drift 0.7.5 → 0.8.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/README.md +10 -3
- package/dist/cli.js +153 -5
- package/dist/cli.js.map +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -339,9 +339,16 @@ CI (with `--yes`).
|
|
|
339
339
|
- **`--fail`** (the `cdk diff --fail` / `cdk drift --fail` convention) exits `1` on
|
|
340
340
|
drift and suppresses all prompts. It's the one flag for scripts and CI.
|
|
341
341
|
- **`--strict`** is the orthogonal **coverage** axis: it exits `1` when a run was
|
|
342
|
-
incomplete (
|
|
343
|
-
|
|
344
|
-
|
|
342
|
+
incomplete (a resource skipped for an ACTIONABLE reason — a CC-unsupported type
|
|
343
|
+
with no override, a read error / throttle / AccessDenied — or a nested stack not
|
|
344
|
+
recursed into). A **custom resource** (`Custom::*` /
|
|
345
|
+
`AWS::CloudFormation::CustomResource`, e.g. `Custom::S3AutoDeleteObjects` /
|
|
346
|
+
`Custom::LogRetention`) has no cloud-side model to read, so it is a
|
|
347
|
+
permanent-by-nature gap that no `record` / `ignore` could clear — it is
|
|
348
|
+
**informational** and does NOT fail `--strict` (otherwise the flag would exit `1`
|
|
349
|
+
forever on nearly every real CDK app). The gap is always surfaced regardless (as
|
|
350
|
+
the `skipped=N` footer line or a loud `warning:`); `--strict` only decides whether
|
|
351
|
+
an actionable gap fails the build.
|
|
345
352
|
- Errors always exit `2`; `revert` exits `1` when drift remains after it.
|
|
346
353
|
- Interrupting a run with **Ctrl-C** (or **ESC** / SIGINT) during the gather/read
|
|
347
354
|
phase exits `130` (128 + SIGINT) for every verb, and a **SIGTERM** (CI
|
package/dist/cli.js
CHANGED
|
@@ -48,6 +48,7 @@ import { BuildBotLocaleCommand, CreateIntentCommand, CreateSlotCommand, CreateSl
|
|
|
48
48
|
import { GetScheduleCommand, SchedulerClient } from "@aws-sdk/client-scheduler";
|
|
49
49
|
import { DescribeReceiptRuleCommand, DescribeReceiptRuleSetCommand, ListReceiptFiltersCommand, SESClient, UpdateReceiptRuleCommand } from "@aws-sdk/client-ses";
|
|
50
50
|
import { DescribeParametersCommand as DescribeParametersCommand$2, SSMClient } from "@aws-sdk/client-ssm";
|
|
51
|
+
import { DescribeEndpointConfigCommand, SageMakerClient } from "@aws-sdk/client-sagemaker";
|
|
51
52
|
import { GetNamespaceCommand, GetServiceCommand, ServiceDiscoveryClient, UpdateHttpNamespaceCommand } from "@aws-sdk/client-servicediscovery";
|
|
52
53
|
import { GetQueueAttributesCommand, SQSClient, SetQueueAttributesCommand } from "@aws-sdk/client-sqs";
|
|
53
54
|
import { createHash } from "node:crypto";
|
|
@@ -4899,6 +4900,37 @@ function subtractSiblingSgRules(live, prop, siblingRules) {
|
|
|
4899
4900
|
}
|
|
4900
4901
|
if (arr.length === 0) delete live[prop];
|
|
4901
4902
|
}
|
|
4903
|
+
const IAM_ATTACHMENT_REFLECTION_TYPES = new Set([
|
|
4904
|
+
"AWS::IAM::Role",
|
|
4905
|
+
"AWS::IAM::User",
|
|
4906
|
+
"AWS::IAM::Group"
|
|
4907
|
+
]);
|
|
4908
|
+
const MANAGED_POLICY_ARNS_PROP = "ManagedPolicyArns";
|
|
4909
|
+
function managedPolicyRefMatches(liveVal, sibVal) {
|
|
4910
|
+
if (typeof liveVal !== "string" || typeof sibVal !== "string") return false;
|
|
4911
|
+
if (liveVal === sibVal) return true;
|
|
4912
|
+
const tail = (s) => s.startsWith("arn:") ? s.split("/").pop() ?? s : s;
|
|
4913
|
+
return tail(liveVal) === tail(sibVal);
|
|
4914
|
+
}
|
|
4915
|
+
function subtractSiblingManagedPolicyArns(live, siblingArns) {
|
|
4916
|
+
const arr = live[MANAGED_POLICY_ARNS_PROP];
|
|
4917
|
+
if (!Array.isArray(arr) || siblingArns.length === 0) return;
|
|
4918
|
+
for (const sib of siblingArns) {
|
|
4919
|
+
const i = arr.findIndex((el) => managedPolicyRefMatches(el, sib));
|
|
4920
|
+
if (i >= 0) arr.splice(i, 1);
|
|
4921
|
+
}
|
|
4922
|
+
if (arr.length === 0) delete live[MANAGED_POLICY_ARNS_PROP];
|
|
4923
|
+
}
|
|
4924
|
+
const USER_GROUPS_PROP = "Groups";
|
|
4925
|
+
function subtractSiblingUserGroups(live, siblingGroups) {
|
|
4926
|
+
const arr = live[USER_GROUPS_PROP];
|
|
4927
|
+
if (!Array.isArray(arr) || siblingGroups.length === 0) return;
|
|
4928
|
+
for (const sib of siblingGroups) {
|
|
4929
|
+
const i = arr.findIndex((el) => el === sib);
|
|
4930
|
+
if (i >= 0) arr.splice(i, 1);
|
|
4931
|
+
}
|
|
4932
|
+
if (arr.length === 0) delete live[USER_GROUPS_PROP];
|
|
4933
|
+
}
|
|
4902
4934
|
const CC_ALT_REPRESENTATION = {
|
|
4903
4935
|
"AWS::EC2::Subnet": {
|
|
4904
4936
|
AvailabilityZoneId: "AvailabilityZone",
|
|
@@ -5281,6 +5313,14 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
|
|
|
5281
5313
|
const sib = physicalId ? opts.siblingSgRules?.[physicalId] : void 0;
|
|
5282
5314
|
if (sib) for (const [prop, side] of Object.entries(SG_RULE_REFLECTION)) subtractSiblingSgRules(live, prop, sib[side]);
|
|
5283
5315
|
}
|
|
5316
|
+
if (IAM_ATTACHMENT_REFLECTION_TYPES.has(resourceType)) {
|
|
5317
|
+
const sibArns = physicalId ? opts.siblingManagedPolicyAttachments?.[physicalId] : void 0;
|
|
5318
|
+
if (sibArns) subtractSiblingManagedPolicyArns(live, sibArns);
|
|
5319
|
+
if (resourceType === "AWS::IAM::User") {
|
|
5320
|
+
const sibGroups = physicalId ? opts.siblingUserGroups?.[physicalId] : void 0;
|
|
5321
|
+
if (sibGroups) subtractSiblingUserGroups(live, sibGroups);
|
|
5322
|
+
}
|
|
5323
|
+
}
|
|
5284
5324
|
if (resourceType === "AWS::S3::Bucket" && physicalId && opts.bucketNotificationManaged?.has(physicalId) && !("NotificationConfiguration" in declared)) delete live.NotificationConfiguration;
|
|
5285
5325
|
const echoSpec = CLUSTER_ECHO_CHILD[resourceType];
|
|
5286
5326
|
const echoModel = echoSpec && physicalId ? opts.clusterEchoModel?.[physicalId] : void 0;
|
|
@@ -8767,6 +8807,47 @@ const readGlueSecurityConfiguration = async ({ physicalId, declared, region }) =
|
|
|
8767
8807
|
if (Object.keys(ec).length > 0) model.EncryptionConfiguration = ec;
|
|
8768
8808
|
return model;
|
|
8769
8809
|
};
|
|
8810
|
+
const projectSageMakerVariant = (v) => {
|
|
8811
|
+
const out = {};
|
|
8812
|
+
if (str$1(v.VariantName)) out.VariantName = v.VariantName;
|
|
8813
|
+
if (str$1(v.ModelName)) out.ModelName = v.ModelName;
|
|
8814
|
+
if (typeof v.InitialInstanceCount === "number") out.InitialInstanceCount = v.InitialInstanceCount;
|
|
8815
|
+
if (str$1(v.InstanceType)) out.InstanceType = v.InstanceType;
|
|
8816
|
+
if (typeof v.InitialVariantWeight === "number") out.InitialVariantWeight = v.InitialVariantWeight;
|
|
8817
|
+
if (v.ServerlessConfig !== void 0) out.ServerlessConfig = v.ServerlessConfig;
|
|
8818
|
+
if (typeof v.VolumeSizeInGB === "number") out.VolumeSizeInGB = v.VolumeSizeInGB;
|
|
8819
|
+
if (typeof v.ModelDataDownloadTimeoutInSeconds === "number") out.ModelDataDownloadTimeoutInSeconds = v.ModelDataDownloadTimeoutInSeconds;
|
|
8820
|
+
if (typeof v.ContainerStartupHealthCheckTimeoutInSeconds === "number") out.ContainerStartupHealthCheckTimeoutInSeconds = v.ContainerStartupHealthCheckTimeoutInSeconds;
|
|
8821
|
+
if (typeof v.EnableSSMAccess === "boolean") out.EnableSSMAccess = v.EnableSSMAccess;
|
|
8822
|
+
if (v.ManagedInstanceScaling !== void 0) out.ManagedInstanceScaling = v.ManagedInstanceScaling;
|
|
8823
|
+
if (v.RoutingConfig !== void 0) out.RoutingConfig = v.RoutingConfig;
|
|
8824
|
+
if (typeof v.VariantInstanceProvisionTimeoutInSeconds === "number") out.VariantInstanceProvisionTimeoutInSeconds = v.VariantInstanceProvisionTimeoutInSeconds;
|
|
8825
|
+
if (Array.isArray(v.InstancePools) && v.InstancePools.length > 0) out.InstancePools = v.InstancePools;
|
|
8826
|
+
if (v.CapacityReservationConfig !== void 0) out.CapacityReservationConfig = v.CapacityReservationConfig;
|
|
8827
|
+
if (str$1(v.InferenceAmiVersion)) out.InferenceAmiVersion = v.InferenceAmiVersion;
|
|
8828
|
+
return out;
|
|
8829
|
+
};
|
|
8830
|
+
const readSageMakerEndpointConfig = async ({ physicalId, declared, region }) => {
|
|
8831
|
+
const name = str$1(physicalId) ?? str$1(declared.EndpointConfigName);
|
|
8832
|
+
if (!name) return void 0;
|
|
8833
|
+
const r = await new SageMakerClient({
|
|
8834
|
+
region,
|
|
8835
|
+
...READ_RETRY
|
|
8836
|
+
}).send(new DescribeEndpointConfigCommand({ EndpointConfigName: name }));
|
|
8837
|
+
if (!r.EndpointConfigName) throw new ResourceGoneError(`SageMaker EndpointConfig ${name} absent`);
|
|
8838
|
+
const model = {};
|
|
8839
|
+
if (str$1(r.EndpointConfigName)) model.EndpointConfigName = r.EndpointConfigName;
|
|
8840
|
+
if (Array.isArray(r.ProductionVariants) && r.ProductionVariants.length > 0) model.ProductionVariants = r.ProductionVariants.map(projectSageMakerVariant);
|
|
8841
|
+
if (Array.isArray(r.ShadowProductionVariants) && r.ShadowProductionVariants.length > 0) model.ShadowProductionVariants = r.ShadowProductionVariants.map(projectSageMakerVariant);
|
|
8842
|
+
if (r.DataCaptureConfig !== void 0) model.DataCaptureConfig = r.DataCaptureConfig;
|
|
8843
|
+
if (r.AsyncInferenceConfig !== void 0) model.AsyncInferenceConfig = r.AsyncInferenceConfig;
|
|
8844
|
+
if (str$1(r.KmsKeyId)) model.KmsKeyId = r.KmsKeyId;
|
|
8845
|
+
if (r.ExplainerConfig !== void 0) model.ExplainerConfig = r.ExplainerConfig;
|
|
8846
|
+
if (typeof r.EnableNetworkIsolation === "boolean") model.EnableNetworkIsolation = r.EnableNetworkIsolation;
|
|
8847
|
+
if (str$1(r.ExecutionRoleArn)) model.ExecutionRoleArn = r.ExecutionRoleArn;
|
|
8848
|
+
if (r.VpcConfig !== void 0) model.VpcConfig = r.VpcConfig;
|
|
8849
|
+
return model;
|
|
8850
|
+
};
|
|
8770
8851
|
const readMetricFilter = async ({ physicalId, declared, region }) => {
|
|
8771
8852
|
const logGroup = str$1(declared.LogGroupName);
|
|
8772
8853
|
const filterName = str$1(physicalId) ?? str$1(declared.FilterName);
|
|
@@ -9225,6 +9306,7 @@ const SDK_OVERRIDES = {
|
|
|
9225
9306
|
"AWS::Glue::Workflow": readGlueWorkflow,
|
|
9226
9307
|
"AWS::Glue::Connection": readGlueConnection,
|
|
9227
9308
|
"AWS::Glue::SecurityConfiguration": readGlueSecurityConfiguration,
|
|
9309
|
+
"AWS::SageMaker::EndpointConfig": readSageMakerEndpointConfig,
|
|
9228
9310
|
"AWS::Logs::MetricFilter": readMetricFilter,
|
|
9229
9311
|
"AWS::Scheduler::Schedule": readSchedulerSchedule
|
|
9230
9312
|
};
|
|
@@ -10299,6 +10381,62 @@ function buildBucketNotificationManaged(desired) {
|
|
|
10299
10381
|
}
|
|
10300
10382
|
return managed;
|
|
10301
10383
|
}
|
|
10384
|
+
const MANAGED_POLICY_TYPE = "AWS::IAM::ManagedPolicy";
|
|
10385
|
+
const MANAGED_POLICY_ATTACH_SIDES = [
|
|
10386
|
+
"Roles",
|
|
10387
|
+
"Users",
|
|
10388
|
+
"Groups"
|
|
10389
|
+
];
|
|
10390
|
+
function buildSiblingManagedPolicyAttachments(desired) {
|
|
10391
|
+
const byLogicalId = /* @__PURE__ */ new Map();
|
|
10392
|
+
for (const r of desired.resources) if (r.physicalId) byLogicalId.set(r.logicalId, r.physicalId);
|
|
10393
|
+
const map = {};
|
|
10394
|
+
for (const r of desired.resources) {
|
|
10395
|
+
if (r.resourceType !== MANAGED_POLICY_TYPE) continue;
|
|
10396
|
+
const decl = r.declared;
|
|
10397
|
+
if (!decl || typeof decl !== "object") continue;
|
|
10398
|
+
const d = decl;
|
|
10399
|
+
const attached = r.physicalId ?? (typeof d.ManagedPolicyName === "string" && d.ManagedPolicyName ? d.ManagedPolicyName : void 0);
|
|
10400
|
+
if (!attached) continue;
|
|
10401
|
+
for (const side of MANAGED_POLICY_ATTACH_SIDES) {
|
|
10402
|
+
const list = d[side];
|
|
10403
|
+
if (!Array.isArray(list)) continue;
|
|
10404
|
+
for (const principal of list) {
|
|
10405
|
+
const key = resolvePrincipalKey(principal, byLogicalId);
|
|
10406
|
+
if (key) (map[key] ??= []).push(attached);
|
|
10407
|
+
}
|
|
10408
|
+
}
|
|
10409
|
+
}
|
|
10410
|
+
return map;
|
|
10411
|
+
}
|
|
10412
|
+
const USER_TO_GROUP_TYPE = "AWS::IAM::UserToGroupAddition";
|
|
10413
|
+
function buildSiblingUserGroups(desired) {
|
|
10414
|
+
const byLogicalId = /* @__PURE__ */ new Map();
|
|
10415
|
+
for (const r of desired.resources) if (r.physicalId) byLogicalId.set(r.logicalId, r.physicalId);
|
|
10416
|
+
const map = {};
|
|
10417
|
+
for (const r of desired.resources) {
|
|
10418
|
+
if (r.resourceType !== USER_TO_GROUP_TYPE) continue;
|
|
10419
|
+
const decl = r.declared;
|
|
10420
|
+
if (!decl || typeof decl !== "object") continue;
|
|
10421
|
+
const d = decl;
|
|
10422
|
+
const group = resolvePrincipalKey(d.GroupName, byLogicalId);
|
|
10423
|
+
if (!group) continue;
|
|
10424
|
+
const users = d.Users;
|
|
10425
|
+
if (!Array.isArray(users)) continue;
|
|
10426
|
+
for (const user of users) {
|
|
10427
|
+
const key = resolvePrincipalKey(user, byLogicalId);
|
|
10428
|
+
if (key) (map[key] ??= []).push(group);
|
|
10429
|
+
}
|
|
10430
|
+
}
|
|
10431
|
+
return map;
|
|
10432
|
+
}
|
|
10433
|
+
function resolvePrincipalKey(ref, byLogicalId) {
|
|
10434
|
+
if (typeof ref === "string" && ref) return ref;
|
|
10435
|
+
if (ref && typeof ref === "object" && "Ref" in ref) {
|
|
10436
|
+
const logicalId = ref.Ref;
|
|
10437
|
+
if (typeof logicalId === "string") return byLogicalId.get(logicalId);
|
|
10438
|
+
}
|
|
10439
|
+
}
|
|
10302
10440
|
function buildClusterEchoModels(desired) {
|
|
10303
10441
|
const parentTypes = new Set(Object.values(CLUSTER_ECHO_CHILD).map((s) => s.parentType));
|
|
10304
10442
|
const clusterByPhys = {};
|
|
@@ -10452,6 +10590,8 @@ async function gatherFindings(stackName, region, templateOverride, recoveryTempl
|
|
|
10452
10590
|
oaiCanonicalIds,
|
|
10453
10591
|
siblingSgRules: buildSiblingSgRules(desired),
|
|
10454
10592
|
siblingEventBusPolicies: buildSiblingEventBusPolicies(desired),
|
|
10593
|
+
siblingManagedPolicyAttachments: buildSiblingManagedPolicyAttachments(desired),
|
|
10594
|
+
siblingUserGroups: buildSiblingUserGroups(desired),
|
|
10455
10595
|
bucketNotificationManaged: buildBucketNotificationManaged(desired),
|
|
10456
10596
|
clusterEchoModel: buildClusterEchoModels(desired)
|
|
10457
10597
|
};
|
|
@@ -10511,6 +10651,8 @@ async function regatherTouched(gathered, touched, region) {
|
|
|
10511
10651
|
oaiCanonicalIds,
|
|
10512
10652
|
siblingSgRules: buildSiblingSgRules(desired),
|
|
10513
10653
|
siblingEventBusPolicies: buildSiblingEventBusPolicies(desired),
|
|
10654
|
+
siblingManagedPolicyAttachments: buildSiblingManagedPolicyAttachments(desired),
|
|
10655
|
+
siblingUserGroups: buildSiblingUserGroups(desired),
|
|
10514
10656
|
bucketNotificationManaged: buildBucketNotificationManaged(desired),
|
|
10515
10657
|
clusterEchoModel: buildClusterEchoModels(desired)
|
|
10516
10658
|
};
|
|
@@ -14773,21 +14915,24 @@ async function revertStack(p) {
|
|
|
14773
14915
|
for (const item of plan.items) {
|
|
14774
14916
|
if (item.kind === "delete" || !okIds.has(item.logicalId)) continue;
|
|
14775
14917
|
for (const op of item.ops) {
|
|
14776
|
-
if (op.op !== "remove") continue;
|
|
14918
|
+
if (op.op !== "remove" && op.op !== "add") continue;
|
|
14777
14919
|
const dotted = op.path.replace(/^\//, "").replace(/\//g, ".");
|
|
14778
14920
|
const key = `${item.logicalId}\0${dotted}`;
|
|
14779
14921
|
if (!preActual.has(key)) continue;
|
|
14780
14922
|
const pre = preActual.get(key);
|
|
14781
|
-
|
|
14923
|
+
const post0 = post.find((f) => f.logicalId === item.logicalId && f.path === dotted && !isDrift(f));
|
|
14924
|
+
const persisted = post0 !== void 0 && deepEqual(post0.actual, pre);
|
|
14925
|
+
if (op.op === "remove" ? persisted : persisted && !deepEqual(post0.actual, op.value)) noOpRemovals.push({
|
|
14782
14926
|
displayId: item.displayId,
|
|
14783
|
-
path: dotted
|
|
14927
|
+
path: dotted,
|
|
14928
|
+
kind: op.op
|
|
14784
14929
|
});
|
|
14785
14930
|
}
|
|
14786
14931
|
}
|
|
14787
14932
|
const unverified = post.filter((f) => touched.has(f.logicalId) && f.tier === "skipped").length;
|
|
14788
14933
|
const unconfirmed = unverified + failedDeleteIds.size + failedUpdateIds.size;
|
|
14789
14934
|
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)`));
|
|
14935
|
+
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
14936
|
const notConverged = unconfirmed + noOpRemovals.length;
|
|
14792
14937
|
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
14938
|
const unrecordedLeft = unrecordedCount(post);
|
|
@@ -15936,6 +16081,9 @@ function nestedStackWarning(resources, stackName) {
|
|
|
15936
16081
|
function isPendingCreationSkip(f) {
|
|
15937
16082
|
return f.tier === "skipped" && f.note === "no physical id";
|
|
15938
16083
|
}
|
|
16084
|
+
function isCustomResourceSkip(f) {
|
|
16085
|
+
return f.tier === "skipped" && (f.resourceType === "AWS::CloudFormation::CustomResource" || f.resourceType.startsWith("Custom::"));
|
|
16086
|
+
}
|
|
15939
16087
|
function coverageWarning(findings, stackName, preDeploy = false) {
|
|
15940
16088
|
const skipped = findings.filter((f) => f.tier === "skipped" && !(preDeploy && isPendingCreationSkip(f)));
|
|
15941
16089
|
if (skipped.length === 0) return null;
|
|
@@ -15953,7 +16101,7 @@ function pendingCreationInfo(findings, stackName) {
|
|
|
15953
16101
|
return `info: ${stackName}: ${pending.length} resource(s) not yet deployed — will be created by the next deploy (pending creation, not a coverage gap): ${shown.join(", ")}${more}`;
|
|
15954
16102
|
}
|
|
15955
16103
|
function hasCoverageGap(findings, resources, preDeploy = false) {
|
|
15956
|
-
return findings.some((f) => f.tier === "skipped" && !(preDeploy && isPendingCreationSkip(f))) || resources.some((r) => r.resourceType === "AWS::CloudFormation::Stack");
|
|
16104
|
+
return findings.some((f) => f.tier === "skipped" && !(preDeploy && isPendingCreationSkip(f)) && !isCustomResourceSkip(f)) || resources.some((r) => r.resourceType === "AWS::CloudFormation::Stack");
|
|
15957
16105
|
}
|
|
15958
16106
|
function strictCoverageExit(strict, findings, resources, preDeploy = false) {
|
|
15959
16107
|
return strict && hasCoverageGap(findings, resources, preDeploy) ? 1 : 0;
|