cdk-real-drift 0.2.79 → 0.3.1
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 +30 -2
- package/dist/cli.js +192 -46
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -343,6 +343,14 @@ CI (with `--yes`).
|
|
|
343
343
|
|
|
344
344
|
### Options
|
|
345
345
|
|
|
346
|
+
<!-- Editor note: this table is hand-aligned to a fixed column width. The
|
|
347
|
+
alignment is COSMETIC only — GitHub renders the table regardless — but a
|
|
348
|
+
cell that overflows the width silently skews the `|` columns in the source.
|
|
349
|
+
When editing a row, re-pad the `option` and `meaning` cells (and the
|
|
350
|
+
separator row) to match, or accept that alignment is inconsequential and
|
|
351
|
+
leave cells natural-width. Don't chase pixel alignment at the cost of a
|
|
352
|
+
readable diff. -->
|
|
353
|
+
|
|
346
354
|
| option | meaning |
|
|
347
355
|
| -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
348
356
|
| `--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 `--profile`'s region |
|
|
@@ -480,8 +488,11 @@ ignore:
|
|
|
480
488
|
segment, bounded by `.`, `/`, and `[` (`*.DesiredCount` matches
|
|
481
489
|
`<anyId>.DesiredCount`, not a deeper `Tbl.Config.DesiredCount`; `MyApi/*`
|
|
482
490
|
matches a direct construct-path child but not a grandchild
|
|
483
|
-
`MyApi/Resource/Method`) —
|
|
484
|
-
|
|
491
|
+
`MyApi/Resource/Method`) — but an explicit parent `path` (e.g. `MyApi/Resource`)
|
|
492
|
+
still covers its whole `/`-subtree (`MyApi/Resource/Method.Prop`) via the
|
|
493
|
+
ancestor walk, symmetric with the `.` case, so the segment bound does not
|
|
494
|
+
under-match. A leaf-pinned wildcard like `MyApi/*.Prop` still does NOT cross
|
|
495
|
+
segments (it only matches a direct child's `.Prop`). Inside a `[...]`
|
|
485
496
|
bracket key a `*` /
|
|
486
497
|
`?` is **unbounded within that bracket** (the brackets delimit the key, so a `.`
|
|
487
498
|
between them is data): `Alb.LoadBalancerAttributes[*]` and
|
|
@@ -644,6 +655,23 @@ Optional per-finding fields, present only when they apply:
|
|
|
644
655
|
the live one (so a recorded `added` resource that changed shows the delta), and
|
|
645
656
|
`unrecorded` marks a never-recorded one as potential drift.
|
|
646
657
|
|
|
658
|
+
`record` / `ignore` / `revert` also honor `--json` (for scripting / non-TTY use),
|
|
659
|
+
each emitting the same **one-array-per-invocation** shape — one element per stack,
|
|
660
|
+
all notes on stderr, `[]` on a top-level error. `--json` forces non-interactive
|
|
661
|
+
mode: a `record` / `ignore` that would need the selection prompt refuses without
|
|
662
|
+
`--yes` (`"refused": true`), and `revert` refuses the AWS write without `--yes`
|
|
663
|
+
(`"exit": 2`). Per-verb element:
|
|
664
|
+
|
|
665
|
+
- `record` → `{ "stack", "recorded": <n>, "wrote": <bool>, "baseline"?: "<path>",
|
|
666
|
+
"refused"?: true, "error"?: "<reason>" }` — `recorded` is how many undeclared
|
|
667
|
+
value(s) were written.
|
|
668
|
+
- `ignore` → `{ "stack", "added": <n>, "wrote": <bool>, "config"?:
|
|
669
|
+
".cdkrd/ignore.yaml", "refused"?: true, "error"?: "<reason>" }` — `added` is how
|
|
670
|
+
many new rules were appended.
|
|
671
|
+
- `revert` → `{ "stack", "reverted": <n>, "failed": <n>, "aborted": <bool>, "exit":
|
|
672
|
+
<n>, "error"?: "<reason>" }` — `reverted` / `failed` count resources; `exit` is
|
|
673
|
+
that stack's contribution (0 clean / 1 drift remains / 2 failure).
|
|
674
|
+
|
|
647
675
|
After publication this shape is a backward-compatible API.
|
|
648
676
|
|
|
649
677
|
## IAM permissions
|
package/dist/cli.js
CHANGED
|
@@ -457,8 +457,8 @@ function matchesGlob(pattern, name) {
|
|
|
457
457
|
* construct paths (`MyApi/Resource/Method`), so `MyApi/*` means "a direct child of
|
|
458
458
|
* MyApi" — bounding `*` at `/` keeps it from leaking to arbitrarily deep descendants
|
|
459
459
|
* (`MyApi/Resource/Method`). Deep-subtree coverage of a `/`-parent rule is still
|
|
460
|
-
* handled by the ancestor walk in `pathMatches` (which trims at
|
|
461
|
-
*
|
|
460
|
+
* handled by the ancestor walk in `pathMatches` (which trims at `.`, `[`, OR `/`, so a
|
|
461
|
+
* `/`-parent rule's whole subtree is covered — symmetric with `.`). Inside a `[...]` bracket a `/`
|
|
462
462
|
* is DATA, not a boundary — the brackets already delimit the key — so it stays literal
|
|
463
463
|
* there, exactly like `.`.
|
|
464
464
|
*
|
|
@@ -736,17 +736,18 @@ function parseIgnoreRule(entry) {
|
|
|
736
736
|
};
|
|
737
737
|
}
|
|
738
738
|
/**
|
|
739
|
-
* True when `pattern` matches `target` (= "<logicalId>.<path>"
|
|
740
|
-
* as a PARENT path: a rule "X.Policies" also ignores child paths
|
|
741
|
-
* "X.Policies.0.PolicyName" AND "X.Policies[MyPol].PolicyName" (so ignoring a
|
|
742
|
-
* structured property covers its leaves, including array / identity-keyed elements)
|
|
743
|
-
*
|
|
739
|
+
* True when `pattern` matches `target` (= "<logicalId>.<path>" / a `/`-joined construct
|
|
740
|
+
* path), either exactly or as a PARENT path: a rule "X.Policies" also ignores child paths
|
|
741
|
+
* like "X.Policies.0.PolicyName" AND "X.Policies[MyPol].PolicyName" (so ignoring a
|
|
742
|
+
* structured property covers its leaves, including array / identity-keyed elements), and a
|
|
743
|
+
* rule "MyApi/Res" covers its whole construct-path subtree "MyApi/Res/Method.Prop".
|
|
744
|
+
* Parent matching walks ancestors at each `.`, `[`, OR `/` boundary, combined with the glob.
|
|
744
745
|
*/
|
|
745
746
|
function pathMatches(pattern, target) {
|
|
746
747
|
if (matchesPathGlob(pattern, target)) return true;
|
|
747
748
|
let t = target;
|
|
748
749
|
while (true) {
|
|
749
|
-
const cut = Math.max(t.lastIndexOf("."), t.lastIndexOf("["));
|
|
750
|
+
const cut = Math.max(t.lastIndexOf("."), t.lastIndexOf("["), t.lastIndexOf("/"));
|
|
750
751
|
if (cut <= 0) break;
|
|
751
752
|
t = t.slice(0, cut);
|
|
752
753
|
if (matchesPathGlob(pattern, t)) return true;
|
|
@@ -12506,12 +12507,14 @@ async function recordStack(p) {
|
|
|
12506
12507
|
previous: existing,
|
|
12507
12508
|
physicalIdByLogical: physicalIdsByLogical(desired.resources)
|
|
12508
12509
|
});
|
|
12509
|
-
console.log(style.ok(recordOutcomeMessage(stackName, path, count, refreshedOnly, !!existing)));
|
|
12510
|
+
if (!p.json) console.log(style.ok(recordOutcomeMessage(stackName, path, count, refreshedOnly, !!existing)));
|
|
12510
12511
|
const scopeNote = recordScopeNote(stackName, findings);
|
|
12511
12512
|
if (scopeNote) console.error(scopeNote);
|
|
12512
12513
|
return {
|
|
12513
12514
|
wrote: true,
|
|
12514
|
-
refused: false
|
|
12515
|
+
refused: false,
|
|
12516
|
+
count,
|
|
12517
|
+
path
|
|
12515
12518
|
};
|
|
12516
12519
|
}
|
|
12517
12520
|
/** Header for ignore's multiselect. The key hints are rendered by `bulkMultiselect`
|
|
@@ -12551,7 +12554,7 @@ async function ignoreStack(p) {
|
|
|
12551
12554
|
const { stackName, findings, yes, interactive, accountId = "", region = "" } = p;
|
|
12552
12555
|
const ignorable = findings.filter((f) => f.tier === "declared" || f.tier === "undeclared" || f.tier === "added");
|
|
12553
12556
|
if (ignorable.length === 0) {
|
|
12554
|
-
console.log(style.clean(`${stackName}: no ignorable drift to ignore.`));
|
|
12557
|
+
if (!p.json) console.log(style.clean(`${stackName}: no ignorable drift to ignore.`));
|
|
12555
12558
|
return {
|
|
12556
12559
|
wrote: false,
|
|
12557
12560
|
refused: false,
|
|
@@ -12589,14 +12592,15 @@ async function ignoreStack(p) {
|
|
|
12589
12592
|
}
|
|
12590
12593
|
}
|
|
12591
12594
|
const { path, added, alreadyPresent } = await addIgnoreRules(chosen.map((f) => ignoreRuleFor(f, stackName, accountId, region)));
|
|
12592
|
-
if (added.length > 0) {
|
|
12595
|
+
if (!p.json) if (added.length > 0) {
|
|
12593
12596
|
const dup = alreadyPresent.length > 0 ? `, ${alreadyPresent.length} already present` : "";
|
|
12594
12597
|
console.log(style.ok(`ignore rule(s) added: ${path} (${added.length} new${dup})`));
|
|
12595
12598
|
} else console.log(style.note(`${stackName}: all ${alreadyPresent.length} selected rule(s) already present — config unchanged`));
|
|
12596
12599
|
return {
|
|
12597
12600
|
wrote: added.length > 0,
|
|
12598
12601
|
refused: false,
|
|
12599
|
-
added: added.length
|
|
12602
|
+
added: added.length,
|
|
12603
|
+
path
|
|
12600
12604
|
};
|
|
12601
12605
|
}
|
|
12602
12606
|
/**
|
|
@@ -12684,6 +12688,7 @@ function includeUnrecordedRemovals(removeUnrecorded, interactive, yes) {
|
|
|
12684
12688
|
}
|
|
12685
12689
|
async function revertStack(p) {
|
|
12686
12690
|
const { stackName, region, gathered, baseline, config, dryRun, yes, removeUnrecorded, verbose, interactive, autoSelectAll, waitMs, waitNow, waitSleep } = p;
|
|
12691
|
+
const out = p.json ? () => {} : console.log;
|
|
12687
12692
|
let worst = 0;
|
|
12688
12693
|
const includeRemovals = includeUnrecordedRemovals(removeUnrecorded, interactive, yes);
|
|
12689
12694
|
const baselineOpts = {
|
|
@@ -12708,13 +12713,13 @@ async function revertStack(p) {
|
|
|
12708
12713
|
liveByLogical: gathered.liveByLogical
|
|
12709
12714
|
});
|
|
12710
12715
|
if (plan.items.length === 0 && plan.notRevertable.length === 0) {
|
|
12711
|
-
|
|
12716
|
+
out(style.clean(`${stackName} (${region}): no drift to revert.`));
|
|
12712
12717
|
return {
|
|
12713
12718
|
exit: 0,
|
|
12714
12719
|
aborted: false
|
|
12715
12720
|
};
|
|
12716
12721
|
}
|
|
12717
|
-
printPlan(stackName, region, plan, {
|
|
12722
|
+
if (!p.json) printPlan(stackName, region, plan, {
|
|
12718
12723
|
verbose,
|
|
12719
12724
|
unrecordedGuidance: !includeRemovals && drifted.some((f) => f.unrecorded === true)
|
|
12720
12725
|
});
|
|
@@ -12722,15 +12727,14 @@ async function revertStack(p) {
|
|
|
12722
12727
|
const dc = driftCount(drifted);
|
|
12723
12728
|
const uc = unrecordedCount(drifted);
|
|
12724
12729
|
const parts = [...dc > 0 ? [`${dc} drift(s)`] : [], ...uc > 0 ? [`${uc} unrecorded value(s)`] : []];
|
|
12725
|
-
|
|
12730
|
+
out("\n" + style.drift(`nothing revertable — ${parts.join(" + ")} remain.`));
|
|
12726
12731
|
return {
|
|
12727
12732
|
exit: 1,
|
|
12728
12733
|
aborted: false
|
|
12729
12734
|
};
|
|
12730
12735
|
}
|
|
12731
12736
|
if (dryRun) {
|
|
12732
|
-
|
|
12733
|
-
console.log(`\n(dry-run) would apply ${opCount} op(s) to ${plan.items.length} resource(s). No changes made.`);
|
|
12737
|
+
out(`\n(dry-run) would apply ${plan.items.reduce((n, i) => n + i.ops.length, 0)} op(s) to ${plan.items.length} resource(s). No changes made.`);
|
|
12734
12738
|
return {
|
|
12735
12739
|
exit: 0,
|
|
12736
12740
|
aborted: false
|
|
@@ -12747,7 +12751,7 @@ async function revertStack(p) {
|
|
|
12747
12751
|
if (!autoSelectAll) {
|
|
12748
12752
|
const picked = await bulkMultiselect(revertSelectMessage(stackName), revertSelectOptions(plan));
|
|
12749
12753
|
if (picked === void 0) {
|
|
12750
|
-
|
|
12754
|
+
out(style.note("aborted."));
|
|
12751
12755
|
return {
|
|
12752
12756
|
exit: 0,
|
|
12753
12757
|
aborted: true
|
|
@@ -12755,7 +12759,7 @@ async function revertStack(p) {
|
|
|
12755
12759
|
}
|
|
12756
12760
|
plan = filterRevertPlan(plan, new Set(picked));
|
|
12757
12761
|
if (plan.items.length === 0) {
|
|
12758
|
-
|
|
12762
|
+
out(style.note("nothing selected — aborted."));
|
|
12759
12763
|
return {
|
|
12760
12764
|
exit: 0,
|
|
12761
12765
|
aborted: true
|
|
@@ -12764,7 +12768,7 @@ async function revertStack(p) {
|
|
|
12764
12768
|
}
|
|
12765
12769
|
const ok = await confirm({ message: revertConfirmMessage(stackName, plan.items.reduce((n, i) => n + i.ops.length, 0), plan.notRevertable.length) });
|
|
12766
12770
|
if (isCancel(ok) || !ok) {
|
|
12767
|
-
|
|
12771
|
+
out(style.note("aborted."));
|
|
12768
12772
|
return {
|
|
12769
12773
|
exit: 0,
|
|
12770
12774
|
aborted: true
|
|
@@ -12784,7 +12788,7 @@ async function revertStack(p) {
|
|
|
12784
12788
|
onRetry: ({ attempt, delayMs, hint }) => {
|
|
12785
12789
|
const reason = (hint ?? "transient error").split(" — ")[0];
|
|
12786
12790
|
const secs = Math.max(1, Math.round(delayMs / 1e3));
|
|
12787
|
-
|
|
12791
|
+
out(style.note(` ↻ ${displayId}: ${reason} — retry ${attempt} (next in ${secs}s)…`));
|
|
12788
12792
|
}
|
|
12789
12793
|
});
|
|
12790
12794
|
const deleteItems = plan.items.filter((i) => i.kind === "delete");
|
|
@@ -12852,16 +12856,19 @@ async function revertStack(p) {
|
|
|
12852
12856
|
});
|
|
12853
12857
|
if (!r.ok) worst = Math.max(worst, 2);
|
|
12854
12858
|
}
|
|
12855
|
-
|
|
12859
|
+
const summarized = summarizeRevertResults(applied);
|
|
12860
|
+
const revertedCount = summarized.filter((s) => s.ok).length;
|
|
12861
|
+
const failedCount = summarized.filter((s) => !s.ok).length;
|
|
12862
|
+
for (const s of summarized) if (s.ok) out(style.ok(` reverted: ${s.displayId}`));
|
|
12856
12863
|
else {
|
|
12857
|
-
|
|
12864
|
+
out(style.fail(` FAILED: ${s.displayId} — ${s.error}`));
|
|
12858
12865
|
if (s.hint) {
|
|
12859
12866
|
const suffix = waitMs === void 0 ? " (or re-run with --wait to block until it settles)" : "";
|
|
12860
|
-
|
|
12867
|
+
out(style.note(` ↳ ${s.hint}${suffix}`));
|
|
12861
12868
|
}
|
|
12862
12869
|
}
|
|
12863
12870
|
const touched = new Set(plan.items.map((i) => i.logicalId));
|
|
12864
|
-
|
|
12871
|
+
out("\n" + style.note(`verifying convergence (re-reading ${touched.size} resource(s))...`));
|
|
12865
12872
|
const reconcile = (findings) => applyIgnores(applyBaseline(findings, baseline, baselineOpts), {
|
|
12866
12873
|
stackName,
|
|
12867
12874
|
accountId: gathered.desired.accountId,
|
|
@@ -12896,17 +12903,19 @@ async function revertStack(p) {
|
|
|
12896
12903
|
const unverified = post.filter((f) => touched.has(f.logicalId) && f.tier === "skipped").length;
|
|
12897
12904
|
const unconfirmed = unverified + failedDeleteIds.size + failedUpdateIds.size;
|
|
12898
12905
|
const converged = remaining === 0 && unconfirmed === 0 && noOpRemovals.length === 0;
|
|
12899
|
-
for (const n of noOpRemovals)
|
|
12906
|
+
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)`));
|
|
12900
12907
|
const notConverged = unconfirmed + noOpRemovals.length;
|
|
12901
|
-
|
|
12908
|
+
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).`));
|
|
12902
12909
|
const unrecordedLeft = unrecordedCount(post);
|
|
12903
|
-
if (unrecordedLeft > 0)
|
|
12904
|
-
if (unverified > 0)
|
|
12905
|
-
for (const line of formatSurvivingDrift(remainingDrift, stackName))
|
|
12910
|
+
if (unrecordedLeft > 0) out(style.note(` (${unrecordedLeft} unrecorded value(s) still await a baseline — run cdkrd record)`));
|
|
12911
|
+
if (unverified > 0) out(style.note(` (${unverified} resource(s) could not be re-read to verify — re-run cdkrd check to confirm)`));
|
|
12912
|
+
for (const line of formatSurvivingDrift(remainingDrift, stackName)) out(line);
|
|
12906
12913
|
if (remaining > 0 || unverified > 0 || noOpRemovals.length > 0) worst = Math.max(worst, 1);
|
|
12907
12914
|
return {
|
|
12908
12915
|
exit: worst,
|
|
12909
|
-
aborted: false
|
|
12916
|
+
aborted: false,
|
|
12917
|
+
reverted: revertedCount,
|
|
12918
|
+
failed: failedCount
|
|
12910
12919
|
};
|
|
12911
12920
|
}
|
|
12912
12921
|
/**
|
|
@@ -12931,6 +12940,15 @@ function availableActions(findings, baseline, schemas, removeUnrecorded) {
|
|
|
12931
12940
|
};
|
|
12932
12941
|
}
|
|
12933
12942
|
|
|
12943
|
+
//#endregion
|
|
12944
|
+
//#region src/commands/verb-json.ts
|
|
12945
|
+
function stackLabel(stackName, region) {
|
|
12946
|
+
return region ? `${stackName} (${region})` : stackName;
|
|
12947
|
+
}
|
|
12948
|
+
function emitJsonArray(reports) {
|
|
12949
|
+
console.log(JSON.stringify(reports, null, 2));
|
|
12950
|
+
}
|
|
12951
|
+
|
|
12934
12952
|
//#endregion
|
|
12935
12953
|
//#region src/commands/record.ts
|
|
12936
12954
|
async function runRecord(args) {
|
|
@@ -12948,18 +12966,28 @@ async function runRecord(args) {
|
|
|
12948
12966
|
stacks = await resolveStacks(a);
|
|
12949
12967
|
} catch (e) {
|
|
12950
12968
|
console.error(`error: ${e.message}`);
|
|
12969
|
+
if (a.json) emitJsonArray([]);
|
|
12951
12970
|
return 2;
|
|
12952
12971
|
}
|
|
12953
12972
|
if (stacks.length === 0) {
|
|
12954
12973
|
console.error("note: the CDK app defines no stacks — nothing to record");
|
|
12974
|
+
if (a.json) emitJsonArray([]);
|
|
12955
12975
|
return 0;
|
|
12956
12976
|
}
|
|
12977
|
+
const jsonReports = [];
|
|
12957
12978
|
let worst = 0;
|
|
12958
12979
|
let wroteAny = false;
|
|
12959
12980
|
const showProgress = !a.json && isInteractive();
|
|
12960
12981
|
for (const [idx, { stackName, region, template }] of stacks.entries()) {
|
|
12961
12982
|
if (!region) {
|
|
12962
|
-
|
|
12983
|
+
const msg = "no region — set env on the stack, pass --region, or set a region for the AWS profile";
|
|
12984
|
+
console.error(`error: ${stackName}: ${msg}`);
|
|
12985
|
+
if (a.json) jsonReports.push({
|
|
12986
|
+
stack: stackName,
|
|
12987
|
+
recorded: 0,
|
|
12988
|
+
wrote: false,
|
|
12989
|
+
error: msg
|
|
12990
|
+
});
|
|
12963
12991
|
worst = Math.max(worst, 2);
|
|
12964
12992
|
continue;
|
|
12965
12993
|
}
|
|
@@ -12975,24 +13003,55 @@ async function runRecord(args) {
|
|
|
12975
13003
|
region
|
|
12976
13004
|
}, config),
|
|
12977
13005
|
yes: a.yes,
|
|
12978
|
-
interactive: isInteractive(),
|
|
12979
|
-
expandNested: a.verbose
|
|
13006
|
+
interactive: a.json ? false : isInteractive(),
|
|
13007
|
+
expandNested: a.verbose,
|
|
13008
|
+
json: a.json
|
|
12980
13009
|
});
|
|
12981
13010
|
if (result.refused) worst = Math.max(worst, 2);
|
|
12982
13011
|
if (result.wrote) wroteAny = true;
|
|
13012
|
+
if (a.json) jsonReports.push({
|
|
13013
|
+
stack: stackLabel(stackName, region),
|
|
13014
|
+
recorded: result.count ?? 0,
|
|
13015
|
+
wrote: result.wrote,
|
|
13016
|
+
...result.refused && { refused: true },
|
|
13017
|
+
...result.path !== void 0 && { baseline: result.path }
|
|
13018
|
+
});
|
|
12983
13019
|
} catch (e) {
|
|
12984
13020
|
if (isStackNotDeployed(e)) {
|
|
12985
13021
|
console.error(`note: ${stackName}: not deployed yet — nothing to record`);
|
|
13022
|
+
if (a.json) jsonReports.push({
|
|
13023
|
+
stack: stackLabel(stackName, region),
|
|
13024
|
+
recorded: 0,
|
|
13025
|
+
wrote: false,
|
|
13026
|
+
error: "not deployed yet — nothing to record"
|
|
13027
|
+
});
|
|
12986
13028
|
continue;
|
|
12987
13029
|
}
|
|
12988
13030
|
if (e instanceof StackNotCheckableError) {
|
|
12989
13031
|
console.error(`note: ${stackName}: ${e.message} — nothing to record`);
|
|
13032
|
+
if (a.json) jsonReports.push({
|
|
13033
|
+
stack: stackLabel(stackName, region),
|
|
13034
|
+
recorded: 0,
|
|
13035
|
+
wrote: false,
|
|
13036
|
+
error: `${e.message} — nothing to record`
|
|
13037
|
+
});
|
|
12990
13038
|
continue;
|
|
12991
13039
|
}
|
|
12992
|
-
|
|
13040
|
+
const msg = e.message;
|
|
13041
|
+
console.error(`error: ${stackName}: ${msg}`);
|
|
13042
|
+
if (a.json) jsonReports.push({
|
|
13043
|
+
stack: stackLabel(stackName, region),
|
|
13044
|
+
recorded: 0,
|
|
13045
|
+
wrote: false,
|
|
13046
|
+
error: msg
|
|
13047
|
+
});
|
|
12993
13048
|
worst = Math.max(worst, 2);
|
|
12994
13049
|
}
|
|
12995
13050
|
}
|
|
13051
|
+
if (a.json) {
|
|
13052
|
+
emitJsonArray(jsonReports);
|
|
13053
|
+
return worst;
|
|
13054
|
+
}
|
|
12996
13055
|
if (worst === 0 && wroteAny) console.log("commit the baseline file(s) so drift is detected against them going forward.");
|
|
12997
13056
|
return worst;
|
|
12998
13057
|
}
|
|
@@ -13014,18 +13073,28 @@ async function runIgnore(args) {
|
|
|
13014
13073
|
stacks = await resolveStacks(a);
|
|
13015
13074
|
} catch (e) {
|
|
13016
13075
|
console.error(`error: ${e.message}`);
|
|
13076
|
+
if (a.json) emitJsonArray([]);
|
|
13017
13077
|
return 2;
|
|
13018
13078
|
}
|
|
13019
13079
|
if (stacks.length === 0) {
|
|
13020
13080
|
console.error("note: the CDK app defines no stacks — nothing to ignore");
|
|
13081
|
+
if (a.json) emitJsonArray([]);
|
|
13021
13082
|
return 0;
|
|
13022
13083
|
}
|
|
13084
|
+
const jsonReports = [];
|
|
13023
13085
|
let worst = 0;
|
|
13024
13086
|
let wroteAny = false;
|
|
13025
13087
|
const showProgress = !a.json && isInteractive();
|
|
13026
13088
|
for (const [idx, { stackName, region, template }] of stacks.entries()) {
|
|
13027
13089
|
if (!region) {
|
|
13028
|
-
|
|
13090
|
+
const msg = "no region — set env on the stack, pass --region, or set a region for the AWS profile";
|
|
13091
|
+
console.error(`error: ${stackName}: ${msg}`);
|
|
13092
|
+
if (a.json) jsonReports.push({
|
|
13093
|
+
stack: stackName,
|
|
13094
|
+
added: 0,
|
|
13095
|
+
wrote: false,
|
|
13096
|
+
error: msg
|
|
13097
|
+
});
|
|
13029
13098
|
worst = Math.max(worst, 2);
|
|
13030
13099
|
continue;
|
|
13031
13100
|
}
|
|
@@ -13046,25 +13115,56 @@ async function runIgnore(args) {
|
|
|
13046
13115
|
region
|
|
13047
13116
|
}, config),
|
|
13048
13117
|
yes: a.yes,
|
|
13049
|
-
interactive: isInteractive(),
|
|
13118
|
+
interactive: a.json ? false : isInteractive(),
|
|
13050
13119
|
accountId: desired.accountId,
|
|
13051
|
-
region
|
|
13120
|
+
region,
|
|
13121
|
+
json: a.json
|
|
13052
13122
|
});
|
|
13053
13123
|
if (result.wrote) wroteAny = true;
|
|
13054
13124
|
if (result.refused) worst = Math.max(worst, 2);
|
|
13125
|
+
if (a.json) jsonReports.push({
|
|
13126
|
+
stack: stackLabel(stackName, region),
|
|
13127
|
+
added: result.added,
|
|
13128
|
+
wrote: result.wrote,
|
|
13129
|
+
...result.refused && { refused: true },
|
|
13130
|
+
...result.path !== void 0 && { config: result.path }
|
|
13131
|
+
});
|
|
13055
13132
|
} catch (e) {
|
|
13056
13133
|
if (isStackNotDeployed(e)) {
|
|
13057
13134
|
console.error(`note: ${stackName}: not deployed yet — nothing to ignore`);
|
|
13135
|
+
if (a.json) jsonReports.push({
|
|
13136
|
+
stack: stackLabel(stackName, region),
|
|
13137
|
+
added: 0,
|
|
13138
|
+
wrote: false,
|
|
13139
|
+
error: "not deployed yet — nothing to ignore"
|
|
13140
|
+
});
|
|
13058
13141
|
continue;
|
|
13059
13142
|
}
|
|
13060
13143
|
if (e instanceof StackNotCheckableError) {
|
|
13061
13144
|
console.error(`note: ${stackName}: ${e.message} — nothing to ignore`);
|
|
13145
|
+
if (a.json) jsonReports.push({
|
|
13146
|
+
stack: stackLabel(stackName, region),
|
|
13147
|
+
added: 0,
|
|
13148
|
+
wrote: false,
|
|
13149
|
+
error: `${e.message} — nothing to ignore`
|
|
13150
|
+
});
|
|
13062
13151
|
continue;
|
|
13063
13152
|
}
|
|
13064
|
-
|
|
13153
|
+
const msg = e.message;
|
|
13154
|
+
console.error(`error: ${stackName}: ${msg}`);
|
|
13155
|
+
if (a.json) jsonReports.push({
|
|
13156
|
+
stack: stackLabel(stackName, region),
|
|
13157
|
+
added: 0,
|
|
13158
|
+
wrote: false,
|
|
13159
|
+
error: msg
|
|
13160
|
+
});
|
|
13065
13161
|
worst = Math.max(worst, 2);
|
|
13066
13162
|
}
|
|
13067
13163
|
}
|
|
13164
|
+
if (a.json) {
|
|
13165
|
+
emitJsonArray(jsonReports);
|
|
13166
|
+
return worst;
|
|
13167
|
+
}
|
|
13068
13168
|
if (worst === 0 && wroteAny) console.log("commit .cdkrd/ignore.yaml so the ignore rules apply for everyone going forward.");
|
|
13069
13169
|
return worst;
|
|
13070
13170
|
}
|
|
@@ -14181,17 +14281,29 @@ async function runRevert(args) {
|
|
|
14181
14281
|
stacks = await resolveStacks(a);
|
|
14182
14282
|
} catch (e) {
|
|
14183
14283
|
console.error(`error: ${e.message}`);
|
|
14284
|
+
if (a.json) emitJsonArray([]);
|
|
14184
14285
|
return 2;
|
|
14185
14286
|
}
|
|
14186
14287
|
if (stacks.length === 0) {
|
|
14187
14288
|
console.error("note: the CDK app defines no stacks — nothing to revert");
|
|
14289
|
+
if (a.json) emitJsonArray([]);
|
|
14188
14290
|
return 0;
|
|
14189
14291
|
}
|
|
14292
|
+
const jsonReports = [];
|
|
14190
14293
|
let worst = 0;
|
|
14191
14294
|
const showProgress = !a.json && isInteractive();
|
|
14192
14295
|
for (const [idx, { stackName, region, template }] of stacks.entries()) {
|
|
14193
14296
|
if (!region) {
|
|
14194
|
-
|
|
14297
|
+
const msg = "no region — set env on the stack, pass --region, or set a region for the AWS profile";
|
|
14298
|
+
console.error(`error: ${stackName}: ${msg}`);
|
|
14299
|
+
if (a.json) jsonReports.push({
|
|
14300
|
+
stack: stackName,
|
|
14301
|
+
reverted: 0,
|
|
14302
|
+
failed: 0,
|
|
14303
|
+
aborted: false,
|
|
14304
|
+
exit: 2,
|
|
14305
|
+
error: msg
|
|
14306
|
+
});
|
|
14195
14307
|
worst = Math.max(worst, 2);
|
|
14196
14308
|
continue;
|
|
14197
14309
|
}
|
|
@@ -14199,7 +14311,7 @@ async function runRevert(args) {
|
|
|
14199
14311
|
const gathered = await gatherWithProgress(showProgress, progressLabel(idx, stacks.length, stackName, region), () => gatherFindings(stackName, region, void 0, template));
|
|
14200
14312
|
const baseline = await loadBaseline(stackName, gathered.desired.accountId, region);
|
|
14201
14313
|
if (baseline) checkBaselineAccount(baseline, gathered.desired.accountId, stackName);
|
|
14202
|
-
const
|
|
14314
|
+
const outcome = await revertStack({
|
|
14203
14315
|
stackName,
|
|
14204
14316
|
region,
|
|
14205
14317
|
gathered,
|
|
@@ -14209,23 +14321,57 @@ async function runRevert(args) {
|
|
|
14209
14321
|
yes: a.yes,
|
|
14210
14322
|
removeUnrecorded: a.removeUnrecorded,
|
|
14211
14323
|
verbose: a.verbose,
|
|
14212
|
-
interactive: isInteractive(),
|
|
14213
|
-
...a.waitMs !== void 0 && { waitMs: a.waitMs }
|
|
14324
|
+
interactive: a.json ? false : isInteractive(),
|
|
14325
|
+
...a.waitMs !== void 0 && { waitMs: a.waitMs },
|
|
14326
|
+
json: a.json
|
|
14327
|
+
});
|
|
14328
|
+
worst = Math.max(worst, outcome.exit);
|
|
14329
|
+
if (a.json) jsonReports.push({
|
|
14330
|
+
stack: stackLabel(stackName, region),
|
|
14331
|
+
reverted: outcome.reverted ?? 0,
|
|
14332
|
+
failed: outcome.failed ?? 0,
|
|
14333
|
+
aborted: outcome.aborted,
|
|
14334
|
+
exit: outcome.exit
|
|
14214
14335
|
});
|
|
14215
|
-
worst = Math.max(worst, exit);
|
|
14216
14336
|
} catch (e) {
|
|
14217
14337
|
if (isStackNotDeployed(e)) {
|
|
14218
14338
|
console.error(`note: ${stackName}: not deployed — skipped`);
|
|
14339
|
+
if (a.json) jsonReports.push({
|
|
14340
|
+
stack: stackLabel(stackName, region),
|
|
14341
|
+
reverted: 0,
|
|
14342
|
+
failed: 0,
|
|
14343
|
+
aborted: false,
|
|
14344
|
+
exit: 0,
|
|
14345
|
+
error: "not deployed — skipped"
|
|
14346
|
+
});
|
|
14219
14347
|
continue;
|
|
14220
14348
|
}
|
|
14221
14349
|
if (e instanceof StackNotCheckableError) {
|
|
14222
14350
|
console.error(`note: ${stackName}: ${e.message} — skipped`);
|
|
14351
|
+
if (a.json) jsonReports.push({
|
|
14352
|
+
stack: stackLabel(stackName, region),
|
|
14353
|
+
reverted: 0,
|
|
14354
|
+
failed: 0,
|
|
14355
|
+
aborted: false,
|
|
14356
|
+
exit: 0,
|
|
14357
|
+
error: `${e.message} — skipped`
|
|
14358
|
+
});
|
|
14223
14359
|
continue;
|
|
14224
14360
|
}
|
|
14225
|
-
|
|
14361
|
+
const msg = e.message;
|
|
14362
|
+
console.error(`error: ${stackName}: ${msg}`);
|
|
14363
|
+
if (a.json) jsonReports.push({
|
|
14364
|
+
stack: stackLabel(stackName, region),
|
|
14365
|
+
reverted: 0,
|
|
14366
|
+
failed: 0,
|
|
14367
|
+
aborted: false,
|
|
14368
|
+
exit: 2,
|
|
14369
|
+
error: msg
|
|
14370
|
+
});
|
|
14226
14371
|
worst = Math.max(worst, 2);
|
|
14227
14372
|
}
|
|
14228
14373
|
}
|
|
14374
|
+
if (a.json) emitJsonArray(jsonReports);
|
|
14229
14375
|
return worst;
|
|
14230
14376
|
}
|
|
14231
14377
|
|