cdk-real-drift 0.2.79 → 0.3.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 +17 -0
- package/dist/cli.js +183 -38
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -644,6 +644,23 @@ Optional per-finding fields, present only when they apply:
|
|
|
644
644
|
the live one (so a recorded `added` resource that changed shows the delta), and
|
|
645
645
|
`unrecorded` marks a never-recorded one as potential drift.
|
|
646
646
|
|
|
647
|
+
`record` / `ignore` / `revert` also honor `--json` (for scripting / non-TTY use),
|
|
648
|
+
each emitting the same **one-array-per-invocation** shape — one element per stack,
|
|
649
|
+
all notes on stderr, `[]` on a top-level error. `--json` forces non-interactive
|
|
650
|
+
mode: a `record` / `ignore` that would need the selection prompt refuses without
|
|
651
|
+
`--yes` (`"refused": true`), and `revert` refuses the AWS write without `--yes`
|
|
652
|
+
(`"exit": 2`). Per-verb element:
|
|
653
|
+
|
|
654
|
+
- `record` → `{ "stack", "recorded": <n>, "wrote": <bool>, "baseline"?: "<path>",
|
|
655
|
+
"refused"?: true, "error"?: "<reason>" }` — `recorded` is how many undeclared
|
|
656
|
+
value(s) were written.
|
|
657
|
+
- `ignore` → `{ "stack", "added": <n>, "wrote": <bool>, "config"?:
|
|
658
|
+
".cdkrd/ignore.yaml", "refused"?: true, "error"?: "<reason>" }` — `added` is how
|
|
659
|
+
many new rules were appended.
|
|
660
|
+
- `revert` → `{ "stack", "reverted": <n>, "failed": <n>, "aborted": <bool>, "exit":
|
|
661
|
+
<n>, "error"?: "<reason>" }` — `reverted` / `failed` count resources; `exit` is
|
|
662
|
+
that stack's contribution (0 clean / 1 drift remains / 2 failure).
|
|
663
|
+
|
|
647
664
|
After publication this shape is a backward-compatible API.
|
|
648
665
|
|
|
649
666
|
## IAM permissions
|
package/dist/cli.js
CHANGED
|
@@ -12506,12 +12506,14 @@ async function recordStack(p) {
|
|
|
12506
12506
|
previous: existing,
|
|
12507
12507
|
physicalIdByLogical: physicalIdsByLogical(desired.resources)
|
|
12508
12508
|
});
|
|
12509
|
-
console.log(style.ok(recordOutcomeMessage(stackName, path, count, refreshedOnly, !!existing)));
|
|
12509
|
+
if (!p.json) console.log(style.ok(recordOutcomeMessage(stackName, path, count, refreshedOnly, !!existing)));
|
|
12510
12510
|
const scopeNote = recordScopeNote(stackName, findings);
|
|
12511
12511
|
if (scopeNote) console.error(scopeNote);
|
|
12512
12512
|
return {
|
|
12513
12513
|
wrote: true,
|
|
12514
|
-
refused: false
|
|
12514
|
+
refused: false,
|
|
12515
|
+
count,
|
|
12516
|
+
path
|
|
12515
12517
|
};
|
|
12516
12518
|
}
|
|
12517
12519
|
/** Header for ignore's multiselect. The key hints are rendered by `bulkMultiselect`
|
|
@@ -12551,7 +12553,7 @@ async function ignoreStack(p) {
|
|
|
12551
12553
|
const { stackName, findings, yes, interactive, accountId = "", region = "" } = p;
|
|
12552
12554
|
const ignorable = findings.filter((f) => f.tier === "declared" || f.tier === "undeclared" || f.tier === "added");
|
|
12553
12555
|
if (ignorable.length === 0) {
|
|
12554
|
-
console.log(style.clean(`${stackName}: no ignorable drift to ignore.`));
|
|
12556
|
+
if (!p.json) console.log(style.clean(`${stackName}: no ignorable drift to ignore.`));
|
|
12555
12557
|
return {
|
|
12556
12558
|
wrote: false,
|
|
12557
12559
|
refused: false,
|
|
@@ -12589,14 +12591,15 @@ async function ignoreStack(p) {
|
|
|
12589
12591
|
}
|
|
12590
12592
|
}
|
|
12591
12593
|
const { path, added, alreadyPresent } = await addIgnoreRules(chosen.map((f) => ignoreRuleFor(f, stackName, accountId, region)));
|
|
12592
|
-
if (added.length > 0) {
|
|
12594
|
+
if (!p.json) if (added.length > 0) {
|
|
12593
12595
|
const dup = alreadyPresent.length > 0 ? `, ${alreadyPresent.length} already present` : "";
|
|
12594
12596
|
console.log(style.ok(`ignore rule(s) added: ${path} (${added.length} new${dup})`));
|
|
12595
12597
|
} else console.log(style.note(`${stackName}: all ${alreadyPresent.length} selected rule(s) already present — config unchanged`));
|
|
12596
12598
|
return {
|
|
12597
12599
|
wrote: added.length > 0,
|
|
12598
12600
|
refused: false,
|
|
12599
|
-
added: added.length
|
|
12601
|
+
added: added.length,
|
|
12602
|
+
path
|
|
12600
12603
|
};
|
|
12601
12604
|
}
|
|
12602
12605
|
/**
|
|
@@ -12684,6 +12687,7 @@ function includeUnrecordedRemovals(removeUnrecorded, interactive, yes) {
|
|
|
12684
12687
|
}
|
|
12685
12688
|
async function revertStack(p) {
|
|
12686
12689
|
const { stackName, region, gathered, baseline, config, dryRun, yes, removeUnrecorded, verbose, interactive, autoSelectAll, waitMs, waitNow, waitSleep } = p;
|
|
12690
|
+
const out = p.json ? () => {} : console.log;
|
|
12687
12691
|
let worst = 0;
|
|
12688
12692
|
const includeRemovals = includeUnrecordedRemovals(removeUnrecorded, interactive, yes);
|
|
12689
12693
|
const baselineOpts = {
|
|
@@ -12708,13 +12712,13 @@ async function revertStack(p) {
|
|
|
12708
12712
|
liveByLogical: gathered.liveByLogical
|
|
12709
12713
|
});
|
|
12710
12714
|
if (plan.items.length === 0 && plan.notRevertable.length === 0) {
|
|
12711
|
-
|
|
12715
|
+
out(style.clean(`${stackName} (${region}): no drift to revert.`));
|
|
12712
12716
|
return {
|
|
12713
12717
|
exit: 0,
|
|
12714
12718
|
aborted: false
|
|
12715
12719
|
};
|
|
12716
12720
|
}
|
|
12717
|
-
printPlan(stackName, region, plan, {
|
|
12721
|
+
if (!p.json) printPlan(stackName, region, plan, {
|
|
12718
12722
|
verbose,
|
|
12719
12723
|
unrecordedGuidance: !includeRemovals && drifted.some((f) => f.unrecorded === true)
|
|
12720
12724
|
});
|
|
@@ -12722,15 +12726,14 @@ async function revertStack(p) {
|
|
|
12722
12726
|
const dc = driftCount(drifted);
|
|
12723
12727
|
const uc = unrecordedCount(drifted);
|
|
12724
12728
|
const parts = [...dc > 0 ? [`${dc} drift(s)`] : [], ...uc > 0 ? [`${uc} unrecorded value(s)`] : []];
|
|
12725
|
-
|
|
12729
|
+
out("\n" + style.drift(`nothing revertable — ${parts.join(" + ")} remain.`));
|
|
12726
12730
|
return {
|
|
12727
12731
|
exit: 1,
|
|
12728
12732
|
aborted: false
|
|
12729
12733
|
};
|
|
12730
12734
|
}
|
|
12731
12735
|
if (dryRun) {
|
|
12732
|
-
|
|
12733
|
-
console.log(`\n(dry-run) would apply ${opCount} op(s) to ${plan.items.length} resource(s). No changes made.`);
|
|
12736
|
+
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
12737
|
return {
|
|
12735
12738
|
exit: 0,
|
|
12736
12739
|
aborted: false
|
|
@@ -12747,7 +12750,7 @@ async function revertStack(p) {
|
|
|
12747
12750
|
if (!autoSelectAll) {
|
|
12748
12751
|
const picked = await bulkMultiselect(revertSelectMessage(stackName), revertSelectOptions(plan));
|
|
12749
12752
|
if (picked === void 0) {
|
|
12750
|
-
|
|
12753
|
+
out(style.note("aborted."));
|
|
12751
12754
|
return {
|
|
12752
12755
|
exit: 0,
|
|
12753
12756
|
aborted: true
|
|
@@ -12755,7 +12758,7 @@ async function revertStack(p) {
|
|
|
12755
12758
|
}
|
|
12756
12759
|
plan = filterRevertPlan(plan, new Set(picked));
|
|
12757
12760
|
if (plan.items.length === 0) {
|
|
12758
|
-
|
|
12761
|
+
out(style.note("nothing selected — aborted."));
|
|
12759
12762
|
return {
|
|
12760
12763
|
exit: 0,
|
|
12761
12764
|
aborted: true
|
|
@@ -12764,7 +12767,7 @@ async function revertStack(p) {
|
|
|
12764
12767
|
}
|
|
12765
12768
|
const ok = await confirm({ message: revertConfirmMessage(stackName, plan.items.reduce((n, i) => n + i.ops.length, 0), plan.notRevertable.length) });
|
|
12766
12769
|
if (isCancel(ok) || !ok) {
|
|
12767
|
-
|
|
12770
|
+
out(style.note("aborted."));
|
|
12768
12771
|
return {
|
|
12769
12772
|
exit: 0,
|
|
12770
12773
|
aborted: true
|
|
@@ -12784,7 +12787,7 @@ async function revertStack(p) {
|
|
|
12784
12787
|
onRetry: ({ attempt, delayMs, hint }) => {
|
|
12785
12788
|
const reason = (hint ?? "transient error").split(" — ")[0];
|
|
12786
12789
|
const secs = Math.max(1, Math.round(delayMs / 1e3));
|
|
12787
|
-
|
|
12790
|
+
out(style.note(` ↻ ${displayId}: ${reason} — retry ${attempt} (next in ${secs}s)…`));
|
|
12788
12791
|
}
|
|
12789
12792
|
});
|
|
12790
12793
|
const deleteItems = plan.items.filter((i) => i.kind === "delete");
|
|
@@ -12852,16 +12855,19 @@ async function revertStack(p) {
|
|
|
12852
12855
|
});
|
|
12853
12856
|
if (!r.ok) worst = Math.max(worst, 2);
|
|
12854
12857
|
}
|
|
12855
|
-
|
|
12858
|
+
const summarized = summarizeRevertResults(applied);
|
|
12859
|
+
const revertedCount = summarized.filter((s) => s.ok).length;
|
|
12860
|
+
const failedCount = summarized.filter((s) => !s.ok).length;
|
|
12861
|
+
for (const s of summarized) if (s.ok) out(style.ok(` reverted: ${s.displayId}`));
|
|
12856
12862
|
else {
|
|
12857
|
-
|
|
12863
|
+
out(style.fail(` FAILED: ${s.displayId} — ${s.error}`));
|
|
12858
12864
|
if (s.hint) {
|
|
12859
12865
|
const suffix = waitMs === void 0 ? " (or re-run with --wait to block until it settles)" : "";
|
|
12860
|
-
|
|
12866
|
+
out(style.note(` ↳ ${s.hint}${suffix}`));
|
|
12861
12867
|
}
|
|
12862
12868
|
}
|
|
12863
12869
|
const touched = new Set(plan.items.map((i) => i.logicalId));
|
|
12864
|
-
|
|
12870
|
+
out("\n" + style.note(`verifying convergence (re-reading ${touched.size} resource(s))...`));
|
|
12865
12871
|
const reconcile = (findings) => applyIgnores(applyBaseline(findings, baseline, baselineOpts), {
|
|
12866
12872
|
stackName,
|
|
12867
12873
|
accountId: gathered.desired.accountId,
|
|
@@ -12896,17 +12902,19 @@ async function revertStack(p) {
|
|
|
12896
12902
|
const unverified = post.filter((f) => touched.has(f.logicalId) && f.tier === "skipped").length;
|
|
12897
12903
|
const unconfirmed = unverified + failedDeleteIds.size + failedUpdateIds.size;
|
|
12898
12904
|
const converged = remaining === 0 && unconfirmed === 0 && noOpRemovals.length === 0;
|
|
12899
|
-
for (const n of noOpRemovals)
|
|
12905
|
+
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
12906
|
const notConverged = unconfirmed + noOpRemovals.length;
|
|
12901
|
-
|
|
12907
|
+
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
12908
|
const unrecordedLeft = unrecordedCount(post);
|
|
12903
|
-
if (unrecordedLeft > 0)
|
|
12904
|
-
if (unverified > 0)
|
|
12905
|
-
for (const line of formatSurvivingDrift(remainingDrift, stackName))
|
|
12909
|
+
if (unrecordedLeft > 0) out(style.note(` (${unrecordedLeft} unrecorded value(s) still await a baseline — run cdkrd record)`));
|
|
12910
|
+
if (unverified > 0) out(style.note(` (${unverified} resource(s) could not be re-read to verify — re-run cdkrd check to confirm)`));
|
|
12911
|
+
for (const line of formatSurvivingDrift(remainingDrift, stackName)) out(line);
|
|
12906
12912
|
if (remaining > 0 || unverified > 0 || noOpRemovals.length > 0) worst = Math.max(worst, 1);
|
|
12907
12913
|
return {
|
|
12908
12914
|
exit: worst,
|
|
12909
|
-
aborted: false
|
|
12915
|
+
aborted: false,
|
|
12916
|
+
reverted: revertedCount,
|
|
12917
|
+
failed: failedCount
|
|
12910
12918
|
};
|
|
12911
12919
|
}
|
|
12912
12920
|
/**
|
|
@@ -12931,6 +12939,15 @@ function availableActions(findings, baseline, schemas, removeUnrecorded) {
|
|
|
12931
12939
|
};
|
|
12932
12940
|
}
|
|
12933
12941
|
|
|
12942
|
+
//#endregion
|
|
12943
|
+
//#region src/commands/verb-json.ts
|
|
12944
|
+
function stackLabel(stackName, region) {
|
|
12945
|
+
return region ? `${stackName} (${region})` : stackName;
|
|
12946
|
+
}
|
|
12947
|
+
function emitJsonArray(reports) {
|
|
12948
|
+
console.log(JSON.stringify(reports, null, 2));
|
|
12949
|
+
}
|
|
12950
|
+
|
|
12934
12951
|
//#endregion
|
|
12935
12952
|
//#region src/commands/record.ts
|
|
12936
12953
|
async function runRecord(args) {
|
|
@@ -12948,18 +12965,28 @@ async function runRecord(args) {
|
|
|
12948
12965
|
stacks = await resolveStacks(a);
|
|
12949
12966
|
} catch (e) {
|
|
12950
12967
|
console.error(`error: ${e.message}`);
|
|
12968
|
+
if (a.json) emitJsonArray([]);
|
|
12951
12969
|
return 2;
|
|
12952
12970
|
}
|
|
12953
12971
|
if (stacks.length === 0) {
|
|
12954
12972
|
console.error("note: the CDK app defines no stacks — nothing to record");
|
|
12973
|
+
if (a.json) emitJsonArray([]);
|
|
12955
12974
|
return 0;
|
|
12956
12975
|
}
|
|
12976
|
+
const jsonReports = [];
|
|
12957
12977
|
let worst = 0;
|
|
12958
12978
|
let wroteAny = false;
|
|
12959
12979
|
const showProgress = !a.json && isInteractive();
|
|
12960
12980
|
for (const [idx, { stackName, region, template }] of stacks.entries()) {
|
|
12961
12981
|
if (!region) {
|
|
12962
|
-
|
|
12982
|
+
const msg = "no region — set env on the stack, pass --region, or set a region for the AWS profile";
|
|
12983
|
+
console.error(`error: ${stackName}: ${msg}`);
|
|
12984
|
+
if (a.json) jsonReports.push({
|
|
12985
|
+
stack: stackName,
|
|
12986
|
+
recorded: 0,
|
|
12987
|
+
wrote: false,
|
|
12988
|
+
error: msg
|
|
12989
|
+
});
|
|
12963
12990
|
worst = Math.max(worst, 2);
|
|
12964
12991
|
continue;
|
|
12965
12992
|
}
|
|
@@ -12975,24 +13002,55 @@ async function runRecord(args) {
|
|
|
12975
13002
|
region
|
|
12976
13003
|
}, config),
|
|
12977
13004
|
yes: a.yes,
|
|
12978
|
-
interactive: isInteractive(),
|
|
12979
|
-
expandNested: a.verbose
|
|
13005
|
+
interactive: a.json ? false : isInteractive(),
|
|
13006
|
+
expandNested: a.verbose,
|
|
13007
|
+
json: a.json
|
|
12980
13008
|
});
|
|
12981
13009
|
if (result.refused) worst = Math.max(worst, 2);
|
|
12982
13010
|
if (result.wrote) wroteAny = true;
|
|
13011
|
+
if (a.json) jsonReports.push({
|
|
13012
|
+
stack: stackLabel(stackName, region),
|
|
13013
|
+
recorded: result.count ?? 0,
|
|
13014
|
+
wrote: result.wrote,
|
|
13015
|
+
...result.refused && { refused: true },
|
|
13016
|
+
...result.path !== void 0 && { baseline: result.path }
|
|
13017
|
+
});
|
|
12983
13018
|
} catch (e) {
|
|
12984
13019
|
if (isStackNotDeployed(e)) {
|
|
12985
13020
|
console.error(`note: ${stackName}: not deployed yet — nothing to record`);
|
|
13021
|
+
if (a.json) jsonReports.push({
|
|
13022
|
+
stack: stackLabel(stackName, region),
|
|
13023
|
+
recorded: 0,
|
|
13024
|
+
wrote: false,
|
|
13025
|
+
error: "not deployed yet — nothing to record"
|
|
13026
|
+
});
|
|
12986
13027
|
continue;
|
|
12987
13028
|
}
|
|
12988
13029
|
if (e instanceof StackNotCheckableError) {
|
|
12989
13030
|
console.error(`note: ${stackName}: ${e.message} — nothing to record`);
|
|
13031
|
+
if (a.json) jsonReports.push({
|
|
13032
|
+
stack: stackLabel(stackName, region),
|
|
13033
|
+
recorded: 0,
|
|
13034
|
+
wrote: false,
|
|
13035
|
+
error: `${e.message} — nothing to record`
|
|
13036
|
+
});
|
|
12990
13037
|
continue;
|
|
12991
13038
|
}
|
|
12992
|
-
|
|
13039
|
+
const msg = e.message;
|
|
13040
|
+
console.error(`error: ${stackName}: ${msg}`);
|
|
13041
|
+
if (a.json) jsonReports.push({
|
|
13042
|
+
stack: stackLabel(stackName, region),
|
|
13043
|
+
recorded: 0,
|
|
13044
|
+
wrote: false,
|
|
13045
|
+
error: msg
|
|
13046
|
+
});
|
|
12993
13047
|
worst = Math.max(worst, 2);
|
|
12994
13048
|
}
|
|
12995
13049
|
}
|
|
13050
|
+
if (a.json) {
|
|
13051
|
+
emitJsonArray(jsonReports);
|
|
13052
|
+
return worst;
|
|
13053
|
+
}
|
|
12996
13054
|
if (worst === 0 && wroteAny) console.log("commit the baseline file(s) so drift is detected against them going forward.");
|
|
12997
13055
|
return worst;
|
|
12998
13056
|
}
|
|
@@ -13014,18 +13072,28 @@ async function runIgnore(args) {
|
|
|
13014
13072
|
stacks = await resolveStacks(a);
|
|
13015
13073
|
} catch (e) {
|
|
13016
13074
|
console.error(`error: ${e.message}`);
|
|
13075
|
+
if (a.json) emitJsonArray([]);
|
|
13017
13076
|
return 2;
|
|
13018
13077
|
}
|
|
13019
13078
|
if (stacks.length === 0) {
|
|
13020
13079
|
console.error("note: the CDK app defines no stacks — nothing to ignore");
|
|
13080
|
+
if (a.json) emitJsonArray([]);
|
|
13021
13081
|
return 0;
|
|
13022
13082
|
}
|
|
13083
|
+
const jsonReports = [];
|
|
13023
13084
|
let worst = 0;
|
|
13024
13085
|
let wroteAny = false;
|
|
13025
13086
|
const showProgress = !a.json && isInteractive();
|
|
13026
13087
|
for (const [idx, { stackName, region, template }] of stacks.entries()) {
|
|
13027
13088
|
if (!region) {
|
|
13028
|
-
|
|
13089
|
+
const msg = "no region — set env on the stack, pass --region, or set a region for the AWS profile";
|
|
13090
|
+
console.error(`error: ${stackName}: ${msg}`);
|
|
13091
|
+
if (a.json) jsonReports.push({
|
|
13092
|
+
stack: stackName,
|
|
13093
|
+
added: 0,
|
|
13094
|
+
wrote: false,
|
|
13095
|
+
error: msg
|
|
13096
|
+
});
|
|
13029
13097
|
worst = Math.max(worst, 2);
|
|
13030
13098
|
continue;
|
|
13031
13099
|
}
|
|
@@ -13046,25 +13114,56 @@ async function runIgnore(args) {
|
|
|
13046
13114
|
region
|
|
13047
13115
|
}, config),
|
|
13048
13116
|
yes: a.yes,
|
|
13049
|
-
interactive: isInteractive(),
|
|
13117
|
+
interactive: a.json ? false : isInteractive(),
|
|
13050
13118
|
accountId: desired.accountId,
|
|
13051
|
-
region
|
|
13119
|
+
region,
|
|
13120
|
+
json: a.json
|
|
13052
13121
|
});
|
|
13053
13122
|
if (result.wrote) wroteAny = true;
|
|
13054
13123
|
if (result.refused) worst = Math.max(worst, 2);
|
|
13124
|
+
if (a.json) jsonReports.push({
|
|
13125
|
+
stack: stackLabel(stackName, region),
|
|
13126
|
+
added: result.added,
|
|
13127
|
+
wrote: result.wrote,
|
|
13128
|
+
...result.refused && { refused: true },
|
|
13129
|
+
...result.path !== void 0 && { config: result.path }
|
|
13130
|
+
});
|
|
13055
13131
|
} catch (e) {
|
|
13056
13132
|
if (isStackNotDeployed(e)) {
|
|
13057
13133
|
console.error(`note: ${stackName}: not deployed yet — nothing to ignore`);
|
|
13134
|
+
if (a.json) jsonReports.push({
|
|
13135
|
+
stack: stackLabel(stackName, region),
|
|
13136
|
+
added: 0,
|
|
13137
|
+
wrote: false,
|
|
13138
|
+
error: "not deployed yet — nothing to ignore"
|
|
13139
|
+
});
|
|
13058
13140
|
continue;
|
|
13059
13141
|
}
|
|
13060
13142
|
if (e instanceof StackNotCheckableError) {
|
|
13061
13143
|
console.error(`note: ${stackName}: ${e.message} — nothing to ignore`);
|
|
13144
|
+
if (a.json) jsonReports.push({
|
|
13145
|
+
stack: stackLabel(stackName, region),
|
|
13146
|
+
added: 0,
|
|
13147
|
+
wrote: false,
|
|
13148
|
+
error: `${e.message} — nothing to ignore`
|
|
13149
|
+
});
|
|
13062
13150
|
continue;
|
|
13063
13151
|
}
|
|
13064
|
-
|
|
13152
|
+
const msg = e.message;
|
|
13153
|
+
console.error(`error: ${stackName}: ${msg}`);
|
|
13154
|
+
if (a.json) jsonReports.push({
|
|
13155
|
+
stack: stackLabel(stackName, region),
|
|
13156
|
+
added: 0,
|
|
13157
|
+
wrote: false,
|
|
13158
|
+
error: msg
|
|
13159
|
+
});
|
|
13065
13160
|
worst = Math.max(worst, 2);
|
|
13066
13161
|
}
|
|
13067
13162
|
}
|
|
13163
|
+
if (a.json) {
|
|
13164
|
+
emitJsonArray(jsonReports);
|
|
13165
|
+
return worst;
|
|
13166
|
+
}
|
|
13068
13167
|
if (worst === 0 && wroteAny) console.log("commit .cdkrd/ignore.yaml so the ignore rules apply for everyone going forward.");
|
|
13069
13168
|
return worst;
|
|
13070
13169
|
}
|
|
@@ -14181,17 +14280,29 @@ async function runRevert(args) {
|
|
|
14181
14280
|
stacks = await resolveStacks(a);
|
|
14182
14281
|
} catch (e) {
|
|
14183
14282
|
console.error(`error: ${e.message}`);
|
|
14283
|
+
if (a.json) emitJsonArray([]);
|
|
14184
14284
|
return 2;
|
|
14185
14285
|
}
|
|
14186
14286
|
if (stacks.length === 0) {
|
|
14187
14287
|
console.error("note: the CDK app defines no stacks — nothing to revert");
|
|
14288
|
+
if (a.json) emitJsonArray([]);
|
|
14188
14289
|
return 0;
|
|
14189
14290
|
}
|
|
14291
|
+
const jsonReports = [];
|
|
14190
14292
|
let worst = 0;
|
|
14191
14293
|
const showProgress = !a.json && isInteractive();
|
|
14192
14294
|
for (const [idx, { stackName, region, template }] of stacks.entries()) {
|
|
14193
14295
|
if (!region) {
|
|
14194
|
-
|
|
14296
|
+
const msg = "no region — set env on the stack, pass --region, or set a region for the AWS profile";
|
|
14297
|
+
console.error(`error: ${stackName}: ${msg}`);
|
|
14298
|
+
if (a.json) jsonReports.push({
|
|
14299
|
+
stack: stackName,
|
|
14300
|
+
reverted: 0,
|
|
14301
|
+
failed: 0,
|
|
14302
|
+
aborted: false,
|
|
14303
|
+
exit: 2,
|
|
14304
|
+
error: msg
|
|
14305
|
+
});
|
|
14195
14306
|
worst = Math.max(worst, 2);
|
|
14196
14307
|
continue;
|
|
14197
14308
|
}
|
|
@@ -14199,7 +14310,7 @@ async function runRevert(args) {
|
|
|
14199
14310
|
const gathered = await gatherWithProgress(showProgress, progressLabel(idx, stacks.length, stackName, region), () => gatherFindings(stackName, region, void 0, template));
|
|
14200
14311
|
const baseline = await loadBaseline(stackName, gathered.desired.accountId, region);
|
|
14201
14312
|
if (baseline) checkBaselineAccount(baseline, gathered.desired.accountId, stackName);
|
|
14202
|
-
const
|
|
14313
|
+
const outcome = await revertStack({
|
|
14203
14314
|
stackName,
|
|
14204
14315
|
region,
|
|
14205
14316
|
gathered,
|
|
@@ -14209,23 +14320,57 @@ async function runRevert(args) {
|
|
|
14209
14320
|
yes: a.yes,
|
|
14210
14321
|
removeUnrecorded: a.removeUnrecorded,
|
|
14211
14322
|
verbose: a.verbose,
|
|
14212
|
-
interactive: isInteractive(),
|
|
14213
|
-
...a.waitMs !== void 0 && { waitMs: a.waitMs }
|
|
14323
|
+
interactive: a.json ? false : isInteractive(),
|
|
14324
|
+
...a.waitMs !== void 0 && { waitMs: a.waitMs },
|
|
14325
|
+
json: a.json
|
|
14326
|
+
});
|
|
14327
|
+
worst = Math.max(worst, outcome.exit);
|
|
14328
|
+
if (a.json) jsonReports.push({
|
|
14329
|
+
stack: stackLabel(stackName, region),
|
|
14330
|
+
reverted: outcome.reverted ?? 0,
|
|
14331
|
+
failed: outcome.failed ?? 0,
|
|
14332
|
+
aborted: outcome.aborted,
|
|
14333
|
+
exit: outcome.exit
|
|
14214
14334
|
});
|
|
14215
|
-
worst = Math.max(worst, exit);
|
|
14216
14335
|
} catch (e) {
|
|
14217
14336
|
if (isStackNotDeployed(e)) {
|
|
14218
14337
|
console.error(`note: ${stackName}: not deployed — skipped`);
|
|
14338
|
+
if (a.json) jsonReports.push({
|
|
14339
|
+
stack: stackLabel(stackName, region),
|
|
14340
|
+
reverted: 0,
|
|
14341
|
+
failed: 0,
|
|
14342
|
+
aborted: false,
|
|
14343
|
+
exit: 0,
|
|
14344
|
+
error: "not deployed — skipped"
|
|
14345
|
+
});
|
|
14219
14346
|
continue;
|
|
14220
14347
|
}
|
|
14221
14348
|
if (e instanceof StackNotCheckableError) {
|
|
14222
14349
|
console.error(`note: ${stackName}: ${e.message} — skipped`);
|
|
14350
|
+
if (a.json) jsonReports.push({
|
|
14351
|
+
stack: stackLabel(stackName, region),
|
|
14352
|
+
reverted: 0,
|
|
14353
|
+
failed: 0,
|
|
14354
|
+
aborted: false,
|
|
14355
|
+
exit: 0,
|
|
14356
|
+
error: `${e.message} — skipped`
|
|
14357
|
+
});
|
|
14223
14358
|
continue;
|
|
14224
14359
|
}
|
|
14225
|
-
|
|
14360
|
+
const msg = e.message;
|
|
14361
|
+
console.error(`error: ${stackName}: ${msg}`);
|
|
14362
|
+
if (a.json) jsonReports.push({
|
|
14363
|
+
stack: stackLabel(stackName, region),
|
|
14364
|
+
reverted: 0,
|
|
14365
|
+
failed: 0,
|
|
14366
|
+
aborted: false,
|
|
14367
|
+
exit: 2,
|
|
14368
|
+
error: msg
|
|
14369
|
+
});
|
|
14226
14370
|
worst = Math.max(worst, 2);
|
|
14227
14371
|
}
|
|
14228
14372
|
}
|
|
14373
|
+
if (a.json) emitJsonArray(jsonReports);
|
|
14229
14374
|
return worst;
|
|
14230
14375
|
}
|
|
14231
14376
|
|