cdk-real-drift 0.9.13 → 0.10.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 CHANGED
@@ -376,25 +376,26 @@ CI (with `--yes`).
376
376
  leave cells natural-width. Don't chase pixel alignment at the cost of a
377
377
  readable diff. -->
378
378
 
379
- | option | meaning |
380
- | -------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
381
- | `--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 AWS-CLI/cdk region chain — the active profile's region, then the `[default]` profile's region, then EC2 IMDS |
382
- | `--profile <p>` | AWS profile (else `$AWS_PROFILE`, else `$AWS_DEFAULT_PROFILE` — same order `aws` and `cdk` use) |
383
- | `-a, --app <cmd\|cdk.out>` | CDK app command or pre-synthesized assembly dir (or `$CDKRD_APP` / cdk.json `"app"`); stack auto-discovery + construct paths |
384
- | `-c, --context key=value` | context for synth (repeatable; cdk.json is the base layer) |
385
- | `--all` | target every stack the app defines (the default when no `<stack>` is named; overrides any positional names) |
386
- | `--json` | machine-readable output (see [JSON contract](#json-output-contract)) |
387
- | `--fail` | (check) exit 1 on drift and never prompt; for scripts/CI. Without it, check reports drift but exits 0 |
388
- | `--strict` | (check) exit 1 when coverage is incomplete. A coverage gap is always surfaced loudly; `--strict` makes it CI-failing. Orthogonal to `--fail` |
389
- | `--show-all` | (check) inventory mode: show all current undeclared state, ignoring the baseline |
390
- | `--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. `-v` means `--verbose` **inside a verb** (`check -v`); a bare `cdkrd -v` (no verb) prints the version |
391
- | `--pre-deploy` | (check) compare live vs the LOCAL synth template: the declared drift your next `cdk deploy` would silently overwrite |
392
- | `--undeclared-only` | (check) undeclared drift only: pair cdkrd with `cdk drift` for the declared side |
393
- | `--declared-only` | (check) declared drift vs the deployed template only (undeclared tier skipped; baseline untouched). Not `--pre-deploy` |
394
- | `--dry-run` | (revert) print the plan; make no changes |
395
- | `--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`). The DURATION is **inline-only** (`--wait=5m`); a separate `--wait 5m` is not read |
396
- | `--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 |
397
- | `--yes` / `-y` | skip confirmations (revert apply; record records all without the multiselect) |
379
+ | option | meaning |
380
+ | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
381
+ | `--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 AWS-CLI/cdk region chain — the active profile's region, then the `[default]` profile's region, then EC2 IMDS |
382
+ | `--profile <p>` | AWS profile (else `$AWS_PROFILE`, else `$AWS_DEFAULT_PROFILE` — same order `aws` and `cdk` use) |
383
+ | `-a, --app <cmd\|cdk.out>` | CDK app command or pre-synthesized assembly dir (or `$CDKRD_APP` / cdk.json `"app"`); stack auto-discovery + construct paths |
384
+ | `-c, --context key=value` | context for synth (repeatable; cdk.json is the base layer) |
385
+ | `--all` | target every stack the app defines (the default when no `<stack>` is named; overrides any positional names) |
386
+ | `--json` | machine-readable output (see [JSON contract](#json-output-contract)) |
387
+ | `--fail` | (check) exit 1 on drift and never prompt; for scripts/CI. Without it, check reports drift but exits 0 |
388
+ | `--strict` | (check) exit 1 when coverage is incomplete. A coverage gap is always surfaced loudly; `--strict` makes it CI-failing. Orthogonal to `--fail` |
389
+ | `--show-all` | (check) inventory mode: show all current undeclared state, ignoring the baseline |
390
+ | `--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. `-v` means `--verbose` **inside a verb** (`check -v`); a bare `cdkrd -v` (no verb) prints the version |
391
+ | `--pre-deploy` | (check) compare live vs the LOCAL synth template: the declared drift your next `cdk deploy` would silently overwrite |
392
+ | `--undeclared-only` | (check) undeclared drift only: pair cdkrd with `cdk drift` for the declared side |
393
+ | `--declared-only` | (check) declared drift vs the deployed template only (undeclared tier skipped; baseline untouched). Not `--pre-deploy` |
394
+ | `--dry-run` | (revert) print the plan; make no changes |
395
+ | `--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`). The DURATION is **inline-only** (`--wait=5m`); a separate `--wait 5m` is not read |
396
+ | `--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 |
397
+ | `--force` | (revert) proceed even when the stack is **mid-operation** (`*_IN_PROGRESS`). By default revert re-reads the stack right before the write and refuses (to avoid fighting an in-flight deploy); `--force` overrides that for a knowingly-wedged stack. The mid-operation warning still prints; `--force` does **not** skip the confirm (that is `--yes`) |
398
+ | `--yes` / `-y` | skip confirmations (revert apply; record records all without the multiselect) |
398
399
 
399
400
  Unknown options (`--apq`) and options missing their value (`--app` at the end of
400
401
  the line) are errors (exit `2`): a typo'd flag never silently becomes a stack name.
@@ -729,7 +730,10 @@ After publication this shape is a backward-compatible API.
729
730
  `revert` also **refuses to write (exit 2) when the target stack is mid-operation**
730
731
  (`*_IN_PROGRESS`): it re-reads the stack status immediately before applying, so a
731
732
  revert can never fight an in-flight `cdk deploy` / update by writing stale values
732
- onto an updating stack — wait for the stack to settle, then re-run. And
733
+ onto an updating stack — wait for the stack to settle, then re-run. For a stack
734
+ that is **wedged** in an `*_IN_PROGRESS` state that will never settle, pass
735
+ `--force` to override the refusal (the mid-operation warning still prints; `--force`
736
+ only skips this in-progress refusal — not the confirm, which is `--yes`). And
733
737
  `record` / `ignore` / `revert` now surface the same stack-status warning `check`
734
738
  prints when a stack is mid-operation or in a failed state (a `record` mid-update
735
739
  would otherwise snapshot transient values into the committed baseline).
package/dist/cli.js CHANGED
@@ -293,6 +293,7 @@ const BOOLEAN_FLAGS = new Set([
293
293
  "--declared-only",
294
294
  "--dry-run",
295
295
  "--remove-unrecorded",
296
+ "--force",
296
297
  "--verbose",
297
298
  "-v",
298
299
  "--strict",
@@ -333,7 +334,8 @@ const ALLOWED_FLAGS_BY_VERB = {
333
334
  "--verbose",
334
335
  "--remove-unrecorded",
335
336
  "--dry-run",
336
- "--wait"
337
+ "--wait",
338
+ "--force"
337
339
  ])
338
340
  };
339
341
  /**
@@ -428,6 +430,7 @@ function parseCommonArgs(args, verb) {
428
430
  undeclaredOnly: has("--undeclared-only"),
429
431
  declaredOnly: has("--declared-only"),
430
432
  removeUnrecorded: has("--remove-unrecorded"),
433
+ force: has("--force"),
431
434
  verbose: has("--verbose") || has("-v"),
432
435
  waitMs
433
436
  };
@@ -2998,9 +3001,6 @@ const EB_OPTION_DERIVED = {
2998
3001
  };
2999
3002
  const EB_OPTION_VALUE_INDEPENDENT = new Set([
3000
3003
  "aws:autoscaling:launchconfiguration|ImageId",
3001
- "aws:autoscaling:launchconfiguration|InstanceType",
3002
- "aws:autoscaling:launchconfiguration|SecurityGroups",
3003
- "aws:elb:loadbalancer|SecurityGroups",
3004
3004
  "aws:cloudformation:template:parameter|AppSource",
3005
3005
  "aws:cloudformation:template:parameter|HooksPkgUrl",
3006
3006
  "aws:cloudformation:template:parameter|InstanceTypeFamily",
@@ -3011,9 +3011,20 @@ const EB_OPTION_VALUE_INDEPENDENT = new Set([
3011
3011
  "aws:elasticbeanstalk:healthreporting:system|ConfigDocument",
3012
3012
  "aws:elasticbeanstalk:healthreporting:system|EnhancedHealthAuthEnabled"
3013
3013
  ]);
3014
- function ebOptionSettingTier(namespace, optionName, value, envType) {
3014
+ function isAllEbGeneratedGroups(value) {
3015
+ if (typeof value !== "string" || value === "") return false;
3016
+ return value.split(",").every((el) => /awseb/i.test(el.trim()));
3017
+ }
3018
+ function ebOptionSettingTier(namespace, optionName, value, envType, siblingOption) {
3015
3019
  if (value == null || value === "") return "atDefault";
3016
3020
  const key = `${String(namespace)}|${String(optionName)}`;
3021
+ if (key === "aws:autoscaling:launchconfiguration|SecurityGroups" || key === "aws:elb:loadbalancer|SecurityGroups") return isAllEbGeneratedGroups(value) ? "atDefault" : "undeclared";
3022
+ if (key === "aws:autoscaling:launchconfiguration|InstanceType") {
3023
+ const instanceTypes = siblingOption?.("aws:ec2:instances", "InstanceTypes");
3024
+ const first = typeof instanceTypes === "string" ? instanceTypes.split(",")[0]?.trim() : void 0;
3025
+ if (first !== void 0) return first === value ? "atDefault" : "undeclared";
3026
+ return "atDefault";
3027
+ }
3017
3028
  if (EB_OPTION_VALUE_INDEPENDENT.has(key)) return "atDefault";
3018
3029
  const derived = EB_OPTION_DERIVED[key];
3019
3030
  if (derived) return derived[envType] === value ? "atDefault" : "undeclared";
@@ -5059,9 +5070,11 @@ const IAM_ATTACHMENT_SUBSET = { "AWS::IAM::ManagedPolicy": new Set([
5059
5070
  "Groups"
5060
5071
  ]) };
5061
5072
  const ebOptionSettingsEntryTier = (entry, liveArray) => {
5062
- const envEntry = (Array.isArray(liveArray) ? liveArray : []).find((e) => e && e.OptionName === "EnvironmentType");
5073
+ const arr = Array.isArray(liveArray) ? liveArray : [];
5074
+ const envEntry = arr.find((e) => e && e.OptionName === "EnvironmentType");
5063
5075
  const envType = typeof envEntry?.Value === "string" ? envEntry.Value : "LoadBalanced";
5064
- return ebOptionSettingTier(entry.Namespace, entry.OptionName, entry.Value, envType);
5076
+ const siblingOption = (ns, opt) => arr.find((e) => e && e.Namespace === ns && e.OptionName === opt)?.Value;
5077
+ return ebOptionSettingTier(entry.Namespace, entry.OptionName, entry.Value, envType, siblingOption);
5065
5078
  };
5066
5079
  const ebOptionSettingsSubsetSpec = {
5067
5080
  re: /(^|\.)OptionSettings$/,
@@ -10646,9 +10659,7 @@ function isDefinitiveNotManaged(physicalId, accountId, region) {
10646
10659
  if (arnAccount !== "" && arnAccount !== accountId) return false;
10647
10660
  return true;
10648
10661
  }
10649
- async function isManagedBySiblingStack(cfn, c, cache, accountId, region) {
10650
- const physicalId = c.siblingLookupId ?? c.identifier;
10651
- if (c.siblingLookupId === void 0 && physicalId.includes("|")) return "notManaged";
10662
+ async function probeSiblingPhysicalId(cfn, c, physicalId, cache, accountId, region) {
10652
10663
  const cached = cache.get(physicalId);
10653
10664
  if (cached !== void 0) return cached;
10654
10665
  let managed = false;
@@ -10685,6 +10696,18 @@ async function isManagedBySiblingStack(cfn, c, cache, accountId, region) {
10685
10696
  cache.set(physicalId, result);
10686
10697
  return result;
10687
10698
  }
10699
+ async function isManagedBySiblingStack(cfn, c, cache, accountId, region) {
10700
+ const physicalId = c.siblingLookupId ?? c.identifier;
10701
+ if (c.siblingLookupId !== void 0 || !physicalId.includes("|")) return probeSiblingPhysicalId(cfn, c, physicalId, cache, accountId, region);
10702
+ let sawUnverified = false;
10703
+ for (const segment of physicalId.split("|")) {
10704
+ if (!segment) continue;
10705
+ const seg = await probeSiblingPhysicalId(cfn, c, segment, cache, accountId, region);
10706
+ if (seg === "managed") return "managed";
10707
+ if (seg === "unverified") sawUnverified = true;
10708
+ }
10709
+ return sawUnverified ? "unverified" : "notManaged";
10710
+ }
10688
10711
  const SG_RULE_RESOURCE_SIDE = {
10689
10712
  "AWS::EC2::SecurityGroupIngress": "ingress",
10690
10713
  "AWS::EC2::SecurityGroupEgress": "egress"
@@ -15244,7 +15267,7 @@ function augmentRevertPlan(plan, schemas, liveByLogical, declaredByLogical) {
15244
15267
  };
15245
15268
  }
15246
15269
  async function revertStack(p) {
15247
- const { stackName, region, gathered, baseline, config, dryRun, yes, removeUnrecorded, verbose, interactive, autoSelectAll, selectedFindingKeys, waitMs, waitNow, waitSleep } = p;
15270
+ const { stackName, region, gathered, baseline, config, dryRun, yes, removeUnrecorded, force, verbose, interactive, autoSelectAll, selectedFindingKeys, waitMs, waitNow, waitSleep } = p;
15248
15271
  const out = p.json ? () => {} : console.log;
15249
15272
  let worst = 0;
15250
15273
  const includeRemovals = includeUnrecordedRemovals(removeUnrecorded, interactive, yes);
@@ -15351,7 +15374,8 @@ async function revertStack(p) {
15351
15374
  }
15352
15375
  plan = augment(plan);
15353
15376
  const inProgress = await stackInProgressRefusal(stackName, region);
15354
- if (inProgress) {
15377
+ if (inProgress) if (force) console.error("\nwarning: " + inProgress + " Proceeding anyway (--force).");
15378
+ else {
15355
15379
  console.error("\n" + inProgress);
15356
15380
  return {
15357
15381
  exit: 2,
@@ -17127,6 +17151,7 @@ async function runRevert(args) {
17127
17151
  dryRun,
17128
17152
  yes: a.yes,
17129
17153
  removeUnrecorded: a.removeUnrecorded,
17154
+ force: a.force,
17130
17155
  verbose: a.verbose,
17131
17156
  interactive: a.json ? false : isInteractive(),
17132
17157
  ...a.waitMs !== void 0 && { waitMs: a.waitMs },
@@ -17253,6 +17278,12 @@ OPTIONS
17253
17278
  --remove-unrecorded (revert, and check for its inline revert) REMOVE unrecorded
17254
17279
  values + DELETE unrecorded added resources (never recorded;
17255
17280
  default: refuse — record the ones that are right)
17281
+ --force (revert) proceed even when the stack is mid-operation
17282
+ (*_IN_PROGRESS). By default revert re-reads the stack right
17283
+ before the write and REFUSES, to avoid fighting an in-flight
17284
+ deploy; --force overrides that for a knowingly-wedged stack
17285
+ (the mid-operation warning still prints; --force does NOT
17286
+ skip the confirm — that is --yes)
17256
17287
  --yes, -y skip the write confirm AND the op multiselect — apply the
17257
17288
  FULL plan (revert) / skip the selection multiselect +
17258
17289
  overwrite notice, record ALL (record) / ignore ALL shown