@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
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Three stacks wired only by exports and imports need one approval
|
|
3
|
+
* (#4466d), as #4430 shows for parameters: the shape of
|
|
4
|
+
* `examples/demo-composed-stacks`'s `chant-compose-imports` scenario,
|
|
5
|
+
* against the mock executor. The same scenario runs on Floci in
|
|
6
|
+
* demo-composed-stacks-floci.e2e.test.ts.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
10
|
+
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
11
|
+
import { tmpdir } from "node:os";
|
|
12
|
+
import { join } from "node:path";
|
|
13
|
+
import { CapabilityRegistry } from "@intentius/chant/components/capability";
|
|
14
|
+
import type { DriverComponent } from "@intentius/chant/components/driver";
|
|
15
|
+
import { withDeclaredReads } from "@intentius/chant/components/declared-reads";
|
|
16
|
+
import { planFanOut } from "@intentius/chant/components/fan-out";
|
|
17
|
+
import { applyPrSet, planPrSet } from "@intentius/chant/components/pr-run";
|
|
18
|
+
import { createCfnDeployCapability } from "./apply";
|
|
19
|
+
import { createMockCloudExecutor, type FakeStackConfig } from "./__tests__/mock-cloud-executor";
|
|
20
|
+
|
|
21
|
+
let dir: string;
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
dir = mkdtempSync(join(tmpdir(), "cfn-imports-three-"));
|
|
24
|
+
});
|
|
25
|
+
afterEach(() => rmSync(dir, { recursive: true, force: true }));
|
|
26
|
+
|
|
27
|
+
const TEMPLATES = {
|
|
28
|
+
network: {
|
|
29
|
+
Resources: { mainVpc: { Type: "AWS::EC2::VPC" }, subnetC: { Type: "AWS::EC2::Subnet", Properties: { VpcId: { Ref: "mainVpc" }, CidrBlock: "10.0.3.0/24" } } },
|
|
30
|
+
Outputs: { SubnetCId: { Value: { Ref: "subnetC" }, Export: { Name: "chant-compose-subnet-c-id" } } },
|
|
31
|
+
},
|
|
32
|
+
app: {
|
|
33
|
+
Resources: { importsInterface: { Type: "AWS::EC2::NetworkInterface", Properties: { SubnetId: { "Fn::ImportValue": "chant-compose-subnet-c-id" } } } },
|
|
34
|
+
Outputs: { ImportsInterfaceId: { Value: { Ref: "importsInterface" }, Export: { Name: "chant-compose-imports-interface" } } },
|
|
35
|
+
},
|
|
36
|
+
edge: {
|
|
37
|
+
Resources: {
|
|
38
|
+
importsInterfaceRecord: {
|
|
39
|
+
Type: "AWS::SSM::Parameter",
|
|
40
|
+
Properties: { Name: "/chant-compose/imports-interface", Type: "String", Value: { "Fn::ImportValue": "chant-compose-imports-interface" } },
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const add = (logicalResourceId: string, resourceType: string) => ({ action: "Add" as const, logicalResourceId, resourceType, replacement: false });
|
|
47
|
+
const stacks = (): Record<string, FakeStackConfig> => ({
|
|
48
|
+
network: { outputs: { SubnetCId: "subnet-c" }, changes: [add("subnetC", "AWS::EC2::Subnet")] },
|
|
49
|
+
app: { outputs: { ImportsInterfaceId: "eni-1" }, changes: [add("importsInterface", "AWS::EC2::NetworkInterface")] },
|
|
50
|
+
edge: { changes: [add("importsInterfaceRecord", "AWS::SSM::Parameter")] },
|
|
51
|
+
});
|
|
52
|
+
const executed = (mock: ReturnType<typeof createMockCloudExecutor>) =>
|
|
53
|
+
mock.calls.filter((c) => c.method === "executeChangeSet").map((c) => (c.args as { stackName: string }).stackName);
|
|
54
|
+
|
|
55
|
+
async function planned() {
|
|
56
|
+
// No dependsOn and no inputs: the imports are the only wiring.
|
|
57
|
+
const declared: DriverComponent[] = (["edge", "app", "network"] as const).map((name) => {
|
|
58
|
+
const template = join(dir, `${name}.template.json`);
|
|
59
|
+
writeFileSync(template, JSON.stringify(TEMPLATES[name]));
|
|
60
|
+
return { name, dependsOn: [], deploy: [{ phase: "Apply", steps: [{ kind: "cfn-deploy", stack: name, template }] }] };
|
|
61
|
+
});
|
|
62
|
+
const mock = createMockCloudExecutor({ stacks: stacks() });
|
|
63
|
+
const registry = new CapabilityRegistry();
|
|
64
|
+
registry.register(createCfnDeployCapability(mock.executor));
|
|
65
|
+
const components = await withDeclaredReads(declared, registry, dir);
|
|
66
|
+
const plan = planFanOut({ components, changed: ["network", "app", "edge"] });
|
|
67
|
+
const set = await planPrSet({ components, plan, registry, env: "local" });
|
|
68
|
+
return { mock, registry, components, plan, set };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
describe("three stacks wired only by imports (#4466d)", () => {
|
|
72
|
+
it("are ordered by the imports, with each import known after apply and each importer previewed", async () => {
|
|
73
|
+
const { plan, set } = await planned();
|
|
74
|
+
expect(plan.waves).toEqual([["network"], ["app"], ["edge"]]);
|
|
75
|
+
const by = Object.fromEntries(set.members.map((m) => [m.component, m]));
|
|
76
|
+
expect(by.app!.unknownInputs).toEqual(["network.SubnetCId"]);
|
|
77
|
+
expect(by.edge!.unknownInputs).toEqual(["app.ImportsInterfaceId"]);
|
|
78
|
+
expect(set.plans.app?.app).toMatchObject({ kind: "cfn-deploy-shape" });
|
|
79
|
+
expect(set.plans.edge?.edge).toMatchObject({ kind: "cfn-deploy-shape" });
|
|
80
|
+
expect(set.doc.members.every((m) => m.holes.length === 0)).toBe(true);
|
|
81
|
+
expect(set.doc.entries.map((e) => `${e.member}/${e.address}`).sort()).toEqual(["app/importsInterface", "edge/importsInterfaceRecord", "network/subnetC"]);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("need one approval: both rounds are covered and the three stacks execute in order", async () => {
|
|
85
|
+
const { mock, registry, components, plan, set } = await planned();
|
|
86
|
+
let asked = 0;
|
|
87
|
+
const applied = await applyPrSet({
|
|
88
|
+
components,
|
|
89
|
+
plan,
|
|
90
|
+
registry,
|
|
91
|
+
env: "local",
|
|
92
|
+
set,
|
|
93
|
+
approval: { status: "approved", approvedBy: ["github:rev"] },
|
|
94
|
+
decideRound: async () => {
|
|
95
|
+
asked++;
|
|
96
|
+
return { satisfied: false, approval: { status: "pending" } };
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
expect(asked).toBe(0);
|
|
100
|
+
expect(applied.status).toBe("applied");
|
|
101
|
+
expect(executed(mock)).toEqual(["network", "app", "edge"]);
|
|
102
|
+
const rounds = applied.rounds ?? [];
|
|
103
|
+
expect(rounds.find((r) => r.components.includes("app"))?.covered?.filledInputs).toContain("network.SubnetCId");
|
|
104
|
+
// Round 2 plans app and edge, and edge waits for app; the last round with edge is the one that applies it.
|
|
105
|
+
expect([...rounds].reverse().find((r) => r.components.includes("edge"))?.covered?.filledInputs).toContain("app.ImportsInterfaceId");
|
|
106
|
+
});
|
|
107
|
+
});
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `Fn::ImportValue` between stacks (#4466a): an import of a name another
|
|
3
|
+
* `cfn-deploy` step's template exports is a read of `<component>.<output>`,
|
|
4
|
+
* which orders the importer after the exporter, lists it under
|
|
5
|
+
* `unknownInputs` and plans it as waiting on that stack. A name the plan
|
|
6
|
+
* cannot resolve is a hole that says why.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
10
|
+
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
11
|
+
import { tmpdir } from "node:os";
|
|
12
|
+
import { join } from "node:path";
|
|
13
|
+
import { CapabilityRegistry } from "@intentius/chant/components/capability";
|
|
14
|
+
import type { DriverComponent } from "@intentius/chant/components/driver";
|
|
15
|
+
import { withDeclaredReads } from "@intentius/chant/components/declared-reads";
|
|
16
|
+
import { planFanOut } from "@intentius/chant/components/fan-out";
|
|
17
|
+
import { planPrSet } from "@intentius/chant/components/pr-run";
|
|
18
|
+
import { capabilitySteps } from "@intentius/chant/components/wave-plan";
|
|
19
|
+
import { cfnDeclaredReads, cfnPlannedOutputs, createCfnDeployCapability } from "./apply";
|
|
20
|
+
import { cfnExports, cfnImportPointer, cfnImports, cfnKnownValues, cfnPseudoParameters, resolveCfnName } from "./cfn-imports";
|
|
21
|
+
import { createMockCloudExecutor } from "./__tests__/mock-cloud-executor";
|
|
22
|
+
|
|
23
|
+
let dir: string;
|
|
24
|
+
const write = (name: string, template: unknown): string => {
|
|
25
|
+
const path = join(dir, name);
|
|
26
|
+
writeFileSync(path, JSON.stringify(template));
|
|
27
|
+
return path;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
beforeEach(() => {
|
|
31
|
+
dir = mkdtempSync(join(tmpdir(), "cfn-imports-"));
|
|
32
|
+
});
|
|
33
|
+
afterEach(() => rmSync(dir, { recursive: true, force: true }));
|
|
34
|
+
|
|
35
|
+
const NETWORK = {
|
|
36
|
+
Resources: { Vpc: { Type: "AWS::EC2::VPC" } },
|
|
37
|
+
Outputs: {
|
|
38
|
+
VpcId: { Value: { Ref: "Vpc" }, Export: { Name: { "Fn::Sub": "${AWS::StackName}-VpcId" } } },
|
|
39
|
+
Internal: { Value: { Ref: "Vpc" } },
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
const APP = {
|
|
43
|
+
Parameters: { NetworkStack: { Type: "String", Default: "network" } },
|
|
44
|
+
Resources: {
|
|
45
|
+
Group: { Type: "AWS::EC2::SecurityGroup", Properties: { VpcId: { "Fn::ImportValue": { "Fn::Sub": "${NetworkStack}-VpcId" } } } },
|
|
46
|
+
},
|
|
47
|
+
Outputs: { GroupId: { Value: { Ref: "Group" }, Export: { Name: "app-GroupId" } } },
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
describe("export and import names (#4466a)", () => {
|
|
51
|
+
const known = { NetworkStack: "network", "AWS::StackName": "app" };
|
|
52
|
+
|
|
53
|
+
it("a string is itself; Fn::Sub, Ref and Fn::Join resolve from what is known", () => {
|
|
54
|
+
expect(resolveCfnName("x", known)).toEqual({ name: "x" });
|
|
55
|
+
expect(resolveCfnName({ "Fn::Sub": "${NetworkStack}-VpcId" }, known)).toEqual({ name: "network-VpcId" });
|
|
56
|
+
expect(resolveCfnName({ "Fn::Sub": ["${Prefix}-${AWS::StackName}", { Prefix: { Ref: "NetworkStack" } }] }, known)).toEqual({ name: "network-app" });
|
|
57
|
+
expect(resolveCfnName({ "Fn::Sub": "${!Literal}-x" }, known)).toEqual({ name: "${Literal}-x" });
|
|
58
|
+
expect(resolveCfnName({ Ref: "NetworkStack" }, known)).toEqual({ name: "network" });
|
|
59
|
+
expect(resolveCfnName({ "Fn::Join": ["-", [{ Ref: "NetworkStack" }, "VpcId"]] }, known)).toEqual({ name: "network-VpcId" });
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("a name that reads what the plan does not know is unresolved, and says what it reads", () => {
|
|
63
|
+
expect(resolveCfnName({ "Fn::Sub": "${Missing}-VpcId" }, known)).toEqual({ unresolved: "reads parameter Missing, which has no value the plan knows" });
|
|
64
|
+
expect(resolveCfnName({ "Fn::Sub": "${AWS::AccountId}-VpcId" }, known)).toEqual({ unresolved: "reads AWS::AccountId, which is known only at apply" });
|
|
65
|
+
expect(resolveCfnName({ "Fn::Sub": "${Vpc.Arn}" }, known)).toEqual({ unresolved: "reads Vpc.Arn, a resource attribute" });
|
|
66
|
+
expect(resolveCfnName({ "Fn::Select": [0, ["a"]] }, known)).toEqual({ unresolved: "uses Fn::Select, which this plan does not follow" });
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("the pseudo parameters: the stack name always, the region's when the environment names it", () => {
|
|
70
|
+
expect(cfnPseudoParameters("app", {})).toEqual({ "AWS::StackName": "app" });
|
|
71
|
+
expect(cfnPseudoParameters("app", { AWS_REGION: "cn-north-1" })).toEqual({
|
|
72
|
+
"AWS::StackName": "app",
|
|
73
|
+
"AWS::Region": "cn-north-1",
|
|
74
|
+
"AWS::Partition": "aws-cn",
|
|
75
|
+
"AWS::URLSuffix": "amazonaws.com.cn",
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("known values are the defaults, overlaid by plain inputs; a wired input is not known", () => {
|
|
80
|
+
const values = cfnKnownValues(APP, "app", { NetworkStack: "shared", Other: { stackOutput: { stack: "x", name: "y" } } }, {});
|
|
81
|
+
expect(values).toEqual({ NetworkStack: "shared", "AWS::StackName": "app" });
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("lists exports by output and imports by place", () => {
|
|
85
|
+
expect(cfnExports(NETWORK, cfnKnownValues(NETWORK, "network", {}, {}))).toEqual([{ output: "VpcId", name: "network-VpcId" }]);
|
|
86
|
+
expect(cfnImports(APP, cfnKnownValues(APP, "app", {}, {}))).toEqual([{ at: "Resources.Group.Properties.VpcId", logicalId: "Group", name: "network-VpcId" }]);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("an export name's pointer escapes / and ~", () => {
|
|
90
|
+
expect(cfnImportPointer("a/b~c")).toBe("/imports/a~1b~0c");
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe("cfn-deploy's declared reads (#4466a)", () => {
|
|
95
|
+
it("an import of a name another step exports is a read of that component's output", () => {
|
|
96
|
+
const network = write("network.json", NETWORK);
|
|
97
|
+
const app = write("app.json", APP);
|
|
98
|
+
const reads = cfnDeclaredReads(dir, [
|
|
99
|
+
{ component: "network", index: 0, step: { stack: "network", template: network } },
|
|
100
|
+
{ component: "app", index: 0, step: { stack: "app", template: app } },
|
|
101
|
+
]);
|
|
102
|
+
expect(reads).toEqual([{ reader: "app", index: 0, upstream: "network", output: "VpcId", at: "/imports/network-VpcId" }]);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("a relative template path is read against the root", () => {
|
|
106
|
+
write("network.json", NETWORK);
|
|
107
|
+
write("app.json", APP);
|
|
108
|
+
const reads = cfnDeclaredReads(dir, [
|
|
109
|
+
{ component: "network", index: 0, step: { template: "network.json" } },
|
|
110
|
+
{ component: "app", index: 0, step: { template: "app.json" } },
|
|
111
|
+
]);
|
|
112
|
+
expect(reads.map((r) => `${r.reader}<-${r.upstream}.${r.output}`)).toEqual(["app<-network.VpcId"]);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("no read for a name no step exports, a name two steps export, or a name the step cannot resolve", () => {
|
|
116
|
+
const network = write("network.json", NETWORK);
|
|
117
|
+
const twin = write("twin.json", NETWORK);
|
|
118
|
+
const app = write("app.json", APP);
|
|
119
|
+
// network and twin both default AWS::StackName to the same stack name: two exports of one name.
|
|
120
|
+
expect(
|
|
121
|
+
cfnDeclaredReads(dir, [
|
|
122
|
+
{ component: "network", index: 0, step: { stack: "network", template: network } },
|
|
123
|
+
{ component: "twin", index: 0, step: { stack: "network", template: twin } },
|
|
124
|
+
{ component: "app", index: 0, step: { stack: "app", template: app } },
|
|
125
|
+
]),
|
|
126
|
+
).toEqual([]);
|
|
127
|
+
expect(cfnDeclaredReads(dir, [{ component: "app", index: 0, step: { stack: "app", template: app } }])).toEqual([]);
|
|
128
|
+
const wired = write("wired.json", { ...APP, Parameters: { NetworkStack: { Type: "String" } } });
|
|
129
|
+
expect(
|
|
130
|
+
cfnDeclaredReads(dir, [
|
|
131
|
+
{ component: "network", index: 0, step: { stack: "network", template: network } },
|
|
132
|
+
{ component: "app", index: 0, step: { stack: "app", template: wired, inputs: { NetworkStack: { stackOutput: { stack: "x", name: "y" } } } } },
|
|
133
|
+
]),
|
|
134
|
+
).toEqual([]);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it("an output that passes an import through is known at the import's value", () => {
|
|
138
|
+
const template = { Outputs: { Vpc: { Value: { "Fn::ImportValue": "network-VpcId" } }, Other: { Value: { "Fn::ImportValue": "elsewhere" } } } };
|
|
139
|
+
expect(cfnPlannedOutputs(template, [], { Vpc: "old", Other: "x" }, {}, { "network-VpcId": "vpc-123" })).toEqual({ known: { Vpc: "vpc-123" }, unknown: ["Other"] });
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
describe("a pull request's plan over stacks wired only by imports (#4466a)", () => {
|
|
144
|
+
async function planned() {
|
|
145
|
+
const network = write("network.json", NETWORK);
|
|
146
|
+
const app = write("app.json", APP);
|
|
147
|
+
const declared: DriverComponent[] = [
|
|
148
|
+
{ name: "network", dependsOn: [], deploy: [{ phase: "Apply", steps: [{ kind: "cfn-deploy", stack: "network", template: network }] }] },
|
|
149
|
+
{ name: "app", dependsOn: [], deploy: [{ phase: "Apply", steps: [{ kind: "cfn-deploy", stack: "app", template: app }] }] },
|
|
150
|
+
];
|
|
151
|
+
const mock = createMockCloudExecutor({ stacks: { network: { missing: true }, app: { missing: true } } });
|
|
152
|
+
const registry = new CapabilityRegistry();
|
|
153
|
+
registry.register(createCfnDeployCapability(mock.executor));
|
|
154
|
+
const components = await withDeclaredReads(declared, registry, dir);
|
|
155
|
+
const plan = planFanOut({ components, changed: ["network", "app"] });
|
|
156
|
+
const set = await planPrSet({ components, plan, registry, env: "local" });
|
|
157
|
+
return { components, plan, set, mock };
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
it("orders the importer after the exporter and writes the read into its step", async () => {
|
|
161
|
+
const { components, plan } = await planned();
|
|
162
|
+
expect(plan.waves).toEqual([["network"], ["app"]]);
|
|
163
|
+
const app = components.find((c) => c.name === "app")!;
|
|
164
|
+
expect(app.dependsOn).toEqual(["network"]);
|
|
165
|
+
expect(capabilitySteps(app.deploy)[0]).toMatchObject({ imports: { "network-VpcId": { stackOutput: { stack: "network", name: "VpcId" } } } });
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it("lists the import under unknownInputs and reads, while network's plan cannot say the value", async () => {
|
|
169
|
+
const { set } = await planned();
|
|
170
|
+
const app = set.members.find((m) => m.component === "app")!;
|
|
171
|
+
expect(app.unknownInputs).toEqual(["network.VpcId"]);
|
|
172
|
+
expect(app.reads).toEqual([{ upstream: "network", outputs: ["VpcId"], unknown: ["VpcId"] }]);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it("an importer whose template cannot be read as JSON plans as waiting on the exporter (no preview, #4466b)", async () => {
|
|
176
|
+
const { set, components } = await planned();
|
|
177
|
+
const app = components.find((c) => c.name === "app")!;
|
|
178
|
+
const step = capabilitySteps(app.deploy)[0]! as Record<string, unknown>;
|
|
179
|
+
writeFileSync(step.template as string, "not json");
|
|
180
|
+
const mock = createMockCloudExecutor({ stacks: { app: { missing: true } } });
|
|
181
|
+
const planned2 = await createCfnDeployCapability(mock.executor).plan!(
|
|
182
|
+
{ env: "local", component: "app", unresolvedInputs: ["network"] },
|
|
183
|
+
{ stack: "app", template: step.template as string, imports: { "network-VpcId": undefined } },
|
|
184
|
+
);
|
|
185
|
+
expect(planned2.changeSet!.member.holes).toEqual([
|
|
186
|
+
{
|
|
187
|
+
address: "app",
|
|
188
|
+
type: "AWS::CloudFormation::Stack",
|
|
189
|
+
reason: "imports network-VpcId, exported by network, which apply first; re-checked on apply; no preview: the template could not be read as JSON to stand in for its imports",
|
|
190
|
+
},
|
|
191
|
+
]);
|
|
192
|
+
expect(set.doc.members.find((m) => m.member === "app")).toBeDefined();
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
describe("an import whose name the plan cannot resolve (#4466a)", () => {
|
|
197
|
+
it("is a hole on the importer's member that says what the name reads", async () => {
|
|
198
|
+
const template = write("app.json", {
|
|
199
|
+
Resources: { Group: { Type: "AWS::EC2::SecurityGroup", Properties: { VpcId: { "Fn::ImportValue": { "Fn::Sub": "${AWS::AccountId}-VpcId" } } } } },
|
|
200
|
+
});
|
|
201
|
+
const mock = createMockCloudExecutor({ stacks: { app: { changes: [{ action: "Add", logicalResourceId: "Group", resourceType: "AWS::EC2::SecurityGroup", replacement: false }] } } });
|
|
202
|
+
const planned = await createCfnDeployCapability(mock.executor).plan!({ env: "local", component: "app" }, { stack: "app", template });
|
|
203
|
+
expect(planned.changeSet!.member.holes).toEqual([
|
|
204
|
+
{
|
|
205
|
+
address: "Group",
|
|
206
|
+
type: "AWS::EC2::SecurityGroup",
|
|
207
|
+
reason:
|
|
208
|
+
"the Fn::ImportValue at Resources.Group.Properties.VpcId reads AWS::AccountId, which is known only at apply, so the plan cannot say which export it reads or whether a stack in this change exports it",
|
|
209
|
+
},
|
|
210
|
+
]);
|
|
211
|
+
expect(planned.changeSet!.entries).toHaveLength(1);
|
|
212
|
+
});
|
|
213
|
+
});
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `Fn::ImportValue` between stacks (#4466): which exports a template
|
|
3
|
+
* declares, which it imports, and the names they go by.
|
|
4
|
+
*
|
|
5
|
+
* A stack that imports another stack's export reads that stack, the way a
|
|
6
|
+
* CDK app wires its stacks. The read sits inside the template, so core does
|
|
7
|
+
* not see it in the step. `cfn-deploy`'s `declaredReads` finds it here: an
|
|
8
|
+
* import of a name another `cfn-deploy` step's template exports is a read of
|
|
9
|
+
* `<component>.<output>`, which core writes into the importer's step under
|
|
10
|
+
* `imports` (`CfnDeployInput.imports`) and orders, holds and lists like any
|
|
11
|
+
* other read.
|
|
12
|
+
*
|
|
13
|
+
* A name is a string, or an `Fn::Sub` (or `Fn::Join`, or `Ref`) over
|
|
14
|
+
* parameters and pseudo parameters. It resolves where the values it reads
|
|
15
|
+
* are known: a parameter with a plain value in the step's `inputs` or a
|
|
16
|
+
* `Default` in the template, `AWS::StackName`, and the region's pseudo
|
|
17
|
+
* parameters when `AWS_REGION` or `AWS_DEFAULT_REGION` names the region.
|
|
18
|
+
* Anything else (`AWS::AccountId`, a resource attribute, a parameter wired
|
|
19
|
+
* from another stack, an intrinsic this does not follow) leaves the name
|
|
20
|
+
* unresolved, and the plan says so in a hole.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { createHash } from "node:crypto";
|
|
24
|
+
import { readFileSync } from "node:fs";
|
|
25
|
+
import { isAbsolute, resolve } from "node:path";
|
|
26
|
+
|
|
27
|
+
/** A name an export or import goes by: resolved, or why not. */
|
|
28
|
+
export type CfnName = { name: string } | { unresolved: string };
|
|
29
|
+
|
|
30
|
+
/** One export a template declares: the output it is, and its name. */
|
|
31
|
+
export type CfnExport = { output: string } & CfnName;
|
|
32
|
+
|
|
33
|
+
/** One import in a template: where it sits, as a dotted path, the logical id it sits under, and its name. */
|
|
34
|
+
export type CfnImport = { at: string; logicalId: string } & CfnName;
|
|
35
|
+
|
|
36
|
+
/** The template at `path`, read against `root` when relative, as JSON; `undefined` for one that cannot be read or parsed, or an archive reference. */
|
|
37
|
+
export function readCfnTemplate(path: unknown, root?: string): Record<string, unknown> | undefined {
|
|
38
|
+
if (typeof path !== "string" || path.startsWith("archive:")) return undefined;
|
|
39
|
+
try {
|
|
40
|
+
const parsed = JSON.parse(readFileSync(root && !isAbsolute(path) ? resolve(root, path) : path, "utf8")) as unknown;
|
|
41
|
+
return parsed !== null && typeof parsed === "object" && !Array.isArray(parsed) ? (parsed as Record<string, unknown>) : undefined;
|
|
42
|
+
} catch {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** The region the plan runs against, when the environment names it. */
|
|
48
|
+
function regionOf(env: NodeJS.ProcessEnv): string | undefined {
|
|
49
|
+
return env.AWS_REGION || env.AWS_DEFAULT_REGION || undefined;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The pseudo parameters this plan knows for `stack`: `AWS::StackName`, and
|
|
54
|
+
* `AWS::Region`, `AWS::Partition` and `AWS::URLSuffix` when the region is
|
|
55
|
+
* named. `AWS::AccountId` and `AWS::StackId` are not known before apply.
|
|
56
|
+
*/
|
|
57
|
+
export function cfnPseudoParameters(stack: string, env: NodeJS.ProcessEnv = process.env): Record<string, string> {
|
|
58
|
+
const out: Record<string, string> = { "AWS::StackName": stack };
|
|
59
|
+
const region = regionOf(env);
|
|
60
|
+
if (region) {
|
|
61
|
+
out["AWS::Region"] = region;
|
|
62
|
+
out["AWS::Partition"] = region.startsWith("cn-") ? "aws-cn" : region.startsWith("us-gov-") ? "aws-us-gov" : "aws";
|
|
63
|
+
out["AWS::URLSuffix"] = region.startsWith("cn-") ? "amazonaws.com.cn" : "amazonaws.com";
|
|
64
|
+
}
|
|
65
|
+
return out;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The values a name in `template` can read for `stack`: each parameter's
|
|
70
|
+
* `Default`, overlaid by the step's plain inputs (a string, a number or a
|
|
71
|
+
* boolean; a wired reference or `undefined` is not known), and the pseudo
|
|
72
|
+
* parameters.
|
|
73
|
+
*/
|
|
74
|
+
export function cfnKnownValues(
|
|
75
|
+
template: Record<string, unknown> | undefined,
|
|
76
|
+
stack: string,
|
|
77
|
+
inputs: Record<string, unknown> | undefined,
|
|
78
|
+
env: NodeJS.ProcessEnv = process.env,
|
|
79
|
+
): Record<string, string> {
|
|
80
|
+
const out: Record<string, string> = {};
|
|
81
|
+
const plain = (v: unknown): string | undefined =>
|
|
82
|
+
typeof v === "string" ? v : typeof v === "number" || typeof v === "boolean" ? String(v) : undefined;
|
|
83
|
+
const params = (template?.Parameters ?? {}) as Record<string, { Default?: unknown } | undefined>;
|
|
84
|
+
for (const [k, p] of Object.entries(params)) {
|
|
85
|
+
const d = plain(p?.Default);
|
|
86
|
+
if (d !== undefined) out[k] = d;
|
|
87
|
+
}
|
|
88
|
+
for (const [k, v] of Object.entries(inputs ?? {})) {
|
|
89
|
+
const s = plain(v);
|
|
90
|
+
if (s !== undefined) out[k] = s;
|
|
91
|
+
}
|
|
92
|
+
return { ...out, ...cfnPseudoParameters(stack, env) };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Why a variable a name reads has no value here. */
|
|
96
|
+
function unknownVariable(v: string, known: Record<string, string>): string | undefined {
|
|
97
|
+
if (v in known) return undefined;
|
|
98
|
+
if (v.includes(".")) return `reads ${v}, a resource attribute`;
|
|
99
|
+
if (v.startsWith("AWS::")) return `reads ${v}, which is known only at apply`;
|
|
100
|
+
return `reads parameter ${v}, which has no value the plan knows`;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* The name `value` resolves to against `known`, or why it does not. A
|
|
105
|
+
* string is itself; `Fn::Sub` substitutes `${X}` from `known` and its own
|
|
106
|
+
* variables (`${!X}` is the literal `${X}`); `Ref` reads `known`;
|
|
107
|
+
* `Fn::Join` joins what it resolves. Any other shape is unresolved.
|
|
108
|
+
*/
|
|
109
|
+
export function resolveCfnName(value: unknown, known: Record<string, string>): CfnName {
|
|
110
|
+
if (typeof value === "string") return { name: value };
|
|
111
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) return { unresolved: "is not a string or an intrinsic" };
|
|
112
|
+
const entries = Object.entries(value as Record<string, unknown>);
|
|
113
|
+
if (entries.length !== 1) return { unresolved: "is not a string or an intrinsic" };
|
|
114
|
+
const [key, arg] = entries[0]!;
|
|
115
|
+
if (key === "Ref") {
|
|
116
|
+
if (typeof arg !== "string") return { unresolved: "is a Ref without a name" };
|
|
117
|
+
const why = unknownVariable(arg, known);
|
|
118
|
+
return why ? { unresolved: why } : { name: known[arg]! };
|
|
119
|
+
}
|
|
120
|
+
if (key === "Fn::Sub") {
|
|
121
|
+
const text = typeof arg === "string" ? arg : Array.isArray(arg) && typeof arg[0] === "string" ? arg[0] : undefined;
|
|
122
|
+
if (text === undefined) return { unresolved: "is an Fn::Sub this plan cannot read" };
|
|
123
|
+
const vars: Record<string, string> = { ...known };
|
|
124
|
+
if (Array.isArray(arg) && arg[1] && typeof arg[1] === "object") {
|
|
125
|
+
for (const [k, v] of Object.entries(arg[1] as Record<string, unknown>)) {
|
|
126
|
+
const r = resolveCfnName(v, known);
|
|
127
|
+
if ("unresolved" in r) return { unresolved: `its Fn::Sub variable ${k} ${r.unresolved}` };
|
|
128
|
+
vars[k] = r.name;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
let why: string | undefined;
|
|
132
|
+
const name = text.replace(/\$\{(!?)([^}]*)\}/g, (whole, bang: string, v: string) => {
|
|
133
|
+
if (bang) return "${" + v + "}";
|
|
134
|
+
const w = unknownVariable(v, vars);
|
|
135
|
+
if (w) {
|
|
136
|
+
why ??= w;
|
|
137
|
+
return whole;
|
|
138
|
+
}
|
|
139
|
+
return vars[v]!;
|
|
140
|
+
});
|
|
141
|
+
return why ? { unresolved: why } : { name };
|
|
142
|
+
}
|
|
143
|
+
if (key === "Fn::Join") {
|
|
144
|
+
if (!Array.isArray(arg) || typeof arg[0] !== "string" || !Array.isArray(arg[1])) return { unresolved: "is an Fn::Join this plan cannot read" };
|
|
145
|
+
const parts: string[] = [];
|
|
146
|
+
for (const part of arg[1] as unknown[]) {
|
|
147
|
+
const r = resolveCfnName(part, known);
|
|
148
|
+
if ("unresolved" in r) return r;
|
|
149
|
+
parts.push(r.name);
|
|
150
|
+
}
|
|
151
|
+
return { name: parts.join(arg[0]) };
|
|
152
|
+
}
|
|
153
|
+
return { unresolved: `uses ${key}, which this plan does not follow` };
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** Every export `template` declares (`Outputs.<name>.Export.Name`), by output, sorted. */
|
|
157
|
+
export function cfnExports(template: Record<string, unknown> | undefined, known: Record<string, string>): CfnExport[] {
|
|
158
|
+
const outputs = (template?.Outputs ?? {}) as Record<string, { Export?: { Name?: unknown } } | undefined>;
|
|
159
|
+
const out: CfnExport[] = [];
|
|
160
|
+
for (const [output, o] of Object.entries(outputs).sort(([a], [b]) => a.localeCompare(b))) {
|
|
161
|
+
if (o?.Export === undefined) continue;
|
|
162
|
+
out.push({ output, ...resolveCfnName(o.Export.Name, known) });
|
|
163
|
+
}
|
|
164
|
+
return out;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Every `Fn::ImportValue` in `template`'s resources, outputs and conditions,
|
|
169
|
+
* with where it sits and the name it imports, in template order. An import
|
|
170
|
+
* whose argument is itself an import is listed once, unresolved.
|
|
171
|
+
*/
|
|
172
|
+
export function cfnImports(template: Record<string, unknown> | undefined, known: Record<string, string>): CfnImport[] {
|
|
173
|
+
const out: CfnImport[] = [];
|
|
174
|
+
const walk = (v: unknown, path: string, logicalId: string): void => {
|
|
175
|
+
if (Array.isArray(v)) return v.forEach((x, i) => walk(x, `${path}.${i}`, logicalId));
|
|
176
|
+
if (v === null || typeof v !== "object") return;
|
|
177
|
+
for (const [k, x] of Object.entries(v as Record<string, unknown>)) {
|
|
178
|
+
if (k === "Fn::ImportValue") {
|
|
179
|
+
out.push({ at: path, logicalId, ...resolveCfnName(x, known) });
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
walk(x, `${path}.${k}`, logicalId);
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
for (const section of ["Resources", "Outputs", "Conditions"] as const) {
|
|
186
|
+
const s = template?.[section];
|
|
187
|
+
if (s === null || typeof s !== "object") continue;
|
|
188
|
+
for (const [id, body] of Object.entries(s as Record<string, unknown>)) walk(body, `${section}.${id}`, id);
|
|
189
|
+
}
|
|
190
|
+
return out;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** The JSON Pointer `CfnDeployInput.imports[name]` sits at in a `cfn-deploy` step. */
|
|
194
|
+
export function cfnImportPointer(name: string): string {
|
|
195
|
+
return "/imports/" + name.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** The stand-in parameter that takes an import's place in a preview: `ChantImport`, the name's letters and digits, and a short digest so two names never share one. */
|
|
199
|
+
export function cfnStandInParameter(name: string): string {
|
|
200
|
+
return `ChantImport${name.replace(/[^A-Za-z0-9]/g, "").slice(0, 200)}${createHash("sha256").update(name).digest("hex").slice(0, 8)}`;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* A copy of `template` for a preview (#4466b): each `Fn::ImportValue` of a
|
|
205
|
+
* name in `names` is a `Ref` to a stand-in `String` parameter, which the
|
|
206
|
+
* preview fills with `cfnPlaceholder`. CloudFormation refuses a change set
|
|
207
|
+
* that imports an export that does not exist yet, so the importer of a stack
|
|
208
|
+
* the same change creates is planned against this copy. `standIns` maps each
|
|
209
|
+
* stand-in parameter to the export it stands for; a name the template never
|
|
210
|
+
* imports gets none.
|
|
211
|
+
*/
|
|
212
|
+
export function cfnTemplateWithStandIns(
|
|
213
|
+
template: Record<string, unknown>,
|
|
214
|
+
names: readonly string[],
|
|
215
|
+
known: Record<string, string>,
|
|
216
|
+
): { template: Record<string, unknown>; standIns: Record<string, string> } {
|
|
217
|
+
const wanted = new Set(names);
|
|
218
|
+
const standIns: Record<string, string> = {};
|
|
219
|
+
const swap = (v: unknown): unknown => {
|
|
220
|
+
if (Array.isArray(v)) return v.map(swap);
|
|
221
|
+
if (v === null || typeof v !== "object") return v;
|
|
222
|
+
const entries = Object.entries(v as Record<string, unknown>);
|
|
223
|
+
if (entries.length === 1 && entries[0]![0] === "Fn::ImportValue") {
|
|
224
|
+
const r = resolveCfnName(entries[0]![1], known);
|
|
225
|
+
if ("name" in r && wanted.has(r.name)) {
|
|
226
|
+
const param = cfnStandInParameter(r.name);
|
|
227
|
+
standIns[param] = r.name;
|
|
228
|
+
return { Ref: param };
|
|
229
|
+
}
|
|
230
|
+
return v;
|
|
231
|
+
}
|
|
232
|
+
return Object.fromEntries(entries.map(([k, x]) => [k, swap(x)]));
|
|
233
|
+
};
|
|
234
|
+
const out: Record<string, unknown> = { ...template };
|
|
235
|
+
for (const section of ["Resources", "Outputs", "Conditions"] as const) {
|
|
236
|
+
if (template[section] !== undefined) out[section] = swap(template[section]);
|
|
237
|
+
}
|
|
238
|
+
if (Object.keys(standIns).length > 0) {
|
|
239
|
+
const params = { ...((template.Parameters ?? {}) as Record<string, unknown>) };
|
|
240
|
+
for (const [param, name] of Object.entries(standIns).sort(([a], [b]) => a.localeCompare(b))) {
|
|
241
|
+
params[param] = { Type: "String", Description: `chant preview: stands in for Fn::ImportValue ${name}, known after its stack applies` };
|
|
242
|
+
}
|
|
243
|
+
out.Parameters = params;
|
|
244
|
+
}
|
|
245
|
+
return { template: out, standIns };
|
|
246
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `cfn-deploy`'s plan shapes pass core's plan shape conformance (#4425):
|
|
3
|
+
* the preview with a stand-in parameter, the real change set planned after
|
|
4
|
+
* the upstream applied, and real change sets that add, drop or replace a
|
|
5
|
+
* resource, all made by `plan` against the mock executor.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
9
|
+
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
10
|
+
import { tmpdir } from "node:os";
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
import { checkPlanShapeConformance } from "@intentius/chant/components";
|
|
13
|
+
import type { CfnChange } from "./cloud-executor";
|
|
14
|
+
import { createCfnDeployCapability } from "./apply";
|
|
15
|
+
import { createMockCloudExecutor } from "./__tests__/mock-cloud-executor";
|
|
16
|
+
|
|
17
|
+
let dir: string;
|
|
18
|
+
let template: string;
|
|
19
|
+
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
dir = mkdtempSync(join(tmpdir(), "cfn-shape-conformance-"));
|
|
22
|
+
template = join(dir, "stack.template.json");
|
|
23
|
+
writeFileSync(
|
|
24
|
+
template,
|
|
25
|
+
JSON.stringify({
|
|
26
|
+
Parameters: { SubnetId: { Type: "AWS::EC2::Subnet::Id" } },
|
|
27
|
+
Resources: {
|
|
28
|
+
Eni: { Type: "AWS::EC2::NetworkInterface", Properties: { SubnetId: { Ref: "SubnetId" }, Description: "d" } },
|
|
29
|
+
Q: { Type: "AWS::SQS::Queue", Properties: { QueueName: { "Fn::Sub": "q-${SubnetId}" } } },
|
|
30
|
+
},
|
|
31
|
+
}),
|
|
32
|
+
);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
afterEach(() => rmSync(dir, { recursive: true, force: true }));
|
|
36
|
+
|
|
37
|
+
const ctx = { env: "local", component: "network" };
|
|
38
|
+
|
|
39
|
+
const eni: CfnChange = {
|
|
40
|
+
action: "Modify",
|
|
41
|
+
logicalResourceId: "Eni",
|
|
42
|
+
resourceType: "AWS::EC2::NetworkInterface",
|
|
43
|
+
replacement: false,
|
|
44
|
+
replacementMode: "False",
|
|
45
|
+
details: ["SubnetId", "Description"],
|
|
46
|
+
drivers: [
|
|
47
|
+
{ property: "SubnetId", changeSource: "ParameterReference", causingEntity: "SubnetId" },
|
|
48
|
+
{ property: "Description", changeSource: "DirectModification" },
|
|
49
|
+
],
|
|
50
|
+
};
|
|
51
|
+
const q: CfnChange = { action: "Add", logicalResourceId: "Q", resourceType: "AWS::SQS::Queue", replacement: false };
|
|
52
|
+
const topic: CfnChange = { action: "Add", logicalResourceId: "Topic", resourceType: "AWS::SNS::Topic", replacement: false };
|
|
53
|
+
|
|
54
|
+
/** The member previewed: `SubnetId` holds nothing yet, so the plan uses a stand-in. */
|
|
55
|
+
async function preview() {
|
|
56
|
+
const mock = createMockCloudExecutor({ stacks: { net: { changes: [eni, q] } } });
|
|
57
|
+
const planned = await createCfnDeployCapability(mock.executor).plan!(
|
|
58
|
+
{ ...ctx, unresolvedInputs: ["vpc.SubnetId"] },
|
|
59
|
+
{ stack: "net", template, inputs: { SubnetId: undefined as never } },
|
|
60
|
+
);
|
|
61
|
+
return planned.shape;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** The member planned again once the upstream applied, with the real change set `changes`. */
|
|
65
|
+
async function real(changes: CfnChange[]) {
|
|
66
|
+
const mock = createMockCloudExecutor({ stacks: { net: { changes } } });
|
|
67
|
+
const planned = await createCfnDeployCapability(mock.executor).plan!(ctx, { stack: "net", template, inputs: { SubnetId: "subnet-1" }, onReplace: "allow" });
|
|
68
|
+
return planned.shape;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
describe("cfn-deploy plan shape conformance (#4425)", () => {
|
|
72
|
+
it("passes", async () => {
|
|
73
|
+
const problems = await checkPlanShapeConformance({
|
|
74
|
+
lexicon: "aws",
|
|
75
|
+
preview,
|
|
76
|
+
fresh: () => real([eni, q]),
|
|
77
|
+
added: () => real([eni, q, topic]),
|
|
78
|
+
missing: () => real([q]),
|
|
79
|
+
replaced: () => real([{ ...eni, replacement: true, replacementMode: "True" }, q]),
|
|
80
|
+
});
|
|
81
|
+
expect(problems).toEqual([]);
|
|
82
|
+
});
|
|
83
|
+
});
|