@intentius/chant-lexicon-aws 0.124.52 → 0.124.55
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/dist/api/credential-chain.d.ts +3 -3
- package/dist/api/credential-chain.d.ts.map +1 -1
- package/dist/api/credential-chain.js +2 -2
- package/dist/api/read-client.d.ts +2 -2
- package/dist/api/read-client.d.ts.map +1 -1
- package/dist/api/read-client.js +2 -2
- package/dist/api/{sigv4.d.ts → signing.d.ts} +14 -34
- package/dist/api/signing.d.ts.map +1 -0
- package/dist/api/signing.js +95 -0
- package/dist/codegen/generate-lexicon.d.ts +2 -0
- package/dist/codegen/generate-lexicon.d.ts.map +1 -1
- package/dist/codegen/generate-lexicon.js +1 -0
- package/dist/components/__tests__/mock-cloud-executor.d.ts +4 -0
- package/dist/components/__tests__/mock-cloud-executor.d.ts.map +1 -1
- package/dist/components/__tests__/mock-cloud-executor.js +18 -1
- package/dist/components/apply.d.ts +46 -2
- package/dist/components/apply.d.ts.map +1 -1
- package/dist/components/apply.js +266 -30
- package/dist/components/cfn-adopt-run.d.ts +37 -0
- package/dist/components/cfn-adopt-run.d.ts.map +1 -0
- package/dist/components/cfn-adopt-run.js +104 -0
- package/dist/components/cfn-adopt.d.ts +99 -0
- package/dist/components/cfn-adopt.d.ts.map +1 -0
- package/dist/components/cfn-adopt.js +278 -0
- package/dist/components/cfn-imports.d.ts +84 -0
- package/dist/components/cfn-imports.d.ts.map +1 -0
- package/dist/components/cfn-imports.js +239 -0
- package/dist/components/cloud-executor.d.ts +38 -2
- package/dist/components/cloud-executor.d.ts.map +1 -1
- package/dist/components/cloud-executor.js +84 -2
- package/dist/health.js +1 -1
- package/dist/importable.d.ts +30 -0
- package/dist/importable.d.ts.map +1 -0
- package/dist/importable.js +72 -0
- package/dist/index-identity.d.ts +19 -0
- package/dist/index-identity.d.ts.map +1 -0
- package/dist/index-identity.js +79 -0
- package/dist/index-import.d.ts +25 -0
- package/dist/index-import.d.ts.map +1 -0
- package/dist/index-import.js +132 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/integrity.json +4 -4
- package/dist/listed-types.d.ts +11 -0
- package/dist/listed-types.d.ts.map +1 -0
- package/dist/listed-types.js +52 -0
- package/dist/manifest.json +1 -1
- package/dist/meta.json +13206 -1237
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +12 -3
- package/dist/reference-catalog.d.ts.map +1 -1
- package/dist/reference-catalog.js +62 -20
- package/dist/skills/chant-aws-carve-terraform.md +21 -14
- package/dist/spec/fetch.d.ts +5 -0
- package/dist/spec/fetch.d.ts.map +1 -1
- package/dist/spec/parse.d.ts +8 -0
- package/dist/spec/parse.d.ts.map +1 -1
- package/dist/spec/parse.js +3 -0
- package/package.json +2 -2
- package/src/api/credential-chain.ts +3 -3
- package/src/api/read-client.test.ts +2 -2
- package/src/api/read-client.ts +3 -3
- package/src/api/{sigv4.test.ts → signing.test.ts} +84 -96
- package/src/api/signing.ts +130 -0
- package/src/codegen/generate-lexicon.ts +3 -0
- package/src/components/__tests__/mock-cloud-executor.ts +20 -1
- package/src/components/apply.ts +288 -30
- package/src/components/cfn-adopt-run.test.ts +227 -0
- package/src/components/cfn-adopt-run.ts +141 -0
- package/src/components/cfn-adopt.test.ts +284 -0
- package/src/components/cfn-adopt.ts +340 -0
- package/src/components/cfn-exports-in-use.test.ts +146 -0
- package/src/components/cfn-imports-preview.test.ts +178 -0
- package/src/components/cfn-imports-three-stacks.test.ts +107 -0
- package/src/components/cfn-imports.test.ts +213 -0
- package/src/components/cfn-imports.ts +246 -0
- package/src/components/cfn-plan-shape-conformance.test.ts +83 -0
- package/src/components/cloud-executor.ts +127 -5
- package/src/components/demo-composed-stacks-floci.e2e.test.ts +235 -0
- package/src/derived-edges.test.ts +142 -0
- package/src/generated/lexicon-aws.json +13206 -1237
- package/src/health.ts +1 -1
- package/src/importable.test.ts +86 -0
- package/src/importable.ts +83 -0
- package/src/index-identity.test.ts +134 -0
- package/src/index-identity.ts +98 -0
- package/src/index-import.test.ts +257 -0
- package/src/index-import.ts +158 -0
- package/src/index-search.test.ts +87 -0
- package/src/index.ts +1 -1
- package/src/listed-types.test.ts +97 -0
- package/src/listed-types.ts +56 -0
- package/src/plugin.ts +13 -3
- package/src/reference-catalog.ts +63 -20
- package/src/skills/chant-aws-carve-terraform.md +21 -14
- package/src/spec/fetch.ts +5 -0
- package/src/spec/parse.test.ts +15 -0
- package/src/spec/parse.ts +12 -0
- package/src/testdata/indexed/identity.listing.json +65 -0
- package/src/testdata/indexed/import.listing.json +126 -0
- package/src/testdata/indexed/listing.json +69 -0
- package/src/testdata/indexed/topology.listing.json +350 -0
- package/src/testdata/three-cloud/dns.graph.json +336 -0
- package/src/three-cloud-parity.test.ts +49 -0
- package/dist/api/sigv4.d.ts.map +0 -1
- package/dist/api/sigv4.js +0 -185
- package/src/api/sigv4.ts +0 -243
package/dist/components/apply.js
CHANGED
|
@@ -19,10 +19,13 @@
|
|
|
19
19
|
* invoke, or SSM host command).
|
|
20
20
|
*/
|
|
21
21
|
import { createHash } from "node:crypto";
|
|
22
|
-
import { readFileSync } from "node:fs";
|
|
22
|
+
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
23
|
+
import { tmpdir } from "node:os";
|
|
24
|
+
import { join } from "node:path";
|
|
23
25
|
import { computePlanDigest } from "@intentius/chant/lifecycle/plan-digest";
|
|
24
26
|
import { normalizePlanShape, PlanShapeMovedError, planShapeDifferences, planShapeDigest, } from "@intentius/chant/components/covered-round";
|
|
25
27
|
import { defaultCloudExecutor } from "./cloud-executor.js";
|
|
28
|
+
import { cfnExports, cfnImportPointer, cfnImports, cfnKnownValues, cfnTemplateWithStandIns, readCfnTemplate, resolveCfnName } from "./cfn-imports.js";
|
|
26
29
|
/** CloudFormation's wording when a change set has nothing to apply — the stack
|
|
27
30
|
* is already current. AWS phrases it "The submitted information didn't contain
|
|
28
31
|
* changes."; `aws cloudformation deploy` reports "No updates are to be
|
|
@@ -157,6 +160,8 @@ preview) {
|
|
|
157
160
|
templateDigest: templateDigest(input.template),
|
|
158
161
|
parameters,
|
|
159
162
|
unresolved,
|
|
163
|
+
// #4466: the exports the template imports from stacks in the change, as resolved.
|
|
164
|
+
...(input.imports && Object.keys(input.imports).length > 0 ? { imports: importValues(input.imports) } : {}),
|
|
160
165
|
...(preview ? { preview } : {}),
|
|
161
166
|
});
|
|
162
167
|
}
|
|
@@ -167,10 +172,14 @@ preview) {
|
|
|
167
172
|
* exist yet gets a CREATE change set, so every resource reads as a create,
|
|
168
173
|
* and the empty `REVIEW_IN_PROGRESS` stack CloudFormation made to hold it is
|
|
169
174
|
* deleted too. A change set with nothing to apply (`isNoopChangeSet`) gives
|
|
170
|
-
* a member with no entries. A step whose parameters read outputs
|
|
171
|
-
* not known yet, from a stack the same run applies first,
|
|
172
|
-
*
|
|
173
|
-
*
|
|
175
|
+
* a member with no entries. A step whose parameters or imports read outputs
|
|
176
|
+
* that are not known yet, from a stack the same run applies first, is
|
|
177
|
+
* previewed: its change set is made against a stand-in for each unknown
|
|
178
|
+
* value (#4423), an import standing in as a parameter of a template copy
|
|
179
|
+
* (#4466b), and `run` checks the real change set's shape against the
|
|
180
|
+
* preview's before it executes. When no preview can be made, its member gets
|
|
181
|
+
* a hole saying whose outputs it waits on, and no artifact, so `run` plans
|
|
182
|
+
* it afresh.
|
|
174
183
|
*
|
|
175
184
|
* With `onReplace: "block"` (the default), a change set that replaces a
|
|
176
185
|
* resource fails the plan with {@link CfnReplacementBlockedError}, so the
|
|
@@ -202,31 +211,51 @@ async function planCfnDeploy(executor, ctx, input) {
|
|
|
202
211
|
}
|
|
203
212
|
const unresolved = [...(ctx.unresolvedInputs ?? [])].sort();
|
|
204
213
|
let planDigest = cfnPlanDigest(ctx, stack, input, parameters, unresolved);
|
|
214
|
+
// #4466: an import whose name the plan cannot resolve is a hole that says why.
|
|
215
|
+
const importHoles = unresolvedImportHoles(stack, input, knownParameters(parameters));
|
|
216
|
+
// #4466c: an export another stack imports that the plan may change, said where it cannot tell.
|
|
217
|
+
const exportHoles = [];
|
|
205
218
|
const member = (holes) => ({
|
|
206
219
|
member: stack,
|
|
207
220
|
lexicon: "aws",
|
|
208
221
|
planner: "chant",
|
|
209
222
|
status: "planned",
|
|
210
223
|
planDigest,
|
|
211
|
-
holes,
|
|
224
|
+
holes: [...holes, ...importHoles, ...exportHoles],
|
|
212
225
|
});
|
|
226
|
+
const standing = standingReader(executor, stack);
|
|
213
227
|
if (unresolved.length > 0 || missing.length > 0) {
|
|
214
228
|
const hole = (why) => ({
|
|
215
229
|
member: stack,
|
|
216
230
|
planDigest,
|
|
217
231
|
changeSet: { member: member([{ address: stack, type: "AWS::CloudFormation::Stack", reason: why }]), entries: [] },
|
|
218
232
|
});
|
|
233
|
+
const waiting = unknownImports(input);
|
|
219
234
|
const fallback = unresolved.length > 0
|
|
220
|
-
?
|
|
235
|
+
? missing.length === 0 && waiting.length > 0
|
|
236
|
+
? `imports ${waiting.join(", ")}, exported by ${unresolved.join(", ")}, which apply first; re-checked on apply`
|
|
237
|
+
: `inputs from ${unresolved.join(", ")}; re-checked on apply`
|
|
221
238
|
: `inputs ${[...missing].sort().join(", ")} are known only at apply; re-checked on apply`;
|
|
222
|
-
// Which parameters are unknown: the inputs that hold nothing yet
|
|
223
|
-
//
|
|
224
|
-
|
|
239
|
+
// Which parameters are unknown: the inputs that hold nothing yet, and a
|
|
240
|
+
// stand-in for each import of an export not known yet (#4466b). When the
|
|
241
|
+
// upstream is unresolved but neither says which, nothing can be previewed.
|
|
242
|
+
if (missing.length === 0 && waiting.length === 0)
|
|
225
243
|
return hole(fallback);
|
|
226
|
-
const
|
|
244
|
+
const copy = waiting.length > 0 ? standInTemplate(stack, input, waiting, knownParameters(parameters)) : undefined;
|
|
245
|
+
if (typeof copy === "string")
|
|
246
|
+
return hole(`${fallback}; no preview: ${copy}`);
|
|
247
|
+
let preview;
|
|
248
|
+
try {
|
|
249
|
+
const previewed = copy ? { ...input, template: copy.path } : input;
|
|
250
|
+
preview = await previewCfnDeploy(executor, stack, previewed, [...missing, ...(copy?.parameters ?? [])].sort(), unresolved.length > 0 ? unresolved : undefined);
|
|
251
|
+
}
|
|
252
|
+
finally {
|
|
253
|
+
copy?.remove();
|
|
254
|
+
}
|
|
227
255
|
if (typeof preview === "string")
|
|
228
256
|
return hole(`${fallback}; no preview: ${preview}`);
|
|
229
257
|
const { entries, shape, outputs } = preview;
|
|
258
|
+
exportHoles.push(...(await exportsInUse(executor, stack, input, knownParameters(parameters), outputs, standing)));
|
|
230
259
|
const artifact = { kind: "cfn-deploy-shape", member: stack, shape, digest: planShapeDigest(shape) };
|
|
231
260
|
// The preview's shape enters the digest (#4423); `member` reads it when called below.
|
|
232
261
|
planDigest = cfnPlanDigest(ctx, stack, input, parameters, unresolved, artifact.digest);
|
|
@@ -241,8 +270,8 @@ async function planCfnDeploy(executor, ctx, input) {
|
|
|
241
270
|
if (isNoopChangeSet(changeSet)) {
|
|
242
271
|
const artifact = { kind: "cfn-deploy-plan", stack, changesDigest: cfnChangesDigest(stack, changeSet) };
|
|
243
272
|
// Nothing to apply, so the outputs the stack has are the ones it will have (#3999).
|
|
244
|
-
const
|
|
245
|
-
const outputs =
|
|
273
|
+
const now = await standing();
|
|
274
|
+
const outputs = now ? { known: { ...now.outputs }, unknown: [] } : undefined;
|
|
246
275
|
return { member: stack, planDigest, artifact, changeSet: { member: member([]), entries: [] }, ...(outputs ? { outputs } : {}) };
|
|
247
276
|
}
|
|
248
277
|
if (changeSet.status === "FAILED") {
|
|
@@ -253,7 +282,12 @@ async function planCfnDeploy(executor, ctx, input) {
|
|
|
253
282
|
throw new CfnReplacementBlockedError(stack, blocked);
|
|
254
283
|
const entries = changeSet.changes.map((c) => cfnChangeEntry(stack, c));
|
|
255
284
|
const artifact = { kind: "cfn-deploy-plan", stack, changesDigest: cfnChangesDigest(stack, changeSet) };
|
|
256
|
-
const outputs = changeSet.stackCreated
|
|
285
|
+
const outputs = changeSet.stackCreated
|
|
286
|
+
? undefined
|
|
287
|
+
: await plannedStackOutputs(standing, input.template, changeSet.changes, knownParameters(parameters), importValues(input.imports ?? {}));
|
|
288
|
+
// #4466c: CloudFormation refuses to change or remove an export another stack imports; say so now, not at apply.
|
|
289
|
+
if (!changeSet.stackCreated)
|
|
290
|
+
exportHoles.push(...(await exportsInUse(executor, stack, input, knownParameters(parameters), outputs, standing)));
|
|
257
291
|
// The real change set's shape, with the replacement CloudFormation reports,
|
|
258
292
|
// for a round that checks it against a preview (#4419).
|
|
259
293
|
const shape = cfnPlanShape(stack, changeSet, []);
|
|
@@ -388,7 +422,9 @@ export function cfnPlanShape(stack, changeSet, unknown, templatePath, refs = unk
|
|
|
388
422
|
* Floci accepts a change set that real CloudFormation refuses (a missing
|
|
389
423
|
* export, an id that does not exist), reports `Parameters: null`, and says
|
|
390
424
|
* `Replacement: False` for a change that replaces. So a cross-stack value
|
|
391
|
-
* goes through a parameter here, never an export
|
|
425
|
+
* goes through a parameter here, never an export: an import of an export
|
|
426
|
+
* not known yet is planned from a copy of the template in which it is a
|
|
427
|
+
* stand-in parameter (#4466b, `cfnTemplateWithStandIns`). The replacement a
|
|
392
428
|
* preview reports is whatever the backend says; the shape check at apply
|
|
393
429
|
* compares like with like.
|
|
394
430
|
*/
|
|
@@ -414,7 +450,7 @@ async function previewCfnDeploy(executor, stack, input, unknown, refs = unknown)
|
|
|
414
450
|
// output that reads one of the unknown parameters is unknown, one that
|
|
415
451
|
// reads a known parameter or states its value is not (#4419).
|
|
416
452
|
const given = Object.fromEntries(Object.entries(parameters).filter(([k]) => !unknown.includes(k)));
|
|
417
|
-
const outputs = noop || changeSet.stackCreated ? undefined : await plannedStackOutputs(executor, stack, input.template, changeSet.changes, given);
|
|
453
|
+
const outputs = noop || changeSet.stackCreated ? undefined : await plannedStackOutputs(standingReader(executor, stack), input.template, changeSet.changes, given);
|
|
418
454
|
return { entries, shape: cfnPlanShape(stack, changeSet, unknown, input.template, refs), ...(outputs ? { outputs } : {}) };
|
|
419
455
|
}
|
|
420
456
|
finally {
|
|
@@ -443,26 +479,23 @@ async function cleanUpPlanChangeSet(executor, changeSet) {
|
|
|
443
479
|
}
|
|
444
480
|
}
|
|
445
481
|
}
|
|
446
|
-
/** The stack
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
}
|
|
451
|
-
catch {
|
|
452
|
-
return undefined;
|
|
453
|
-
}
|
|
482
|
+
/** The stack as it stands, read once however often it is asked for, or `undefined` when it cannot be read. */
|
|
483
|
+
function standingReader(executor, stack) {
|
|
484
|
+
let read;
|
|
485
|
+
return () => (read ?? (read = executor.cloudformation.describeStack(stack).then((s) => s, () => undefined)));
|
|
454
486
|
}
|
|
455
487
|
/**
|
|
456
488
|
* What the plan says of the stack's outputs once `changes` apply: none to
|
|
457
489
|
* say for a template with no `Outputs`, which needs no `DescribeStacks`.
|
|
458
490
|
*/
|
|
459
|
-
async function plannedStackOutputs(
|
|
491
|
+
async function plannedStackOutputs(standing, templatePath, changes, parameters = {}, imports = {}) {
|
|
460
492
|
const template = readTemplate(templatePath);
|
|
461
493
|
if (!template || typeof template !== "object")
|
|
462
494
|
return undefined;
|
|
463
495
|
if (Object.keys(template.Outputs ?? {}).length === 0)
|
|
464
496
|
return { known: {}, unknown: [] };
|
|
465
|
-
|
|
497
|
+
const now = await standing();
|
|
498
|
+
return cfnPlannedOutputs(template, changes, now ? { ...now.outputs } : undefined, parameters, imports);
|
|
466
499
|
}
|
|
467
500
|
/** The template at `path` as JSON, or `undefined` when it cannot be read or parsed here. */
|
|
468
501
|
function readTemplate(path) {
|
|
@@ -551,9 +584,13 @@ function valueReads(value) {
|
|
|
551
584
|
* known at that value (`given`, the inputs of this plan). Both are what
|
|
552
585
|
* the stack's outputs will be, whatever they are now.
|
|
553
586
|
*
|
|
587
|
+
* An output that passes an import through (`Fn::ImportValue` of a name
|
|
588
|
+
* `imports` holds, #4466) is known at the value the exporting stack's plan
|
|
589
|
+
* gave it, which is the value core read for the import.
|
|
590
|
+
*
|
|
554
591
|
* `undefined` when there is no template or no standing stack to read from.
|
|
555
592
|
*/
|
|
556
|
-
export function cfnPlannedOutputs(template, changes, standing, given = {}) {
|
|
593
|
+
export function cfnPlannedOutputs(template, changes, standing, given = {}, imports = {}) {
|
|
557
594
|
if (!standing || template === null || typeof template !== "object")
|
|
558
595
|
return undefined;
|
|
559
596
|
const t = template;
|
|
@@ -568,7 +605,7 @@ export function cfnPlannedOutputs(template, changes, standing, given = {}) {
|
|
|
568
605
|
const known = {};
|
|
569
606
|
const unknown = [];
|
|
570
607
|
for (const [name, output] of Object.entries(t.Outputs ?? {}).sort(([a], [b]) => a.localeCompare(b))) {
|
|
571
|
-
const stated = statedOutput(output, given, t.Parameters);
|
|
608
|
+
const stated = statedOutput(output, given, t.Parameters, imports);
|
|
572
609
|
if (stated !== undefined) {
|
|
573
610
|
known[name] = stated;
|
|
574
611
|
continue;
|
|
@@ -592,7 +629,7 @@ function knownParameters(parameters) {
|
|
|
592
629
|
* parameter this plan has a value for. `undefined` for anything that reads a
|
|
593
630
|
* resource, an import or a condition, which the standing outputs speak for.
|
|
594
631
|
*/
|
|
595
|
-
function statedOutput(output, parameters, declared) {
|
|
632
|
+
function statedOutput(output, parameters, declared, imports = {}) {
|
|
596
633
|
if (output?.Condition !== undefined)
|
|
597
634
|
return undefined;
|
|
598
635
|
const value = output?.Value;
|
|
@@ -603,11 +640,202 @@ function statedOutput(output, parameters, declared) {
|
|
|
603
640
|
const [key, arg] = entries[0] ?? [];
|
|
604
641
|
if (entries.length === 1 && key === "Ref" && typeof arg === "string" && declared && arg in declared && arg in parameters)
|
|
605
642
|
return parameters[arg];
|
|
643
|
+
if (entries.length === 1 && key === "Fn::ImportValue") {
|
|
644
|
+
const name = resolveCfnName(arg, parameters);
|
|
645
|
+
if ("name" in name && name.name in imports)
|
|
646
|
+
return imports[name.name];
|
|
647
|
+
}
|
|
606
648
|
}
|
|
607
649
|
return undefined;
|
|
608
650
|
}
|
|
651
|
+
// ── Fn::ImportValue between stacks (#4466) ──────────────────────────────────
|
|
652
|
+
/** The imports core read a value for, as strings; one still unknown is left out. */
|
|
653
|
+
function importValues(imports) {
|
|
654
|
+
const out = {};
|
|
655
|
+
for (const [name, v] of Object.entries(imports).sort(([a], [b]) => a.localeCompare(b))) {
|
|
656
|
+
if (v === undefined || v === null)
|
|
657
|
+
continue;
|
|
658
|
+
out[name] = typeof v === "string" ? v : JSON.stringify(v);
|
|
659
|
+
}
|
|
660
|
+
return out;
|
|
661
|
+
}
|
|
662
|
+
/** The export names the step imports from a stack in the change whose value is not known yet, sorted. */
|
|
663
|
+
function unknownImports(input) {
|
|
664
|
+
return Object.entries(input.imports ?? {})
|
|
665
|
+
.filter(([, v]) => v === undefined || v === null)
|
|
666
|
+
.map(([name]) => name)
|
|
667
|
+
.sort();
|
|
668
|
+
}
|
|
669
|
+
/**
|
|
670
|
+
* A hole for each `Fn::ImportValue` in the template whose name the plan
|
|
671
|
+
* cannot resolve (#4466): it may name an export of a stack in this change,
|
|
672
|
+
* and then nothing orders the two, so the plan says it cannot tell.
|
|
673
|
+
*/
|
|
674
|
+
function unresolvedImportHoles(stack, input, parameters) {
|
|
675
|
+
const template = readCfnTemplate(input.template);
|
|
676
|
+
if (!template)
|
|
677
|
+
return [];
|
|
678
|
+
const resources = (template.Resources ?? {});
|
|
679
|
+
const holes = [];
|
|
680
|
+
for (const i of cfnImports(template, cfnKnownValues(template, stack, parameters))) {
|
|
681
|
+
if (!("unresolved" in i))
|
|
682
|
+
continue;
|
|
683
|
+
const type = typeof resources[i.logicalId]?.Type === "string" ? resources[i.logicalId].Type : undefined;
|
|
684
|
+
holes.push({
|
|
685
|
+
address: i.logicalId,
|
|
686
|
+
...(type ? { type } : {}),
|
|
687
|
+
reason: `the Fn::ImportValue at ${i.at} ${i.unresolved}, so the plan cannot say which export it reads or whether a stack in this change exports it`,
|
|
688
|
+
});
|
|
689
|
+
}
|
|
690
|
+
return holes;
|
|
691
|
+
}
|
|
692
|
+
/**
|
|
693
|
+
* The importer's template with each import of `names` as a stand-in
|
|
694
|
+
* parameter (#4466b), written to a scratch file the preview creates its
|
|
695
|
+
* change set from; or why there is none. `remove` deletes the file.
|
|
696
|
+
*/
|
|
697
|
+
function standInTemplate(stack, input, names, parameters) {
|
|
698
|
+
const template = readCfnTemplate(input.template);
|
|
699
|
+
if (!template)
|
|
700
|
+
return "the template could not be read as JSON to stand in for its imports";
|
|
701
|
+
const { template: copy, standIns } = cfnTemplateWithStandIns(template, names, cfnKnownValues(template, stack, parameters));
|
|
702
|
+
const params = Object.keys(standIns).sort();
|
|
703
|
+
if (params.length === 0)
|
|
704
|
+
return `the template imports none of ${names.join(", ")} by a name the plan resolves`;
|
|
705
|
+
const dir = mkdtempSync(join(tmpdir(), "chant-cfn-preview-"));
|
|
706
|
+
const path = join(dir, `${stack}.preview.template.json`);
|
|
707
|
+
writeFileSync(path, JSON.stringify(copy, null, 2));
|
|
708
|
+
return { path, parameters: params, remove: () => rmSync(dir, { recursive: true, force: true }) };
|
|
709
|
+
}
|
|
710
|
+
/**
|
|
711
|
+
* `cfn-deploy`'s `declaredReads` (#4466): each `Fn::ImportValue` of a name
|
|
712
|
+
* exactly one other `cfn-deploy` step's template exports is a read of that
|
|
713
|
+
* component's output, placed under the step's `imports`. A name two steps
|
|
714
|
+
* export is left alone (CloudFormation refuses the second export), and so
|
|
715
|
+
* is a name no step in the project exports: it reads a stack outside it.
|
|
716
|
+
*/
|
|
717
|
+
export function cfnDeclaredReads(root, members) {
|
|
718
|
+
const seen = members.map((m) => {
|
|
719
|
+
const template = readCfnTemplate(m.step.template, root);
|
|
720
|
+
const stack = typeof m.step.stack === "string" ? m.step.stack : m.component;
|
|
721
|
+
const inputs = (m.step.inputs ?? {});
|
|
722
|
+
const known = cfnKnownValues(template, stack, typeof m.step.imageRef === "string" ? { ...inputs, ImageRef: m.step.imageRef } : inputs);
|
|
723
|
+
return { member: m, template, known };
|
|
724
|
+
});
|
|
725
|
+
const exporters = new Map();
|
|
726
|
+
for (const { member, template, known } of seen) {
|
|
727
|
+
for (const e of cfnExports(template, known)) {
|
|
728
|
+
if (!("name" in e))
|
|
729
|
+
continue;
|
|
730
|
+
(exporters.get(e.name) ?? exporters.set(e.name, []).get(e.name)).push({ component: member.component, output: e.output });
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
const out = [];
|
|
734
|
+
for (const { member, template, known } of seen) {
|
|
735
|
+
const done = new Set();
|
|
736
|
+
for (const i of cfnImports(template, known)) {
|
|
737
|
+
if (!("name" in i) || done.has(i.name))
|
|
738
|
+
continue;
|
|
739
|
+
done.add(i.name);
|
|
740
|
+
const owners = (exporters.get(i.name) ?? []).filter((o) => o.component !== member.component);
|
|
741
|
+
if (owners.length !== 1 || (exporters.get(i.name) ?? []).length !== 1)
|
|
742
|
+
continue;
|
|
743
|
+
out.push({ reader: member.component, index: member.index, upstream: owners[0].component, output: owners[0].output, at: cfnImportPointer(i.name) });
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
return out;
|
|
747
|
+
}
|
|
609
748
|
/** Whether a CloudFormation error says the stack does not exist. */
|
|
610
749
|
const STACK_MISSING = /does not exist/i;
|
|
750
|
+
/**
|
|
751
|
+
* Thrown at plan time when a change set would change or remove an export
|
|
752
|
+
* that another stack still imports (#4466c). CloudFormation refuses that
|
|
753
|
+
* update at apply; the plan refuses it first, naming both stacks.
|
|
754
|
+
*/
|
|
755
|
+
export class CfnExportInUseError extends Error {
|
|
756
|
+
constructor(stack, uses) {
|
|
757
|
+
const importers = [...new Set(uses.flatMap((u) => u.importers))].sort();
|
|
758
|
+
super(`cfn-deploy "${stack}": refusing the plan: ` +
|
|
759
|
+
uses
|
|
760
|
+
.map((u) => `it ${u.change.replace("{export}", `export ${u.exportName}`)}, which ${u.importers.length === 1 ? "stack" : "stacks"} ${u.importers.join(", ")} still ${u.importers.length === 1 ? "imports" : "import"}`)
|
|
761
|
+
.join("; ") +
|
|
762
|
+
`. CloudFormation refuses to change or remove an export another stack imports. Change ${importers.join(", ")} to stop importing it first, then change ${stack}.`);
|
|
763
|
+
this.stack = stack;
|
|
764
|
+
this.uses = uses;
|
|
765
|
+
this.name = "CfnExportInUseError";
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
/**
|
|
769
|
+
* The exports `stack` has now that this plan changes or removes while
|
|
770
|
+
* another stack imports them (#4466c). An export the new template no longer
|
|
771
|
+
* declares is removed; one whose planned value differs from the value it
|
|
772
|
+
* has is changed: both throw {@link CfnExportInUseError}. One the plan
|
|
773
|
+
* cannot say about (its output's value is known only after apply, or an
|
|
774
|
+
* export name in the new template does not resolve) is a hole naming the
|
|
775
|
+
* importers. Asks `ListImports` only for exports at stake, and nothing at
|
|
776
|
+
* all when the executor cannot list imports or the stack exports nothing.
|
|
777
|
+
*/
|
|
778
|
+
async function exportsInUse(executor, stack, input, parameters, planned, standing) {
|
|
779
|
+
const listImports = executor.cloudformation.listImports?.bind(executor.cloudformation);
|
|
780
|
+
if (!listImports)
|
|
781
|
+
return [];
|
|
782
|
+
const was = (await standing())?.exports;
|
|
783
|
+
if (!was || Object.keys(was).length === 0)
|
|
784
|
+
return [];
|
|
785
|
+
const template = readCfnTemplate(input.template);
|
|
786
|
+
if (!template)
|
|
787
|
+
return [];
|
|
788
|
+
const declared = cfnExports(template, cfnKnownValues(template, stack, parameters));
|
|
789
|
+
const now = new Map(declared.filter((e) => "name" in e).map((e) => [e.name, e.output]));
|
|
790
|
+
const unresolvedNow = declared.some((e) => "unresolved" in e);
|
|
791
|
+
const refused = [];
|
|
792
|
+
const holes = [];
|
|
793
|
+
for (const [exportName, { output, value }] of Object.entries(was).sort(([a], [b]) => a.localeCompare(b))) {
|
|
794
|
+
const at = now.get(exportName);
|
|
795
|
+
let change;
|
|
796
|
+
let maybe;
|
|
797
|
+
if (at === undefined) {
|
|
798
|
+
if (unresolvedNow)
|
|
799
|
+
maybe = `may remove export ${exportName}: an export name the template declares does not resolve at plan`;
|
|
800
|
+
else
|
|
801
|
+
change = "removes {export}";
|
|
802
|
+
}
|
|
803
|
+
else {
|
|
804
|
+
const next = planned?.known[at];
|
|
805
|
+
if (next === undefined)
|
|
806
|
+
maybe = `may change export ${exportName}: the value of output ${at} is known only after apply`;
|
|
807
|
+
else if ((typeof next === "string" ? next : JSON.stringify(next)) !== value)
|
|
808
|
+
change = `changes {export} from ${value} to ${typeof next === "string" ? next : JSON.stringify(next)}`;
|
|
809
|
+
}
|
|
810
|
+
if (change === undefined && maybe === undefined)
|
|
811
|
+
continue;
|
|
812
|
+
let importers;
|
|
813
|
+
try {
|
|
814
|
+
importers = (await listImports(exportName)).filter((s) => s !== stack);
|
|
815
|
+
}
|
|
816
|
+
catch (err) {
|
|
817
|
+
// A backend without ListImports (an emulator, say) cannot say who imports it; the plan says so instead of failing.
|
|
818
|
+
holes.push({
|
|
819
|
+
address: `Outputs.${at ?? output}`,
|
|
820
|
+
reason: `the plan ${change?.replace("{export}", `export ${exportName}`) ?? maybe}, and the stacks that import it could not be listed: ${err instanceof Error ? err.message : String(err)}`,
|
|
821
|
+
});
|
|
822
|
+
continue;
|
|
823
|
+
}
|
|
824
|
+
if (importers.length === 0)
|
|
825
|
+
continue;
|
|
826
|
+
if (change !== undefined)
|
|
827
|
+
refused.push({ exportName, change, importers });
|
|
828
|
+
else {
|
|
829
|
+
holes.push({
|
|
830
|
+
address: `Outputs.${at ?? output}`,
|
|
831
|
+
reason: `the plan ${maybe}, and ${importers.join(", ")} still ${importers.length === 1 ? "imports" : "import"} it; CloudFormation refuses the apply if it changes`,
|
|
832
|
+
});
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
if (refused.length > 0)
|
|
836
|
+
throw new CfnExportInUseError(stack, refused);
|
|
837
|
+
return holes;
|
|
838
|
+
}
|
|
611
839
|
/**
|
|
612
840
|
* Thrown when a changeset proposes a resource replacement and `onReplace` is
|
|
613
841
|
* `"block"` (the default) — refusing to apply rather than silently destroying
|
|
@@ -655,6 +883,9 @@ export function createCfnDeployCapability(executor = defaultCloudExecutor()) {
|
|
|
655
883
|
plan(ctx, input) {
|
|
656
884
|
return planCfnDeploy(executor, ctx, input);
|
|
657
885
|
},
|
|
886
|
+
declaredReads(ctx, members) {
|
|
887
|
+
return cfnDeclaredReads(ctx.root, members);
|
|
888
|
+
},
|
|
658
889
|
async outputs(ctx, input) {
|
|
659
890
|
// The outputs the stack has now, for a dependent planned before it
|
|
660
891
|
// applies (#3183). A stack that does not exist yet has none.
|
|
@@ -668,6 +899,11 @@ export function createCfnDeployCapability(executor = defaultCloudExecutor()) {
|
|
|
668
899
|
}
|
|
669
900
|
},
|
|
670
901
|
async run(ctx, input) {
|
|
902
|
+
// #4537: `run --components <name> --adopt <file>` adopts into this stack instead of a plain deploy.
|
|
903
|
+
if (ctx.adoption) {
|
|
904
|
+
const { runCfnAdoption } = await import("./cfn-adopt-run.js");
|
|
905
|
+
return runCfnAdoption(executor, ctx, input, ctx.adoption);
|
|
906
|
+
}
|
|
671
907
|
const stack = input.stack ?? ctx.component;
|
|
672
908
|
const onReplace = input.onReplace ?? "block";
|
|
673
909
|
const changeSet = await executor.cloudformation.createChangeSet({
|
|
@@ -768,7 +1004,7 @@ export function createCfnDeployCapability(executor = defaultCloudExecutor()) {
|
|
|
768
1004
|
};
|
|
769
1005
|
}
|
|
770
1006
|
/** Flatten the wired `inputs` map plus `imageRef` (already resolved by the driver) to plain string CloudFormation parameters. */
|
|
771
|
-
function flattenCfnInputs(input) {
|
|
1007
|
+
export function flattenCfnInputs(input) {
|
|
772
1008
|
const params = {};
|
|
773
1009
|
for (const [key, value] of Object.entries(input.inputs ?? {})) {
|
|
774
1010
|
params[key] = typeof value === "string" ? value : JSON.stringify(value);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `cfn-deploy` under `chant run --components <name> --env <env> --adopt
|
|
3
|
+
* <adoption-file>` (#4537): the step adopts the file's resources into its
|
|
4
|
+
* stack with ./cfn-adopt.ts instead of deploying the template plainly.
|
|
5
|
+
*
|
|
6
|
+
* Core hands the step the adoption file, the index version it names and the
|
|
7
|
+
* review on `DeployContext.adoption` (packages/core/src/components/adoption.ts).
|
|
8
|
+
* This step plans the adoption against the step's built template and the
|
|
9
|
+
* stack's resources now, then runs the IMPORT change set and the marker
|
|
10
|
+
* UPDATE, each through that review. Everything the library refuses is
|
|
11
|
+
* refused here, by name, before any change set is made, and the change set a
|
|
12
|
+
* refusal or a declined review leaves is deleted.
|
|
13
|
+
*
|
|
14
|
+
* When the marker step stops after a good import, the resources are in the
|
|
15
|
+
* stack, with the template's DeletionPolicy (Retain from `chant import
|
|
16
|
+
* --index`) and without chant's markers. A plain deploy of the same template
|
|
17
|
+
* writes them, and the outcome says so.
|
|
18
|
+
*/
|
|
19
|
+
import type { DeployContext } from "@intentius/chant/components/capability";
|
|
20
|
+
import type { DeployAdoption, DeployAdoptionOutcome } from "@intentius/chant/components/adoption";
|
|
21
|
+
import { type CfnDeployInput, type CfnDeployOutput } from "./apply.js";
|
|
22
|
+
import { type CfnAdoptionOutcome, type CfnAdoptionPlan } from "./cfn-adopt.js";
|
|
23
|
+
import type { CloudExecutor } from "./cloud-executor.js";
|
|
24
|
+
import type { ImportabilityManifestEntry } from "../importable.js";
|
|
25
|
+
/** What to do when the marker step stops after a good import. */
|
|
26
|
+
export declare function markerStepHint(stack: string, component: string, env: string): string;
|
|
27
|
+
/** The outcome lines and status for one adoption result. */
|
|
28
|
+
export declare function adoptionOutcome(stack: string, ctx: Pick<DeployContext, "component" | "env">, plan: CfnAdoptionPlan | undefined, result: CfnAdoptionOutcome): DeployAdoptionOutcome;
|
|
29
|
+
/** Run the adoption in place of the step's deploy, and report its outcome on `adoption.outcome`. Throws unless it adopted. */
|
|
30
|
+
export declare function runCfnAdoption(executor: CloudExecutor, ctx: DeployContext, input: CfnDeployInput, adoption: DeployAdoption, opts?: {
|
|
31
|
+
manifest?: ReadonlyMap<string, ImportabilityManifestEntry>;
|
|
32
|
+
waitOptions?: {
|
|
33
|
+
intervalMs?: number;
|
|
34
|
+
timeoutMs?: number;
|
|
35
|
+
};
|
|
36
|
+
}): Promise<CfnDeployOutput>;
|
|
37
|
+
//# sourceMappingURL=cfn-adopt-run.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cfn-adopt-run.d.ts","sourceRoot":"","sources":["../../src/components/cfn-adopt-run.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AAC5E,OAAO,KAAK,EAAyB,cAAc,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AACzH,OAAO,EAAoC,KAAK,cAAc,EAAE,KAAK,eAAe,EAAE,MAAM,SAAS,CAAC;AACtG,OAAO,EAAqE,KAAK,kBAAkB,EAAE,KAAK,eAAe,EAAoB,MAAM,aAAa,CAAC;AAEjK,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAEhE,iEAAiE;AACjE,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAKpF;AAED,4DAA4D;AAC5D,wBAAgB,eAAe,CAC7B,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,IAAI,CAAC,aAAa,EAAE,WAAW,GAAG,KAAK,CAAC,EAC7C,IAAI,EAAE,eAAe,GAAG,SAAS,EACjC,MAAM,EAAE,kBAAkB,GACzB,qBAAqB,CAsCvB;AAED,8HAA8H;AAC9H,wBAAsB,cAAc,CAClC,QAAQ,EAAE,aAAa,EACvB,GAAG,EAAE,aAAa,EAClB,KAAK,EAAE,cAAc,EACrB,QAAQ,EAAE,cAAc,EACxB,IAAI,GAAE;IAAE,QAAQ,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,0BAA0B,CAAC,CAAC;IAAC,WAAW,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CAAO,GACnI,OAAO,CAAC,eAAe,CAAC,CAqD1B"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { cfnChangeEntry, flattenCfnInputs } from "./apply.js";
|
|
2
|
+
import { adoptIntoStack, cfnImportReview, cfnMarkerReview, planCfnAdoption } from "./cfn-adopt.js";
|
|
3
|
+
import { readCfnTemplate } from "./cfn-imports.js";
|
|
4
|
+
/** What to do when the marker step stops after a good import. */
|
|
5
|
+
export function markerStepHint(stack, component, env) {
|
|
6
|
+
return (`The resources are imported into ${stack} and carry no chant markers yet. ` +
|
|
7
|
+
`A plain deploy of the same template writes them: chant run --components ${component} --env ${env}, without --adopt.`);
|
|
8
|
+
}
|
|
9
|
+
/** The outcome lines and status for one adoption result. */
|
|
10
|
+
export function adoptionOutcome(stack, ctx, plan, result) {
|
|
11
|
+
const member = stack;
|
|
12
|
+
switch (result.status) {
|
|
13
|
+
case "adopted":
|
|
14
|
+
return {
|
|
15
|
+
member,
|
|
16
|
+
status: "adopted",
|
|
17
|
+
lines: [
|
|
18
|
+
...(plan ? cfnImportReview(plan).map((l) => l.replace(/^import /, "imported ")) : []),
|
|
19
|
+
...(plan ? cfnMarkerReview(plan) : []),
|
|
20
|
+
...(result.markerChangeSet ? [] : ["the marker change set had nothing to write"]),
|
|
21
|
+
],
|
|
22
|
+
};
|
|
23
|
+
case "refused": {
|
|
24
|
+
const after = result.step === "markers" ? [markerStepHint(stack, ctx.component, ctx.env)] : ["Nothing was imported."];
|
|
25
|
+
return { member, status: "refused", step: result.step, lines: [...result.refusals.map((r) => `refused: ${r}`), ...after] };
|
|
26
|
+
}
|
|
27
|
+
case "declined":
|
|
28
|
+
return {
|
|
29
|
+
member,
|
|
30
|
+
status: "declined",
|
|
31
|
+
step: result.step,
|
|
32
|
+
lines: [
|
|
33
|
+
`the ${result.step === "import" ? "IMPORT" : "marker"} change set was not approved and was deleted`,
|
|
34
|
+
result.step === "markers" ? markerStepHint(stack, ctx.component, ctx.env) : "Nothing was imported.",
|
|
35
|
+
],
|
|
36
|
+
};
|
|
37
|
+
case "failed":
|
|
38
|
+
return {
|
|
39
|
+
member,
|
|
40
|
+
status: "failed",
|
|
41
|
+
step: result.step,
|
|
42
|
+
lines: [
|
|
43
|
+
`the ${result.step === "import" ? "IMPORT" : "marker"} change set executed and the stack reached ${result.stackStatus}; read the stack events for the resource that failed`,
|
|
44
|
+
...(result.step === "markers" ? [markerStepHint(stack, ctx.component, ctx.env)] : []),
|
|
45
|
+
],
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/** Run the adoption in place of the step's deploy, and report its outcome on `adoption.outcome`. Throws unless it adopted. */
|
|
50
|
+
export async function runCfnAdoption(executor, ctx, input, adoption, opts = {}) {
|
|
51
|
+
const stack = input.stack ?? ctx.component;
|
|
52
|
+
if (adoption.outcome) {
|
|
53
|
+
throw new Error(`cfn-deploy "${stack}": the adoption is already taken by ${adoption.outcome.member}; --adopt adopts into one stack, so a component with two cfn-deploy steps cannot take it`);
|
|
54
|
+
}
|
|
55
|
+
const finish = (plan, result) => {
|
|
56
|
+
adoption.outcome = adoptionOutcome(stack, ctx, plan, result);
|
|
57
|
+
return adoption.outcome;
|
|
58
|
+
};
|
|
59
|
+
const refuse = (refusals) => {
|
|
60
|
+
const outcome = finish(undefined, { status: "refused", step: "plan", refusals });
|
|
61
|
+
throw new Error(`cfn-deploy "${stack}": adoption refused: ${outcome.lines.join(" ")}`);
|
|
62
|
+
};
|
|
63
|
+
const template = readCfnTemplate(input.template);
|
|
64
|
+
if (!template || typeof template.Resources !== "object" || template.Resources === null) {
|
|
65
|
+
refuse([`the template ${input.template} cannot be read here as a CloudFormation JSON template; adoption plans from the built template`]);
|
|
66
|
+
}
|
|
67
|
+
const cfn = executor.cloudformation;
|
|
68
|
+
if (!cfn.listStackResources)
|
|
69
|
+
refuse(["this CloudFormation client cannot list the stack's resources, so it cannot tell which are already in the stack"]);
|
|
70
|
+
let existing;
|
|
71
|
+
try {
|
|
72
|
+
existing = await cfn.listStackResources(stack);
|
|
73
|
+
}
|
|
74
|
+
catch (err) {
|
|
75
|
+
return refuse([`could not list the resources of ${stack}: ${err instanceof Error ? err.message : String(err)}`]);
|
|
76
|
+
}
|
|
77
|
+
const plan = planCfnAdoption({ template: template, adoption: adoption.adoption, index: adoption.index, existing: new Set(existing), ...(opts.manifest ? { manifest: opts.manifest } : {}) });
|
|
78
|
+
if (plan.refusals.length > 0)
|
|
79
|
+
refuse(plan.refusals);
|
|
80
|
+
const parameters = flattenCfnInputs(input);
|
|
81
|
+
const result = await adoptIntoStack({
|
|
82
|
+
cfn,
|
|
83
|
+
stackName: stack,
|
|
84
|
+
plan,
|
|
85
|
+
...(parameters ? { parameters } : {}),
|
|
86
|
+
...(opts.waitOptions ? { waitOptions: opts.waitOptions } : {}),
|
|
87
|
+
review: (step, changeSet, lines) => {
|
|
88
|
+
const request = {
|
|
89
|
+
member: stack,
|
|
90
|
+
step,
|
|
91
|
+
changeSet: changeSet.changeSetName,
|
|
92
|
+
entries: changeSet.changes.map((c) => cfnChangeEntry(stack, c)),
|
|
93
|
+
lines,
|
|
94
|
+
};
|
|
95
|
+
return adoption.review(request);
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
const outcome = finish(plan, result);
|
|
99
|
+
if (result.status !== "adopted") {
|
|
100
|
+
throw new Error(`cfn-deploy "${stack}": adoption ${outcome.status}${outcome.step ? ` at the ${outcome.step} step` : ""}: ${outcome.lines.join(" ")}`);
|
|
101
|
+
}
|
|
102
|
+
const { stackStatus, outputs } = await cfn.describeStack(stack);
|
|
103
|
+
return { stackStatus, outputs };
|
|
104
|
+
}
|