cdk-real-drift 0.2.78 → 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 +201 -40
- 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
|
@@ -55,6 +55,22 @@ import { DescribeDomainConfigCommand, OpenSearchClient, UpdateDomainConfigComman
|
|
|
55
55
|
import { GetWebACLCommand, UpdateWebACLCommand, WAFV2Client } from "@aws-sdk/client-wafv2";
|
|
56
56
|
import { ConfigServiceClient, DescribeConfigRulesCommand, PutConfigRuleCommand } from "@aws-sdk/client-config-service";
|
|
57
57
|
|
|
58
|
+
//#region src/exit.ts
|
|
59
|
+
function drain(stream) {
|
|
60
|
+
return new Promise((resolve) => {
|
|
61
|
+
if (stream.writableLength === 0 || stream.writableEnded) {
|
|
62
|
+
resolve();
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
stream.write("", () => resolve());
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
async function flushAndExit(code) {
|
|
69
|
+
await Promise.all([drain(process.stdout), drain(process.stderr)]);
|
|
70
|
+
process.exit(code);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
//#endregion
|
|
58
74
|
//#region src/aws-errors.ts
|
|
59
75
|
function isStackNotDeployed(e) {
|
|
60
76
|
const msg = e?.message ?? String(e);
|
|
@@ -12490,12 +12506,14 @@ async function recordStack(p) {
|
|
|
12490
12506
|
previous: existing,
|
|
12491
12507
|
physicalIdByLogical: physicalIdsByLogical(desired.resources)
|
|
12492
12508
|
});
|
|
12493
|
-
console.log(style.ok(recordOutcomeMessage(stackName, path, count, refreshedOnly, !!existing)));
|
|
12509
|
+
if (!p.json) console.log(style.ok(recordOutcomeMessage(stackName, path, count, refreshedOnly, !!existing)));
|
|
12494
12510
|
const scopeNote = recordScopeNote(stackName, findings);
|
|
12495
12511
|
if (scopeNote) console.error(scopeNote);
|
|
12496
12512
|
return {
|
|
12497
12513
|
wrote: true,
|
|
12498
|
-
refused: false
|
|
12514
|
+
refused: false,
|
|
12515
|
+
count,
|
|
12516
|
+
path
|
|
12499
12517
|
};
|
|
12500
12518
|
}
|
|
12501
12519
|
/** Header for ignore's multiselect. The key hints are rendered by `bulkMultiselect`
|
|
@@ -12535,7 +12553,7 @@ async function ignoreStack(p) {
|
|
|
12535
12553
|
const { stackName, findings, yes, interactive, accountId = "", region = "" } = p;
|
|
12536
12554
|
const ignorable = findings.filter((f) => f.tier === "declared" || f.tier === "undeclared" || f.tier === "added");
|
|
12537
12555
|
if (ignorable.length === 0) {
|
|
12538
|
-
console.log(style.clean(`${stackName}: no ignorable drift to ignore.`));
|
|
12556
|
+
if (!p.json) console.log(style.clean(`${stackName}: no ignorable drift to ignore.`));
|
|
12539
12557
|
return {
|
|
12540
12558
|
wrote: false,
|
|
12541
12559
|
refused: false,
|
|
@@ -12573,14 +12591,15 @@ async function ignoreStack(p) {
|
|
|
12573
12591
|
}
|
|
12574
12592
|
}
|
|
12575
12593
|
const { path, added, alreadyPresent } = await addIgnoreRules(chosen.map((f) => ignoreRuleFor(f, stackName, accountId, region)));
|
|
12576
|
-
if (added.length > 0) {
|
|
12594
|
+
if (!p.json) if (added.length > 0) {
|
|
12577
12595
|
const dup = alreadyPresent.length > 0 ? `, ${alreadyPresent.length} already present` : "";
|
|
12578
12596
|
console.log(style.ok(`ignore rule(s) added: ${path} (${added.length} new${dup})`));
|
|
12579
12597
|
} else console.log(style.note(`${stackName}: all ${alreadyPresent.length} selected rule(s) already present — config unchanged`));
|
|
12580
12598
|
return {
|
|
12581
12599
|
wrote: added.length > 0,
|
|
12582
12600
|
refused: false,
|
|
12583
|
-
added: added.length
|
|
12601
|
+
added: added.length,
|
|
12602
|
+
path
|
|
12584
12603
|
};
|
|
12585
12604
|
}
|
|
12586
12605
|
/**
|
|
@@ -12668,6 +12687,7 @@ function includeUnrecordedRemovals(removeUnrecorded, interactive, yes) {
|
|
|
12668
12687
|
}
|
|
12669
12688
|
async function revertStack(p) {
|
|
12670
12689
|
const { stackName, region, gathered, baseline, config, dryRun, yes, removeUnrecorded, verbose, interactive, autoSelectAll, waitMs, waitNow, waitSleep } = p;
|
|
12690
|
+
const out = p.json ? () => {} : console.log;
|
|
12671
12691
|
let worst = 0;
|
|
12672
12692
|
const includeRemovals = includeUnrecordedRemovals(removeUnrecorded, interactive, yes);
|
|
12673
12693
|
const baselineOpts = {
|
|
@@ -12692,13 +12712,13 @@ async function revertStack(p) {
|
|
|
12692
12712
|
liveByLogical: gathered.liveByLogical
|
|
12693
12713
|
});
|
|
12694
12714
|
if (plan.items.length === 0 && plan.notRevertable.length === 0) {
|
|
12695
|
-
|
|
12715
|
+
out(style.clean(`${stackName} (${region}): no drift to revert.`));
|
|
12696
12716
|
return {
|
|
12697
12717
|
exit: 0,
|
|
12698
12718
|
aborted: false
|
|
12699
12719
|
};
|
|
12700
12720
|
}
|
|
12701
|
-
printPlan(stackName, region, plan, {
|
|
12721
|
+
if (!p.json) printPlan(stackName, region, plan, {
|
|
12702
12722
|
verbose,
|
|
12703
12723
|
unrecordedGuidance: !includeRemovals && drifted.some((f) => f.unrecorded === true)
|
|
12704
12724
|
});
|
|
@@ -12706,15 +12726,14 @@ async function revertStack(p) {
|
|
|
12706
12726
|
const dc = driftCount(drifted);
|
|
12707
12727
|
const uc = unrecordedCount(drifted);
|
|
12708
12728
|
const parts = [...dc > 0 ? [`${dc} drift(s)`] : [], ...uc > 0 ? [`${uc} unrecorded value(s)`] : []];
|
|
12709
|
-
|
|
12729
|
+
out("\n" + style.drift(`nothing revertable — ${parts.join(" + ")} remain.`));
|
|
12710
12730
|
return {
|
|
12711
12731
|
exit: 1,
|
|
12712
12732
|
aborted: false
|
|
12713
12733
|
};
|
|
12714
12734
|
}
|
|
12715
12735
|
if (dryRun) {
|
|
12716
|
-
|
|
12717
|
-
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.`);
|
|
12718
12737
|
return {
|
|
12719
12738
|
exit: 0,
|
|
12720
12739
|
aborted: false
|
|
@@ -12731,7 +12750,7 @@ async function revertStack(p) {
|
|
|
12731
12750
|
if (!autoSelectAll) {
|
|
12732
12751
|
const picked = await bulkMultiselect(revertSelectMessage(stackName), revertSelectOptions(plan));
|
|
12733
12752
|
if (picked === void 0) {
|
|
12734
|
-
|
|
12753
|
+
out(style.note("aborted."));
|
|
12735
12754
|
return {
|
|
12736
12755
|
exit: 0,
|
|
12737
12756
|
aborted: true
|
|
@@ -12739,7 +12758,7 @@ async function revertStack(p) {
|
|
|
12739
12758
|
}
|
|
12740
12759
|
plan = filterRevertPlan(plan, new Set(picked));
|
|
12741
12760
|
if (plan.items.length === 0) {
|
|
12742
|
-
|
|
12761
|
+
out(style.note("nothing selected — aborted."));
|
|
12743
12762
|
return {
|
|
12744
12763
|
exit: 0,
|
|
12745
12764
|
aborted: true
|
|
@@ -12748,7 +12767,7 @@ async function revertStack(p) {
|
|
|
12748
12767
|
}
|
|
12749
12768
|
const ok = await confirm({ message: revertConfirmMessage(stackName, plan.items.reduce((n, i) => n + i.ops.length, 0), plan.notRevertable.length) });
|
|
12750
12769
|
if (isCancel(ok) || !ok) {
|
|
12751
|
-
|
|
12770
|
+
out(style.note("aborted."));
|
|
12752
12771
|
return {
|
|
12753
12772
|
exit: 0,
|
|
12754
12773
|
aborted: true
|
|
@@ -12768,7 +12787,7 @@ async function revertStack(p) {
|
|
|
12768
12787
|
onRetry: ({ attempt, delayMs, hint }) => {
|
|
12769
12788
|
const reason = (hint ?? "transient error").split(" — ")[0];
|
|
12770
12789
|
const secs = Math.max(1, Math.round(delayMs / 1e3));
|
|
12771
|
-
|
|
12790
|
+
out(style.note(` ↻ ${displayId}: ${reason} — retry ${attempt} (next in ${secs}s)…`));
|
|
12772
12791
|
}
|
|
12773
12792
|
});
|
|
12774
12793
|
const deleteItems = plan.items.filter((i) => i.kind === "delete");
|
|
@@ -12836,16 +12855,19 @@ async function revertStack(p) {
|
|
|
12836
12855
|
});
|
|
12837
12856
|
if (!r.ok) worst = Math.max(worst, 2);
|
|
12838
12857
|
}
|
|
12839
|
-
|
|
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}`));
|
|
12840
12862
|
else {
|
|
12841
|
-
|
|
12863
|
+
out(style.fail(` FAILED: ${s.displayId} — ${s.error}`));
|
|
12842
12864
|
if (s.hint) {
|
|
12843
12865
|
const suffix = waitMs === void 0 ? " (or re-run with --wait to block until it settles)" : "";
|
|
12844
|
-
|
|
12866
|
+
out(style.note(` ↳ ${s.hint}${suffix}`));
|
|
12845
12867
|
}
|
|
12846
12868
|
}
|
|
12847
12869
|
const touched = new Set(plan.items.map((i) => i.logicalId));
|
|
12848
|
-
|
|
12870
|
+
out("\n" + style.note(`verifying convergence (re-reading ${touched.size} resource(s))...`));
|
|
12849
12871
|
const reconcile = (findings) => applyIgnores(applyBaseline(findings, baseline, baselineOpts), {
|
|
12850
12872
|
stackName,
|
|
12851
12873
|
accountId: gathered.desired.accountId,
|
|
@@ -12880,17 +12902,19 @@ async function revertStack(p) {
|
|
|
12880
12902
|
const unverified = post.filter((f) => touched.has(f.logicalId) && f.tier === "skipped").length;
|
|
12881
12903
|
const unconfirmed = unverified + failedDeleteIds.size + failedUpdateIds.size;
|
|
12882
12904
|
const converged = remaining === 0 && unconfirmed === 0 && noOpRemovals.length === 0;
|
|
12883
|
-
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)`));
|
|
12884
12906
|
const notConverged = unconfirmed + noOpRemovals.length;
|
|
12885
|
-
|
|
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).`));
|
|
12886
12908
|
const unrecordedLeft = unrecordedCount(post);
|
|
12887
|
-
if (unrecordedLeft > 0)
|
|
12888
|
-
if (unverified > 0)
|
|
12889
|
-
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);
|
|
12890
12912
|
if (remaining > 0 || unverified > 0 || noOpRemovals.length > 0) worst = Math.max(worst, 1);
|
|
12891
12913
|
return {
|
|
12892
12914
|
exit: worst,
|
|
12893
|
-
aborted: false
|
|
12915
|
+
aborted: false,
|
|
12916
|
+
reverted: revertedCount,
|
|
12917
|
+
failed: failedCount
|
|
12894
12918
|
};
|
|
12895
12919
|
}
|
|
12896
12920
|
/**
|
|
@@ -12915,6 +12939,15 @@ function availableActions(findings, baseline, schemas, removeUnrecorded) {
|
|
|
12915
12939
|
};
|
|
12916
12940
|
}
|
|
12917
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
|
+
|
|
12918
12951
|
//#endregion
|
|
12919
12952
|
//#region src/commands/record.ts
|
|
12920
12953
|
async function runRecord(args) {
|
|
@@ -12932,18 +12965,28 @@ async function runRecord(args) {
|
|
|
12932
12965
|
stacks = await resolveStacks(a);
|
|
12933
12966
|
} catch (e) {
|
|
12934
12967
|
console.error(`error: ${e.message}`);
|
|
12968
|
+
if (a.json) emitJsonArray([]);
|
|
12935
12969
|
return 2;
|
|
12936
12970
|
}
|
|
12937
12971
|
if (stacks.length === 0) {
|
|
12938
12972
|
console.error("note: the CDK app defines no stacks — nothing to record");
|
|
12973
|
+
if (a.json) emitJsonArray([]);
|
|
12939
12974
|
return 0;
|
|
12940
12975
|
}
|
|
12976
|
+
const jsonReports = [];
|
|
12941
12977
|
let worst = 0;
|
|
12942
12978
|
let wroteAny = false;
|
|
12943
12979
|
const showProgress = !a.json && isInteractive();
|
|
12944
12980
|
for (const [idx, { stackName, region, template }] of stacks.entries()) {
|
|
12945
12981
|
if (!region) {
|
|
12946
|
-
|
|
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
|
+
});
|
|
12947
12990
|
worst = Math.max(worst, 2);
|
|
12948
12991
|
continue;
|
|
12949
12992
|
}
|
|
@@ -12959,24 +13002,55 @@ async function runRecord(args) {
|
|
|
12959
13002
|
region
|
|
12960
13003
|
}, config),
|
|
12961
13004
|
yes: a.yes,
|
|
12962
|
-
interactive: isInteractive(),
|
|
12963
|
-
expandNested: a.verbose
|
|
13005
|
+
interactive: a.json ? false : isInteractive(),
|
|
13006
|
+
expandNested: a.verbose,
|
|
13007
|
+
json: a.json
|
|
12964
13008
|
});
|
|
12965
13009
|
if (result.refused) worst = Math.max(worst, 2);
|
|
12966
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
|
+
});
|
|
12967
13018
|
} catch (e) {
|
|
12968
13019
|
if (isStackNotDeployed(e)) {
|
|
12969
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
|
+
});
|
|
12970
13027
|
continue;
|
|
12971
13028
|
}
|
|
12972
13029
|
if (e instanceof StackNotCheckableError) {
|
|
12973
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
|
+
});
|
|
12974
13037
|
continue;
|
|
12975
13038
|
}
|
|
12976
|
-
|
|
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
|
+
});
|
|
12977
13047
|
worst = Math.max(worst, 2);
|
|
12978
13048
|
}
|
|
12979
13049
|
}
|
|
13050
|
+
if (a.json) {
|
|
13051
|
+
emitJsonArray(jsonReports);
|
|
13052
|
+
return worst;
|
|
13053
|
+
}
|
|
12980
13054
|
if (worst === 0 && wroteAny) console.log("commit the baseline file(s) so drift is detected against them going forward.");
|
|
12981
13055
|
return worst;
|
|
12982
13056
|
}
|
|
@@ -12998,18 +13072,28 @@ async function runIgnore(args) {
|
|
|
12998
13072
|
stacks = await resolveStacks(a);
|
|
12999
13073
|
} catch (e) {
|
|
13000
13074
|
console.error(`error: ${e.message}`);
|
|
13075
|
+
if (a.json) emitJsonArray([]);
|
|
13001
13076
|
return 2;
|
|
13002
13077
|
}
|
|
13003
13078
|
if (stacks.length === 0) {
|
|
13004
13079
|
console.error("note: the CDK app defines no stacks — nothing to ignore");
|
|
13080
|
+
if (a.json) emitJsonArray([]);
|
|
13005
13081
|
return 0;
|
|
13006
13082
|
}
|
|
13083
|
+
const jsonReports = [];
|
|
13007
13084
|
let worst = 0;
|
|
13008
13085
|
let wroteAny = false;
|
|
13009
13086
|
const showProgress = !a.json && isInteractive();
|
|
13010
13087
|
for (const [idx, { stackName, region, template }] of stacks.entries()) {
|
|
13011
13088
|
if (!region) {
|
|
13012
|
-
|
|
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
|
+
});
|
|
13013
13097
|
worst = Math.max(worst, 2);
|
|
13014
13098
|
continue;
|
|
13015
13099
|
}
|
|
@@ -13030,25 +13114,56 @@ async function runIgnore(args) {
|
|
|
13030
13114
|
region
|
|
13031
13115
|
}, config),
|
|
13032
13116
|
yes: a.yes,
|
|
13033
|
-
interactive: isInteractive(),
|
|
13117
|
+
interactive: a.json ? false : isInteractive(),
|
|
13034
13118
|
accountId: desired.accountId,
|
|
13035
|
-
region
|
|
13119
|
+
region,
|
|
13120
|
+
json: a.json
|
|
13036
13121
|
});
|
|
13037
13122
|
if (result.wrote) wroteAny = true;
|
|
13038
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
|
+
});
|
|
13039
13131
|
} catch (e) {
|
|
13040
13132
|
if (isStackNotDeployed(e)) {
|
|
13041
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
|
+
});
|
|
13042
13140
|
continue;
|
|
13043
13141
|
}
|
|
13044
13142
|
if (e instanceof StackNotCheckableError) {
|
|
13045
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
|
+
});
|
|
13046
13150
|
continue;
|
|
13047
13151
|
}
|
|
13048
|
-
|
|
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
|
+
});
|
|
13049
13160
|
worst = Math.max(worst, 2);
|
|
13050
13161
|
}
|
|
13051
13162
|
}
|
|
13163
|
+
if (a.json) {
|
|
13164
|
+
emitJsonArray(jsonReports);
|
|
13165
|
+
return worst;
|
|
13166
|
+
}
|
|
13052
13167
|
if (worst === 0 && wroteAny) console.log("commit .cdkrd/ignore.yaml so the ignore rules apply for everyone going forward.");
|
|
13053
13168
|
return worst;
|
|
13054
13169
|
}
|
|
@@ -14165,17 +14280,29 @@ async function runRevert(args) {
|
|
|
14165
14280
|
stacks = await resolveStacks(a);
|
|
14166
14281
|
} catch (e) {
|
|
14167
14282
|
console.error(`error: ${e.message}`);
|
|
14283
|
+
if (a.json) emitJsonArray([]);
|
|
14168
14284
|
return 2;
|
|
14169
14285
|
}
|
|
14170
14286
|
if (stacks.length === 0) {
|
|
14171
14287
|
console.error("note: the CDK app defines no stacks — nothing to revert");
|
|
14288
|
+
if (a.json) emitJsonArray([]);
|
|
14172
14289
|
return 0;
|
|
14173
14290
|
}
|
|
14291
|
+
const jsonReports = [];
|
|
14174
14292
|
let worst = 0;
|
|
14175
14293
|
const showProgress = !a.json && isInteractive();
|
|
14176
14294
|
for (const [idx, { stackName, region, template }] of stacks.entries()) {
|
|
14177
14295
|
if (!region) {
|
|
14178
|
-
|
|
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
|
+
});
|
|
14179
14306
|
worst = Math.max(worst, 2);
|
|
14180
14307
|
continue;
|
|
14181
14308
|
}
|
|
@@ -14183,7 +14310,7 @@ async function runRevert(args) {
|
|
|
14183
14310
|
const gathered = await gatherWithProgress(showProgress, progressLabel(idx, stacks.length, stackName, region), () => gatherFindings(stackName, region, void 0, template));
|
|
14184
14311
|
const baseline = await loadBaseline(stackName, gathered.desired.accountId, region);
|
|
14185
14312
|
if (baseline) checkBaselineAccount(baseline, gathered.desired.accountId, stackName);
|
|
14186
|
-
const
|
|
14313
|
+
const outcome = await revertStack({
|
|
14187
14314
|
stackName,
|
|
14188
14315
|
region,
|
|
14189
14316
|
gathered,
|
|
@@ -14193,23 +14320,57 @@ async function runRevert(args) {
|
|
|
14193
14320
|
yes: a.yes,
|
|
14194
14321
|
removeUnrecorded: a.removeUnrecorded,
|
|
14195
14322
|
verbose: a.verbose,
|
|
14196
|
-
interactive: isInteractive(),
|
|
14197
|
-
...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
|
|
14198
14334
|
});
|
|
14199
|
-
worst = Math.max(worst, exit);
|
|
14200
14335
|
} catch (e) {
|
|
14201
14336
|
if (isStackNotDeployed(e)) {
|
|
14202
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
|
+
});
|
|
14203
14346
|
continue;
|
|
14204
14347
|
}
|
|
14205
14348
|
if (e instanceof StackNotCheckableError) {
|
|
14206
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
|
+
});
|
|
14207
14358
|
continue;
|
|
14208
14359
|
}
|
|
14209
|
-
|
|
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
|
+
});
|
|
14210
14370
|
worst = Math.max(worst, 2);
|
|
14211
14371
|
}
|
|
14212
14372
|
}
|
|
14373
|
+
if (a.json) emitJsonArray(jsonReports);
|
|
14213
14374
|
return worst;
|
|
14214
14375
|
}
|
|
14215
14376
|
|
|
@@ -14325,13 +14486,13 @@ async function main(argv) {
|
|
|
14325
14486
|
return 2;
|
|
14326
14487
|
}
|
|
14327
14488
|
}
|
|
14328
|
-
main(process.argv.slice(2)).then((code) =>
|
|
14489
|
+
main(process.argv.slice(2)).then((code) => flushAndExit(code)).catch((e) => {
|
|
14329
14490
|
const msg = e?.message ?? String(e);
|
|
14330
14491
|
if (/credential|could not load cred|security token/i.test(msg)) console.error("error: no AWS credentials available. Configure them (aws configure / AWS_PROFILE / env vars) and retry.");
|
|
14331
14492
|
else if (/stack/i.test(msg) && /(does not exist|ValidationError)/i.test(msg)) console.error("error: stack not found in this account/region. Check the stack name and --region.");
|
|
14332
14493
|
else if (/AccessDenied|not authorized/i.test(msg)) console.error(`error: access denied — ${msg}`);
|
|
14333
14494
|
else console.error(`error: ${msg}`);
|
|
14334
|
-
|
|
14495
|
+
return flushAndExit(2);
|
|
14335
14496
|
});
|
|
14336
14497
|
|
|
14337
14498
|
//#endregion
|