cdk-real-drift 0.22.3 → 0.22.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/README.md CHANGED
@@ -141,6 +141,28 @@ Each block above is one kind of finding, and neither needed a baseline:
141
141
  At the prompt you act on each finding: **record** it (accept and watch),
142
142
  **revert** it (undo the change), or **ignore** it (stop reporting).
143
143
 
144
+ ### Every kind of drift and how it prints
145
+
146
+ Those are just the two a first run can show. The full set, confirmed or
147
+ potential:
148
+
149
+ | label | drift | judged against | appears |
150
+ | ------------------------ | ----------------------------------------------------------------------------------------- | ---------------------------- | ------------------ |
151
+ | `[CFn-Declared Drift]` | a declared property whose live value differs | the deployed template | from the first run |
152
+ | `[CFn-Undeclared Drift]` | a live-only value changed out of band (the differentiator) | your `.cdkrd` baseline | after you `record` |
153
+ | `[Added Resource]` | a recorded [out-of-band resource](#added-out-of-band-resources) changed since the record | your `.cdkrd` baseline | after you `record` |
154
+ | `[Deleted]` | a declared resource, or an added one you recorded, deleted out of band (the most blatant) | the template / your baseline | from the first run |
155
+ | `[Potential Drift]` | unconfirmed live-only values (and unrecorded added resources) | nothing yet | until you `record` |
156
+
157
+ The first four are confirmed drift, the kind that fails CI (see
158
+ [In CI](#in-ci)); `[Potential Drift]`, being unconfirmed, never does: it waits
159
+ for your record / revert / ignore decision. Record it (next section) and it
160
+ leaves the report but **stays watched**: a later out-of-band change to that
161
+ value surfaces as confirmed `[CFn-Undeclared Drift]`, and a whole recorded
162
+ resource comes back as `[Added Resource]` if changed, or `[Deleted]` if
163
+ deleted. Everything else `check` prints is informational, not drift: it is
164
+ folded into a one-line `info:` footer and detailed in [Output](#output).
165
+
144
166
  ### Recording
145
167
 
146
168
  Recording snapshots those live-only values into a git-committed `.cdkrd` baseline,
@@ -163,6 +185,10 @@ result: 1 drift(s) (undeclared=1)
163
185
  ─────────────────────────────────
164
186
  ```
165
187
 
188
+ The same applies one level up: a whole out-of-band resource you've recorded
189
+ surfaces as **`[Added Resource]`** if its live model changes after the record
190
+ (see [Added out-of-band resources](#added-out-of-band-resources)).
191
+
166
192
  `record` covers live-only state only, not a `[CFn-Declared Drift]`; the other
167
193
  verbs are in [The model](#the-model-one-verb-you-run-three-it-offers).
168
194
 
@@ -250,20 +276,14 @@ undeployed code changes don't show up as drift by default. `--pre-deploy` invert
250
276
  that, checking live state against the freshly synthesized template (see
251
277
  [`--pre-deploy`](#--pre-deploy)).
252
278
 
253
- ### The kinds of drift
254
-
255
- Named so "declared" is never ambiguous (`CFn-declared` means **in the deployed
256
- template**, not your CDK code and not your `.cdkrd` baseline):
279
+ ### Naming and mechanics
257
280
 
258
- | term | source | how it's judged |
259
- | ------------------------------ | ------------------------------------ | ----------------------------------------------------------------------- |
260
- | **CFn-declared** | in the deployed template | vs the deployed template; drift from the first run, no baseline needed |
261
- | **CFn-undeclared** (live-only) | on the resource, not in the template | vs your `.cdkrd` baseline; the key differentiator |
262
- | **Added resource** | a whole resource not in the template | reconciled against the baseline like an undeclared property (see below) |
263
- | **Deleted** | in the template, gone live | the most blatant drift; always fails `--fail` |
264
-
265
- (`CFn-undeclared` is a template axis; `recorded` / `unrecorded` is a separate
266
- baseline-file axis: whether you've snapshotted that value yet.)
281
+ The kinds themselves, and the label each prints under, are the
282
+ [table in How to use](#every-kind-of-drift-and-how-it-prints). The names are
283
+ chosen so "declared" is never ambiguous: `CFn-declared` means **in the deployed
284
+ template**, not your CDK code and not your `.cdkrd` baseline. (`CFn-undeclared`
285
+ is a template axis; `recorded` / `unrecorded` is a separate baseline-file axis:
286
+ whether you've snapshotted that value yet.)
267
287
 
268
288
  The mechanics:
269
289
 
@@ -286,11 +306,12 @@ A whole child resource that exists live but isn't in your template (e.g. an API
286
306
  Gateway `ANY` method added on `/` via the console) is the resource-level sibling
287
307
  of an undeclared property, and is reconciled the same way against your baseline:
288
308
 
289
- | state | reported as |
290
- | --------------------------- | ---------------------------------------------- |
291
- | added, **not** recorded | **Potential Drift** (no baseline, unconfirmed) |
292
- | recorded, unchanged | suppressed |
293
- | recorded, **changed** since | failing drift |
309
+ | state | reported as |
310
+ | --------------------------- | --------------------------------------------------------------- |
311
+ | added, **not** recorded | **Potential Drift** (no baseline, unconfirmed) |
312
+ | recorded, unchanged | suppressed |
313
+ | recorded, **changed** since | failing drift (`[Added Resource]`) |
314
+ | recorded, **deleted** since | failing drift (`[Deleted]`: record keeps watching; detect-only) |
294
315
 
295
316
  `cdk drift` / CFn drift detection compare only template-declared resources, so an
296
317
  out-of-band addition is invisible to them. Decide it like any finding: `record`
@@ -657,8 +678,12 @@ info:
657
678
  run with --verbose for the list
658
679
  ```
659
680
 
660
- - **Drift tiers** (`deleted` / `declared` / `undeclared`) are always listed in
661
- full and drive the `--fail` exit. They are the point.
681
+ The table of every drift kind and its section label is up in
682
+ [How to use](#every-kind-of-drift-and-how-it-prints); the mechanics:
683
+
684
+ - The four **confirmed drift tiers** (`deleted` / `declared` / `undeclared` /
685
+ `added`) are always listed in full and drive the `--fail` exit. They are the
686
+ point.
662
687
  - **`[Potential Drift: N]`**: undeclared values with no baseline yet; cdkrd
663
688
  can't tell an intentional setting from an out-of-band change, so they're listed
664
689
  in full as _potential_ (unconfirmed) drift and don't drive the `--fail` exit;
@@ -870,7 +895,9 @@ covers them. **If you never run `revert`, cdkrd needs no write permissions at al
870
895
  `iam:GetUserPolicy`, `iam:GetGroupPolicy`, `iam:GetPolicy`, `iam:GetPolicyVersion`,
871
896
  `lambda:GetPolicy`, `budgets:ViewBudget`, `ec2:DescribeAddresses`,
872
897
  `ec2:DescribeLaunchTemplateVersions`, `ec2:DescribeNetworkAcls`,
873
- `route53:ListResourceRecordSets`,
898
+ `route53:ListResourceRecordSets`, `route53:ListHostedZonesByName` (resolves a
899
+ RecordSet declared via `HostedZoneName` instead of `HostedZoneId` to its zone
900
+ id),
874
901
  `ses:DescribeReceiptRuleSet`, `ses:DescribeReceiptRule`, `ses:ListReceiptFilters`
875
902
  (the SES inbound receipt-rule family — `ReceiptRuleSet` / `ReceiptRule` /
876
903
  `ReceiptFilter` — has no Cloud Control handlers),
package/dist/cli.js CHANGED
@@ -30,7 +30,7 @@ import { DescribeEventBusCommand, EventBridgeClient, ListRulesCommand, PutPermis
30
30
  import { GetClassifierCommand, GetConnectionCommand, GetJobCommand, GetSecurityConfigurationCommand, GetTableCommand, GetTablesCommand, GetTagsCommand, GetWorkflowCommand, GlueClient, UpdateClassifierCommand, UpdateConnectionCommand, UpdateJobCommand, UpdateTableCommand, UpdateWorkflowCommand } from "@aws-sdk/client-glue";
31
31
  import { GetFunctionCommand, GetPolicyCommand, LambdaClient, ListAliasesCommand as ListAliasesCommand$1, ListEventSourceMappingsCommand, ListFunctionUrlConfigsCommand, ListVersionsByFunctionCommand } from "@aws-sdk/client-lambda";
32
32
  import { DescribeDomainConfigCommand, DescribeDomainsCommand, ListDomainNamesCommand, OpenSearchClient, UpdateDomainConfigCommand } from "@aws-sdk/client-opensearch";
33
- import { ChangeResourceRecordSetsCommand, ListResourceRecordSetsCommand, Route53Client } from "@aws-sdk/client-route-53";
33
+ import { ChangeResourceRecordSetsCommand, ListHostedZonesByNameCommand, ListResourceRecordSetsCommand, Route53Client } from "@aws-sdk/client-route-53";
34
34
  import { DeleteBucketPolicyCommand, GetBucketPolicyCommand, GetObjectCommand, PutBucketPolicyCommand, S3Client } from "@aws-sdk/client-s3";
35
35
  import { DeleteResourcePolicyCommand, GetResourcePolicyCommand, SecretsManagerClient } from "@aws-sdk/client-secrets-manager";
36
36
  import { GetTopicAttributesCommand, ListSubscriptionsByTopicCommand, SNSClient, SetTopicAttributesCommand } from "@aws-sdk/client-sns";
@@ -2528,6 +2528,7 @@ const KNOWN_DEFAULTS = {
2528
2528
  KeyUsage: "ENCRYPT_DECRYPT",
2529
2529
  Origin: "AWS_KMS"
2530
2530
  },
2531
+ "AWS::DLM::LifecyclePolicy": { RetainInterval: 7 },
2531
2532
  "AWS::IAM::Group": { Path: "/" },
2532
2533
  "AWS::IAM::User": { Path: "/" },
2533
2534
  "AWS::IAM::InstanceProfile": { Path: "/" },
@@ -3739,6 +3740,7 @@ const VALUE_INDEPENDENT_DEFAULT_TOPLEVEL_PATHS = {
3739
3740
  };
3740
3741
  const VALUE_INDEPENDENT_DEFAULT_NESTED_PATHS = {
3741
3742
  "AWS::Batch::ComputeEnvironment": new Set(["ComputeResources.DesiredvCpus"]),
3743
+ "AWS::DLM::LifecyclePolicy": new Set(["PolicyDetails.Schedules.*.CreateRule.Times"]),
3742
3744
  "AWS::AutoScaling::AutoScalingGroup": new Set(["Tags.*.ResourceId", "Tags.*.ResourceType"])
3743
3745
  };
3744
3746
  function isPhysicalIdSegment(value, physicalId) {
@@ -3918,14 +3920,14 @@ const ELB_TG_ATTRIBUTE_DEFAULTS_BY_PROTOCOL = {
3918
3920
  },
3919
3921
  UDP: {
3920
3922
  "stickiness.type": "source_ip",
3921
- "deregistration_delay.connection_termination.enabled": "false",
3923
+ "deregistration_delay.connection_termination.enabled": "true",
3922
3924
  "proxy_protocol_v2.enabled": "false",
3923
3925
  "target_health_state.unhealthy.connection_termination.enabled": "true",
3924
3926
  "target_health_state.unhealthy.draining_interval_seconds": "0"
3925
3927
  },
3926
3928
  TCP_UDP: {
3927
3929
  "stickiness.type": "source_ip",
3928
- "deregistration_delay.connection_termination.enabled": "false",
3930
+ "deregistration_delay.connection_termination.enabled": "true",
3929
3931
  "proxy_protocol_v2.enabled": "false",
3930
3932
  "target_health_state.unhealthy.connection_termination.enabled": "true",
3931
3933
  "target_health_state.unhealthy.draining_interval_seconds": "0"
@@ -11772,6 +11774,10 @@ const readDlmLifecyclePolicy = async ({ physicalId, declared, region }) => {
11772
11774
  if (declared.PolicyDetails === void 0 && DLM_DEFAULT_POLICY_SHORTHAND.some((k) => declared[k] !== void 0)) {
11773
11775
  for (const k of DLM_DEFAULT_POLICY_SHORTHAND) if (details[k] !== void 0) model[k] = details[k];
11774
11776
  } else if (Object.keys(details).length > 0) model.PolicyDetails = details;
11777
+ if (p.DefaultPolicy === true) {
11778
+ const rt = str$1(details.ResourceType);
11779
+ if (rt !== void 0) model.DefaultPolicy = rt;
11780
+ }
11775
11781
  const dlmTags = projectTagList(Object.entries(p.Tags ?? {}).map(([Key, Value]) => ({
11776
11782
  Key,
11777
11783
  Value
@@ -12279,17 +12285,27 @@ const alignTrailingDot = (live, declared) => {
12279
12285
  if (live === void 0) return void 0;
12280
12286
  return typeof declared === "string" && declared.endsWith(".") ? live.endsWith(".") ? live : `${live}.` : live.replace(/\.$/, "");
12281
12287
  };
12288
+ const canonZone = (s) => unescapeRoute53Name(s).replace(/\.$/, "").toLowerCase();
12289
+ const resolveHostedZoneIdByName = async (c, zoneName) => {
12290
+ const target = canonZone(zoneName);
12291
+ const matches = ((await c.send(new ListHostedZonesByNameCommand({ DNSName: zoneName }))).HostedZones ?? []).filter((z) => !!z.Name && canonZone(z.Name) === target);
12292
+ return (matches.length === 1 ? matches[0] : void 0)?.Id?.replace(/^\/hostedzone\//, "");
12293
+ };
12282
12294
  const readRoute53RecordSet = async ({ physicalId, declared, region }) => {
12283
12295
  const parts = physicalId.split("_");
12284
12296
  const hasIdParts = parts.length >= 3;
12285
- const hostedZoneId = str$1(declared.HostedZoneId) ?? (hasIdParts ? parts[0] : void 0);
12286
- const name = str$1(declared.Name) ?? (hasIdParts ? parts[1] : void 0);
12287
- const type = str$1(declared.Type) ?? (hasIdParts ? parts[parts.length - 1] : void 0);
12288
- if (!hostedZoneId || !name || !type) return void 0;
12289
12297
  const c = new Route53Client({
12290
12298
  region,
12291
12299
  ...READ_RETRY
12292
12300
  });
12301
+ const declaredZoneId = str$1(declared.HostedZoneId);
12302
+ let hostedZoneId = declaredZoneId ?? (hasIdParts ? parts[0] : void 0);
12303
+ const name = str$1(declared.Name) ?? (hasIdParts ? parts[1] : void 0);
12304
+ const type = str$1(declared.Type) ?? (hasIdParts ? parts[parts.length - 1] : void 0);
12305
+ const zoneName = str$1(declared.HostedZoneName);
12306
+ const byName = !declaredZoneId && !!zoneName;
12307
+ if (!hostedZoneId && zoneName) hostedZoneId = await resolveHostedZoneIdByName(c, zoneName);
12308
+ if (!hostedZoneId || !name || !type) return void 0;
12293
12309
  const canon = (s) => unescapeRoute53Name(s).replace(/\.$/, "").toLowerCase();
12294
12310
  const declSetId = str$1(declared.SetIdentifier);
12295
12311
  const isOurNameType = (x) => x.Type === type && !!x.Name && canon(x.Name) === canon(name);
@@ -12320,7 +12336,7 @@ const readRoute53RecordSet = async ({ physicalId, declared, region }) => {
12320
12336
  const model = {
12321
12337
  Name: alignTrailingDot(rec.Name === void 0 ? void 0 : unescapeRoute53Name(rec.Name), declared.Name),
12322
12338
  Type: rec.Type,
12323
- HostedZoneId: hostedZoneId
12339
+ ...byName ? { HostedZoneName: zoneName } : { HostedZoneId: hostedZoneId }
12324
12340
  };
12325
12341
  if (rec.TTL !== void 0) model.TTL = String(rec.TTL);
12326
12342
  const records = rec.ResourceRecords?.map((rr) => rr.Value).filter((v) => !!v);
@@ -16909,7 +16925,7 @@ function report(rawFindings, header, opts = {}) {
16909
16925
  const tierSection = (tier, leadingBlank) => section(byTier(tier), TIER_NAMES[tier], TIER_NOTES[tier], tierStyle(tier), leadingBlank);
16910
16926
  log(style.header(`=== check: ${header} ===`));
16911
16927
  if (unrecordedShown.length > 0) {
16912
- log(style.undeclaredTier("No baseline yet — these live-only values can't be confirmed as drift. Record them right from this `cdkrd check` prompt, or run `cdkrd record`."));
16928
+ log(style.undeclaredTier(opts.hasBaseline ? "Not in your baseline — these live-only values are on resources record couldn't fully snapshot (see readGap/skipped in info:), so cdkrd can't confirm them as drift. Record to accept them." : "No baseline yet — these live-only values can't be confirmed as drift. Record them right from this `cdkrd check` prompt, or run `cdkrd record`."));
16913
16929
  log("");
16914
16930
  }
16915
16931
  let driftSections = 0;
@@ -17851,17 +17867,18 @@ const writeDlmLifecyclePolicy = async (ctx, ops) => {
17851
17867
  ...CLIENT_TIMEOUTS
17852
17868
  });
17853
17869
  const m = await desiredModel("AWS::DLM::LifecyclePolicy", ctx, ops);
17854
- let details = m.PolicyDetails;
17855
- if (details === void 0 && DLM_DEFAULT_POLICY_SHORTHAND.some((k) => m[k] !== void 0)) {
17856
- details = { ...(await c.send(new GetLifecyclePolicyCommand({ PolicyId: id }))).Policy?.PolicyDetails ?? {} };
17857
- for (const k of DLM_DEFAULT_POLICY_SHORTHAND) if (m[k] !== void 0) details[k] = m[k];
17870
+ const details = m.PolicyDetails;
17871
+ const shorthand = {};
17872
+ if (details === void 0) {
17873
+ for (const k of DLM_DEFAULT_POLICY_SHORTHAND) if (m[k] !== void 0) shorthand[k] = m[k];
17858
17874
  }
17859
17875
  await c.send(new UpdateLifecyclePolicyCommand({
17860
17876
  PolicyId: id,
17861
17877
  ...str(m.Description) !== void 0 && { Description: str(m.Description) },
17862
17878
  ...str(m.State) !== void 0 && { State: str(m.State) },
17863
17879
  ...str(m.ExecutionRoleArn) !== void 0 && { ExecutionRoleArn: str(m.ExecutionRoleArn) },
17864
- ...details !== void 0 && { PolicyDetails: details }
17880
+ ...details !== void 0 && { PolicyDetails: details },
17881
+ ...shorthand
17865
17882
  }));
17866
17883
  };
17867
17884
  const writeMetricFilter = async (ctx, ops) => {
@@ -19337,6 +19354,7 @@ const CC_REVERTABLE_DESPITE_READ_OVERRIDE = new Set([
19337
19354
  "AWS::EC2::EIP"
19338
19355
  ]);
19339
19356
  const REVERT_SET_DEFAULT_PATHS = new Set([
19357
+ "AWS::DLM::LifecyclePolicy\0RetainInterval",
19340
19358
  "AWS::IAM::Role\0MaxSessionDuration",
19341
19359
  "AWS::IAM::Role\0Description",
19342
19360
  "AWS::Lambda::Alias\0Description",
@@ -22305,7 +22323,8 @@ async function runCheck(args) {
22305
22323
  code = jsonCode;
22306
22324
  } else code = report(reconciled, reportHeader, {
22307
22325
  verbose: a.verbose,
22308
- expandAtDefault: a.showAll
22326
+ expandAtDefault: a.showAll,
22327
+ ...a.showAll ? {} : { hasBaseline: baseline !== void 0 }
22309
22328
  });
22310
22329
  const hasUnrecorded = reconciled.some((f) => f.unrecorded === true);
22311
22330
  if (shouldOfferInteractiveResolve(a, {