@intentius/chant-lexicon-terraform 0.124.51 → 0.124.54
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 +7 -6
- package/dist/__fixtures__/pr-loop/estate.component.d.ts +7 -0
- package/dist/__fixtures__/pr-loop/estate.component.d.ts.map +1 -0
- package/dist/__fixtures__/pr-loop/estate.component.js +7 -0
- package/dist/__fixtures__/report/generate.d.ts +26 -0
- package/dist/__fixtures__/report/generate.d.ts.map +1 -0
- package/dist/__fixtures__/report/generate.js +58 -0
- package/dist/applied-state.d.ts +27 -0
- package/dist/applied-state.d.ts.map +1 -0
- package/dist/applied-state.js +44 -0
- package/dist/backend-config.d.ts +53 -0
- package/dist/backend-config.d.ts.map +1 -0
- package/dist/backend-config.js +136 -0
- package/dist/behaviour/kinds.d.ts.map +1 -1
- package/dist/behaviour/kinds.js +4 -0
- package/dist/behaviour/predict.d.ts.map +1 -1
- package/dist/behaviour/predict.js +6 -2
- package/dist/behaviour/reference-catalog.d.ts +16 -5
- package/dist/behaviour/reference-catalog.d.ts.map +1 -1
- package/dist/behaviour/reference-catalog.js +16 -5
- package/dist/behaviour/request.d.ts.map +1 -1
- package/dist/behaviour/request.js +3 -2
- package/dist/changed-roots.d.ts +6 -4
- package/dist/changed-roots.d.ts.map +1 -1
- package/dist/changed-roots.js +14 -18
- package/dist/commands.d.ts +5 -0
- package/dist/commands.d.ts.map +1 -1
- package/dist/commands.js +87 -4
- package/dist/components/capability-plugin.d.ts +65 -3
- package/dist/components/capability-plugin.d.ts.map +1 -1
- package/dist/components/capability-plugin.js +197 -13
- package/dist/components/compose-group.d.ts +145 -0
- package/dist/components/compose-group.d.ts.map +1 -0
- package/dist/components/compose-group.js +407 -0
- package/dist/components/placeholder-preview.d.ts +78 -0
- package/dist/components/placeholder-preview.d.ts.map +1 -0
- package/dist/components/placeholder-preview.js +254 -0
- package/dist/compose/apply-events.d.ts +46 -0
- package/dist/compose/apply-events.d.ts.map +1 -0
- package/dist/compose/apply-events.js +77 -0
- package/dist/compose/estate.d.ts +194 -0
- package/dist/compose/estate.d.ts.map +1 -0
- package/dist/compose/estate.js +363 -0
- package/dist/compose/hcl.d.ts +99 -0
- package/dist/compose/hcl.d.ts.map +1 -0
- package/dist/compose/hcl.js +302 -0
- package/dist/compose/module-address.d.ts +24 -0
- package/dist/compose/module-address.d.ts.map +1 -0
- package/dist/compose/module-address.js +43 -0
- package/dist/compose/root.d.ts +127 -0
- package/dist/compose/root.d.ts.map +1 -0
- package/dist/compose/root.js +586 -0
- package/dist/compose/run.d.ts +183 -0
- package/dist/compose/run.d.ts.map +1 -0
- package/dist/compose/run.js +447 -0
- package/dist/compose/slice.d.ts +102 -0
- package/dist/compose/slice.d.ts.map +1 -0
- package/dist/compose/slice.js +249 -0
- package/dist/compose/state-address.d.ts +28 -0
- package/dist/compose/state-address.d.ts.map +1 -0
- package/dist/compose/state-address.js +154 -0
- package/dist/compose/state-merge.d.ts +52 -0
- package/dist/compose/state-merge.d.ts.map +1 -0
- package/dist/compose/state-merge.js +135 -0
- package/dist/compose.d.ts +179 -0
- package/dist/compose.d.ts.map +1 -0
- package/dist/compose.js +482 -0
- package/dist/composites/terraform-apply-op.d.ts.map +1 -1
- package/dist/composites/terraform-apply-op.js +7 -3
- package/dist/config.d.ts +59 -13
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +43 -9
- package/dist/describe-resources.d.ts +74 -12
- package/dist/describe-resources.d.ts.map +1 -1
- package/dist/describe-resources.js +374 -66
- package/dist/drift-read.d.ts +33 -0
- package/dist/drift-read.d.ts.map +1 -0
- package/dist/drift-read.js +243 -0
- package/dist/drift-record.d.ts +147 -0
- package/dist/drift-record.d.ts.map +1 -0
- package/dist/drift-record.js +383 -0
- package/dist/hcl/edges.d.ts.map +1 -1
- package/dist/hcl/edges.js +24 -1
- package/dist/hcl/files.d.ts +61 -0
- package/dist/hcl/files.d.ts.map +1 -0
- package/dist/hcl/files.js +221 -0
- package/dist/hcl/instances.d.ts +82 -0
- package/dist/hcl/instances.d.ts.map +1 -0
- package/dist/hcl/instances.js +390 -0
- package/dist/hcl/parse.d.ts +81 -9
- package/dist/hcl/parse.d.ts.map +1 -1
- package/dist/hcl/parse.js +114 -16
- package/dist/hcl/roots.d.ts.map +1 -1
- package/dist/hcl/roots.js +5 -0
- package/dist/hcl/suppressions.d.ts.map +1 -1
- package/dist/hcl/suppressions.js +8 -2
- package/dist/index.d.ts +11 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -2
- package/dist/integrity.json +3 -3
- package/dist/live-plan-reasons.d.ts +21 -0
- package/dist/live-plan-reasons.d.ts.map +1 -0
- package/dist/live-plan-reasons.js +47 -0
- package/dist/lsp/option-keys.d.ts.map +1 -1
- package/dist/lsp/option-keys.js +2 -0
- package/dist/manifest.json +1 -1
- package/dist/op/activities/index.d.ts +6 -2
- package/dist/op/activities/index.d.ts.map +1 -1
- package/dist/op/activities/index.js +5 -1
- package/dist/op/activities/live-detect.d.ts +4 -3
- package/dist/op/activities/live-detect.d.ts.map +1 -1
- package/dist/op/activities/live-detect.js +57 -32
- package/dist/op/activities/pin-rollout.d.ts +2 -0
- package/dist/op/activities/pin-rollout.d.ts.map +1 -1
- package/dist/op/activities/pin-rollout.js +1 -0
- package/dist/op/activities/terraform.d.ts +153 -5
- package/dist/op/activities/terraform.d.ts.map +1 -1
- package/dist/op/activities/terraform.js +205 -20
- package/dist/op/activity-contracts.d.ts +27 -0
- package/dist/op/activity-contracts.d.ts.map +1 -1
- package/dist/op/activity-contracts.js +19 -1
- package/dist/op/builders.d.ts +7 -1
- package/dist/op/builders.d.ts.map +1 -1
- package/dist/op/builders.js +9 -0
- package/dist/pin/edit.d.ts.map +1 -1
- package/dist/pin/edit.js +35 -0
- package/dist/pin/rollout.d.ts +2 -0
- package/dist/pin/rollout.d.ts.map +1 -1
- package/dist/pin/rollout.js +14 -11
- package/dist/plan-shape.d.ts +30 -0
- package/dist/plan-shape.d.ts.map +1 -0
- package/dist/plan-shape.js +125 -0
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +32 -18
- package/dist/report.d.ts +216 -0
- package/dist/report.d.ts.map +1 -0
- package/dist/report.js +666 -0
- package/dist/skills/chant-terraform.md +1 -1
- package/dist/state/azure-blob.d.ts +68 -0
- package/dist/state/azure-blob.d.ts.map +1 -0
- package/dist/state/azure-blob.js +201 -0
- package/dist/state/backend.d.ts +158 -0
- package/dist/state/backend.d.ts.map +1 -0
- package/dist/state/backend.js +406 -0
- package/dist/state/exec.d.ts +39 -0
- package/dist/state/exec.d.ts.map +1 -0
- package/dist/state/exec.js +80 -0
- package/dist/state/gcs.d.ts +62 -0
- package/dist/state/gcs.d.ts.map +1 -0
- package/dist/state/gcs.js +224 -0
- package/dist/state/index.d.ts +15 -0
- package/dist/state/index.d.ts.map +1 -0
- package/dist/state/index.js +14 -0
- package/dist/state/locks.d.ts +105 -0
- package/dist/state/locks.d.ts.map +1 -0
- package/dist/state/locks.js +130 -0
- package/dist/state/object-store.d.ts +37 -0
- package/dist/state/object-store.d.ts.map +1 -0
- package/dist/state/object-store.js +20 -0
- package/dist/state/root-states.d.ts +131 -0
- package/dist/state/root-states.d.ts.map +1 -0
- package/dist/state/root-states.js +241 -0
- package/dist/state/s3.d.ts +68 -0
- package/dist/state/s3.d.ts.map +1 -0
- package/dist/state/s3.js +170 -0
- package/dist/state/store.d.ts +51 -0
- package/dist/state/store.d.ts.map +1 -0
- package/dist/state/store.js +185 -0
- package/dist/terragrunt/affected.d.ts.map +1 -1
- package/dist/terragrunt/affected.js +2 -1
- package/package.json +7 -3
- package/src/__fixtures__/ACCEPTANCE.md +69 -7
- package/src/__fixtures__/compose/apply-failed-in-app.jsonl +12 -0
- package/src/__fixtures__/compose/state-app.json +66 -0
- package/src/__fixtures__/compose/state-edge.json +40 -0
- package/src/__fixtures__/compose/state-net.json +58 -0
- package/src/__fixtures__/compose/three-app.plan.json +184 -0
- package/src/__fixtures__/compose/three-composed.plan.json +509 -0
- package/src/__fixtures__/compose/three-edge.plan.json +144 -0
- package/src/__fixtures__/compose/three-net.plan.json +174 -0
- package/src/__fixtures__/compose/unknown-composed.plan.json +228 -0
- package/src/__fixtures__/compose/working-after-apply.json +145 -0
- package/src/__fixtures__/config-blocks/app/main.tf +61 -0
- package/src/__fixtures__/config-blocks/app/modules/network/main.tf +4 -0
- package/src/__fixtures__/config-blocks/app-json/main.tf.json +39 -0
- package/src/__fixtures__/config-files/shadow/main.tf +3 -0
- package/src/__fixtures__/config-files/shadow/main.tofu +3 -0
- package/src/__fixtures__/config-files/shadow/other.tf +3 -0
- package/src/__fixtures__/config-files/tf/main.tf +11 -0
- package/src/__fixtures__/config-files/tf-json/main.tf.json +18 -0
- package/src/__fixtures__/config-files/tofu/main.tofu +11 -0
- package/src/__fixtures__/config-files/tofu-json/main.tofu.json +18 -0
- package/src/__fixtures__/config-files/tofu-only/main.tofu +3 -0
- package/src/__fixtures__/drift-record/README.md +11 -0
- package/src/__fixtures__/drift-record/live-plan-sections.json +27 -0
- package/src/__fixtures__/instance-forms/app/main.tf +110 -0
- package/src/__fixtures__/instance-forms/app/modules/svc/main.tf +3 -0
- package/src/__fixtures__/instance-vars/app/main.tf +52 -0
- package/src/__fixtures__/instance-vars/app/modules/app/main.tf +12 -0
- package/src/__fixtures__/instance-vars/app/modules/edge/main.tf +3 -0
- package/src/__fixtures__/instance-vars/app/terraform.tfvars +1 -0
- package/src/__fixtures__/live-module-keyed/live-graph.json +259 -0
- package/src/__fixtures__/live-module-keyed/live-plan.json +87 -0
- package/src/__fixtures__/live-module-keyed/root/estate.chdf.hcl +1 -0
- package/src/__fixtures__/live-module-keyed/root/main.tf +21 -0
- package/src/__fixtures__/live-module-keyed/root/modules/app/main.tf +17 -0
- package/src/__fixtures__/live-module-keyed/root/modules/edge/main.tf +7 -0
- package/src/__fixtures__/live-module-keyed/root/versions.tf +30 -0
- package/src/__fixtures__/live-module-keyed/show-state.json +146 -0
- package/src/__fixtures__/pr-loop/README.md +50 -0
- package/src/__fixtures__/pr-loop/chant.config.json +13 -0
- package/src/__fixtures__/pr-loop/estate.component.ts +10 -0
- package/src/__fixtures__/pr-loop/roots/a/main.tf +11 -0
- package/src/__fixtures__/pr-loop/roots/app/main.tf +19 -0
- package/src/__fixtures__/pr-loop/roots/b/main.tf +7 -0
- package/src/__fixtures__/pr-loop/roots/dns/main.tf +3 -0
- package/src/__fixtures__/pr-loop/roots/net/main.tf +7 -0
- package/src/__fixtures__/report/applied.show.json +51 -0
- package/src/__fixtures__/report/generate.ts +63 -0
- package/src/__fixtures__/report/plan.show.json +200 -0
- package/src/__fixtures__/report/tf-apply/change-set.json +170 -0
- package/src/__fixtures__/report/tf-apply/report.json +338 -0
- package/src/__fixtures__/report/tf-plan/change-set.json +170 -0
- package/src/__fixtures__/report/tf-plan/report.json +320 -0
- package/src/__fixtures__/three-cloud-azure.graph.json +290 -0
- package/src/applied-state.ts +52 -0
- package/src/backend-config.test.ts +105 -0
- package/src/backend-config.ts +133 -0
- package/src/behaviour/kinds.ts +4 -0
- package/src/behaviour/predict.ts +5 -2
- package/src/behaviour/reference-catalog.plugin.test.ts +65 -0
- package/src/behaviour/reference-catalog.ts +16 -5
- package/src/behaviour/request.ts +3 -2
- package/src/change-set-instances.test.ts +98 -0
- package/src/changed-roots.ts +14 -16
- package/src/commands.ts +84 -4
- package/src/components/capability-plugin.test.ts +172 -5
- package/src/components/capability-plugin.ts +212 -11
- package/src/components/change-set-graph.e2e.test.ts +11 -5
- package/src/components/compose-group.test.ts +486 -0
- package/src/components/compose-group.ts +489 -0
- package/src/components/demo-composed-roots.e2e.test.ts +440 -0
- package/src/components/member-outputs.test.ts +76 -0
- package/src/components/placeholder-preview.test.ts +147 -0
- package/src/components/placeholder-preview.ts +257 -0
- package/src/components/pr-loop-compose.tofu.e2e.test.ts +363 -0
- package/src/components/pr-loop.tofu.test.ts +112 -56
- package/src/compose/apply-events.test.ts +62 -0
- package/src/compose/apply-events.ts +100 -0
- package/src/compose/estate.choudoufu.e2e.test.ts +112 -0
- package/src/compose/estate.test.ts +421 -0
- package/src/compose/estate.ts +443 -0
- package/src/compose/hcl.ts +311 -0
- package/src/compose/module-address.ts +49 -0
- package/src/compose/root.test.ts +416 -0
- package/src/compose/root.ts +592 -0
- package/src/compose/run.test.ts +440 -0
- package/src/compose/run.tofu.test.ts +176 -0
- package/src/compose/run.ts +527 -0
- package/src/compose/slice.test.ts +184 -0
- package/src/compose/slice.ts +290 -0
- package/src/compose/state-address.ts +157 -0
- package/src/compose/state-merge.test.ts +131 -0
- package/src/compose/state-merge.ts +148 -0
- package/src/compose.test.ts +248 -0
- package/src/compose.ts +627 -0
- package/src/composites/terraform-apply-op.test.ts +9 -0
- package/src/composites/terraform-apply-op.ts +7 -3
- package/src/composites/terraform-pin-rollout-op.test.ts +2 -2
- package/src/config-file-listers.test.ts +265 -0
- package/src/config.ts +44 -9
- package/src/describe-resources.engine-facts.test.ts +412 -0
- package/src/describe-resources.live-module-keyed.test.ts +290 -0
- package/src/describe-resources.ts +416 -70
- package/src/drift-read.ts +284 -0
- package/src/drift-record.test.ts +223 -0
- package/src/drift-record.ts +455 -0
- package/src/hcl/config-blocks.test.ts +174 -0
- package/src/hcl/edges.ts +21 -1
- package/src/hcl/files.ts +234 -0
- package/src/hcl/instance-forms.test.ts +94 -0
- package/src/hcl/instances.test.ts +137 -0
- package/src/hcl/instances.ts +422 -0
- package/src/hcl/parse.test.ts +139 -1
- package/src/hcl/parse.ts +149 -16
- package/src/hcl/roots.ts +6 -0
- package/src/hcl/suppressions.ts +8 -2
- package/src/index.ts +76 -0
- package/src/live-plan-reasons.ts +54 -0
- package/src/lsp/completions.test.ts +1 -1
- package/src/lsp/option-keys.ts +2 -0
- package/src/op/activities/choudoufu-plan-set-op.test.ts +111 -0
- package/src/op/activities/index.ts +9 -0
- package/src/op/activities/live-detect.ts +55 -26
- package/src/op/activities/pin-rollout.ts +3 -0
- package/src/op/activities/registry.test.ts +2 -1
- package/src/op/activities/terraform.test.ts +55 -0
- package/src/op/activities/terraform.ts +266 -22
- package/src/op/activity-contracts.test.ts +1 -0
- package/src/op/activity-contracts.ts +24 -1
- package/src/op/builders.ts +14 -0
- package/src/pin/bundle.test.ts +2 -0
- package/src/pin/edit.ts +30 -0
- package/src/pin/rollout.ts +16 -11
- package/src/plan-shape.test.ts +148 -0
- package/src/plan-shape.ts +128 -0
- package/src/plugin.ts +33 -19
- package/src/report.test.ts +423 -0
- package/src/report.ts +752 -0
- package/src/signal-only-root.test.ts +72 -0
- package/src/skills/chant-terraform.md +1 -1
- package/src/state/azure-blob.ts +223 -0
- package/src/state/backend-verdict.test.ts +187 -0
- package/src/state/backend.test.ts +127 -0
- package/src/state/backend.ts +488 -0
- package/src/state/exec.ts +111 -0
- package/src/state/gcs.ts +254 -0
- package/src/state/index.ts +15 -0
- package/src/state/locks.test.ts +84 -0
- package/src/state/locks.ts +201 -0
- package/src/state/object-store.ts +35 -0
- package/src/state/root-states-floci.e2e.test.ts +66 -0
- package/src/state/root-states.test.ts +462 -0
- package/src/state/root-states.ts +309 -0
- package/src/state/s3.ts +193 -0
- package/src/state/store.ts +225 -0
- package/src/terragrunt/affected.ts +2 -1
- package/src/workspace-kinds.test.ts +4 -17
- package/workspace-kinds.json +1 -24
- package/dist/workspace-member.d.ts +0 -30
- package/dist/workspace-member.d.ts.map +0 -1
- package/dist/workspace-member.js +0 -91
- package/schemas/pulumi.schema.json +0 -34
- package/src/testdata/pulumi-member/Pulumi.yaml +0 -2
- package/src/testdata/pulumi-member/stack-export.json +0 -53
- package/src/testdata/pulumi-unexported/Pulumi.yaml +0 -2
- package/src/workspace-member.test.ts +0 -89
- package/src/workspace-member.ts +0 -126
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `chant terraform report`, against a hand-built composed plan in the shape of
|
|
3
|
+
* choudoufu's `show -json`: three module calls (network, app, edge), a subnet
|
|
4
|
+
* whose id the plan cannot know, a security group placed in it, an in-place
|
|
5
|
+
* update, and a sensitive value. The post-apply plan carries the state.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { mkdirSync, mkdtempSync, readFileSync, writeFileSync } from "node:fs";
|
|
9
|
+
import { tmpdir } from "node:os";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
import { contract } from "../../../packages/core/src/workspace/__fixtures__/contract-repo";
|
|
12
|
+
import { describe, expect, test } from "vitest";
|
|
13
|
+
import { verifyChangeSetDigest } from "@intentius/chant/change-set";
|
|
14
|
+
import { addToIndex, atmosOutputReads, atmosStackReads, dirStore, estateOfDir, httpStore, moduleEstates, runFactsFromEnv, slicePlan, terraformReport, topModule, writeReport } from "./report";
|
|
15
|
+
import { parseReportArgs } from "./commands";
|
|
16
|
+
import { generateReportFixture } from "./__fixtures__/report/generate";
|
|
17
|
+
import { readdirSync } from "node:fs";
|
|
18
|
+
|
|
19
|
+
const rc = (address: string, module: string, type: string, name: string, actions: string[], change: Record<string, unknown>) => ({
|
|
20
|
+
address, module_address: module, mode: "managed", type, name, provider_name: "registry.terraform.io/hashicorp/aws", change: { actions, ...change },
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const PLAN = {
|
|
24
|
+
format_version: "1.2",
|
|
25
|
+
resource_changes: [
|
|
26
|
+
rc("module.network.aws_subnet.new", "module.network", "aws_subnet", "new", ["create"], {
|
|
27
|
+
before: null, after: { cidr_block: "10.0.9.0/24", tags: { Name: "new" } }, after_unknown: { id: true, arn: true }, after_sensitive: {},
|
|
28
|
+
}),
|
|
29
|
+
rc("module.network.aws_vpc.main", "module.network", "aws_vpc", "main", ["update"], {
|
|
30
|
+
before: { cidr_block: "10.0.0.0/16", enable_dns_support: true }, after: { cidr_block: "10.0.0.0/16", enable_dns_support: false }, after_unknown: {}, before_sensitive: {}, after_sensitive: {},
|
|
31
|
+
}),
|
|
32
|
+
rc("module.app.aws_security_group.sg", "module.app", "aws_security_group", "sg", ["create"], {
|
|
33
|
+
before: null, after: { name: "tgc-sg" }, after_unknown: { id: true, vpc_id: true }, after_sensitive: { password: true },
|
|
34
|
+
}),
|
|
35
|
+
rc("module.edge.aws_route_table.rt", "module.edge", "aws_route_table", "rt", ["delete", "create"], {
|
|
36
|
+
before: { vpc_id: "vpc-1" }, after: { vpc_id: "vpc-2" }, after_unknown: {}, replace_paths: [["vpc_id"]], before_sensitive: {}, after_sensitive: {},
|
|
37
|
+
}),
|
|
38
|
+
rc("module.edge.aws_route.keep", "module.edge", "aws_route", "keep", ["no-op"], { before: { x: 1 }, after: { x: 1 }, after_unknown: {} }),
|
|
39
|
+
],
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const AFTER = {
|
|
43
|
+
format_version: "1.2",
|
|
44
|
+
resource_changes: [],
|
|
45
|
+
prior_state: {
|
|
46
|
+
values: {
|
|
47
|
+
root_module: {
|
|
48
|
+
child_modules: [
|
|
49
|
+
{ address: "module.network", resources: [{ address: "module.network.aws_subnet.new", values: { id: "subnet-123", arn: "arn:aws:ec2:::subnet-123" }, sensitive_values: {} }] },
|
|
50
|
+
{ address: "module.app", resources: [{ address: "module.app.aws_security_group.sg", values: { id: "sg-9", vpc_id: "vpc-2" }, sensitive_values: { vpc_id: true } }] },
|
|
51
|
+
],
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const RUN = { project: "forgejo:3000/admin/demo-terragrunt-choudoufu", commit: "abc123", job_url: "http://forgejo:3000/admin/x/actions/runs/7", pull_request: "4" };
|
|
58
|
+
const FINISHED = "2026-10-24T10:00:00Z";
|
|
59
|
+
const base = { plan: PLAN, run: RUN, binary: "choudoufu", rootDir: "estates", finished: FINISHED };
|
|
60
|
+
|
|
61
|
+
const changeOf = (report: any, root: string, address: string) => report.roots.find((r: any) => r.path === root).changes.find((c: any) => c.address === address);
|
|
62
|
+
|
|
63
|
+
describe("slicing the composed plan", () => {
|
|
64
|
+
test("a module is taken off the addresses", () => {
|
|
65
|
+
expect(topModule("module.network.aws_subnet.new")).toBe("network");
|
|
66
|
+
expect(topModule("module.net[0].module.inner")).toBe("net");
|
|
67
|
+
expect(topModule("aws_vpc.main")).toBeUndefined();
|
|
68
|
+
const s = slicePlan(PLAN, "network") as any;
|
|
69
|
+
expect(s.resource_changes.map((r: any) => r.address)).toEqual(["aws_subnet.new", "aws_vpc.main"]);
|
|
70
|
+
expect(s.resource_changes[0].module_address).toBeUndefined();
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
describe("terraformReport, tf-plan", () => {
|
|
75
|
+
const { report, path, row } = terraformReport({ ...base, stage: "tf-plan" });
|
|
76
|
+
const r = report as any;
|
|
77
|
+
|
|
78
|
+
test("one root per module, in the roots' directory, as one composed wave", () => {
|
|
79
|
+
expect(r.schema).toBe("terragucci.report/v1");
|
|
80
|
+
expect(r.roots.map((x: any) => x.path)).toEqual(["estates/app", "estates/edge", "estates/network"]);
|
|
81
|
+
expect(r.roots.every((x: any) => x.status === "planned" && x.composed.wave === 1)).toBe(true);
|
|
82
|
+
expect(r.roots.find((x: any) => x.path === "estates/network").composed.module).toBe("module.network");
|
|
83
|
+
expect(r.waves).toHaveLength(1);
|
|
84
|
+
expect(r.waves[0].roots).toEqual(["estates/app", "estates/edge", "estates/network"]);
|
|
85
|
+
expect(r.waves[0].state).toBe("planned");
|
|
86
|
+
expect(r.waves[0].composed.members.map((m: any) => m.module)).toEqual(["module.app", "module.edge", "module.network"]);
|
|
87
|
+
expect(r.compose).toEqual({ roots: ["estates/app", "estates/edge", "estates/network"], max: 3, wave: 1, estate: true });
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test("a value the plan cannot know is unknown, with no after", () => {
|
|
91
|
+
const c = changeOf(r, "estates/network", "aws_subnet.new");
|
|
92
|
+
expect(c.action).toBe("create");
|
|
93
|
+
const id = c.attributes.find((a: any) => a.path === "id");
|
|
94
|
+
expect(id.unknown).toBe(true);
|
|
95
|
+
expect(id.after).toBeUndefined();
|
|
96
|
+
expect(c.attributes.find((a: any) => a.path === "cidr_block").after).toBe("10.0.9.0/24");
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test("an update carries before and after; a no-op is counted but not listed", () => {
|
|
100
|
+
const c = changeOf(r, "estates/network", "aws_vpc.main");
|
|
101
|
+
expect(c.attributes).toEqual([{ path: "enable_dns_support", before: true, after: false }]);
|
|
102
|
+
expect(r.roots.find((x: any) => x.path === "estates/edge").counts).toEqual({ replace: 1, "no-op": 1 });
|
|
103
|
+
expect(changeOf(r, "estates/edge", "aws_route.keep")).toBeUndefined();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test("totals, named replacements and the index row agree", () => {
|
|
107
|
+
expect(r.totals).toMatchObject({ create: 2, update: 1, replace: 1, delete: 0 });
|
|
108
|
+
expect(r.totals_roots).toBe(3);
|
|
109
|
+
expect(r.named).toEqual([expect.objectContaining({ root: "estates/edge", address: "aws_route_table.rt", action: "replace" })]);
|
|
110
|
+
expect(path).toBe("2026/10/abc123/tf-plan");
|
|
111
|
+
expect(row).toMatchObject({ project: RUN.project, stage: "tf-plan", path, roots: 3, changed: 3, totals: { create: 2, update: 1, replace: 1, delete: 0 }, pull_request: "4", destroys: ["estates/edge: aws_route_table.rt"] });
|
|
112
|
+
expect(row.applied).toBeUndefined();
|
|
113
|
+
expect(r.change_set).toMatch(/^jcs1-sha256:[0-9a-f]{64}$/);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test("the same plan gives the same report", () => {
|
|
117
|
+
expect(terraformReport({ ...base, stage: "tf-plan" }).report).toEqual(report);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
describe("terraformReport, tf-apply", () => {
|
|
122
|
+
const { report, row } = terraformReport({ ...base, stage: "tf-apply", applied: AFTER, finished: "2026-10-24T10:05:00Z" });
|
|
123
|
+
const r = report as any;
|
|
124
|
+
|
|
125
|
+
test("the values the plan left unknown are read from the state", () => {
|
|
126
|
+
const id = changeOf(r, "estates/network", "aws_subnet.new").attributes.find((a: any) => a.path === "id");
|
|
127
|
+
expect(id).toEqual({ path: "id", after: "subnet-123" });
|
|
128
|
+
const arn = changeOf(r, "estates/network", "aws_subnet.new").attributes.find((a: any) => a.path === "arn");
|
|
129
|
+
expect(arn.after).toBe("arn:aws:ec2:::subnet-123");
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test("a sensitive value stays unwritten, one the state lacks stays unknown", () => {
|
|
133
|
+
const sg = changeOf(r, "estates/app", "aws_security_group.sg").attributes;
|
|
134
|
+
expect(sg.find((a: any) => a.path === "vpc_id")).toEqual({ path: "vpc_id", sensitive: true });
|
|
135
|
+
expect(sg.find((a: any) => a.path === "id").after).toBe("sg-9");
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test("the wave is applied, with each member's changes done, and the row says when", () => {
|
|
139
|
+
expect(r.waves[0].state).toBe("applied");
|
|
140
|
+
expect(r.waves[0].composed.members.find((m: any) => m.root === "estates/network")).toMatchObject({ apply: "applied", changes: { done: 2, planned: 2 }, state: "written" });
|
|
141
|
+
expect(row.applied).toBe("2026-10-24T10:05:00Z");
|
|
142
|
+
expect(row.path).toBe("2026/10/abc123/tf-apply");
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test("an apply report without the post-apply plan is refused", () => {
|
|
146
|
+
expect(() => terraformReport({ ...base, stage: "tf-apply" })).toThrow(/post-apply plan/);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
describe("reads between the composed modules", () => {
|
|
151
|
+
const data = (name: string, estate: string, names: string[]) => ({ mode: "data", type: "terraform_estate_outputs", name, expressions: { estate: { constant_value: estate }, names: { constant_value: names } } });
|
|
152
|
+
const CONFIG = {
|
|
153
|
+
root_module: {
|
|
154
|
+
module_calls: {
|
|
155
|
+
network: { module: { outputs: { subnet_id: { expression: { references: ["aws_subnet.new.id", "aws_subnet.new"] } }, cidr: { expression: { references: ["aws_vpc.main.cidr_block", "aws_vpc.main"] } } } } },
|
|
156
|
+
app: {
|
|
157
|
+
module: {
|
|
158
|
+
resources: [data("net", "tgc-network", ["subnet_id", "cidr"]), { mode: "managed", type: "aws_security_group", name: "sg", expressions: { vpc_id: { references: ["data.terraform_estate_outputs.net.values.subnet_id", "data.terraform_estate_outputs.net.values", "data.terraform_estate_outputs.net"] } } }],
|
|
159
|
+
outputs: { sg: { expression: { references: ["aws_security_group.sg.id", "aws_security_group.sg"] } } },
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
edge: { module: { resources: [data("app", "tgc-app", ["sg"]), data("elsewhere", "tgc-other", ["x"])] } },
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
const ESTATES = { network: "tgc-network", app: "tgc-app", edge: "tgc-edge" };
|
|
167
|
+
const withReads = { ...base, plan: { ...PLAN, configuration: CONFIG }, estates: ESTATES, stage: "tf-plan" as const };
|
|
168
|
+
const r = terraformReport(withReads).report as any;
|
|
169
|
+
const rootReads = (root: string) => r.roots.find((x: any) => x.path === root).reads;
|
|
170
|
+
|
|
171
|
+
test("a read of another module's estate is an edge to that module's root, planned and composed", () => {
|
|
172
|
+
expect(rootReads("estates/app")).toEqual([{ upstream: "estates/network", data: "net", outputs: "planned", unknown: ["subnet_id"], composed: true }]);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
test("only the outputs the reader uses count as unknown, and a read of an estate nobody owns is left out", () => {
|
|
176
|
+
expect(rootReads("estates/edge")).toEqual([{ upstream: "estates/app", data: "app", outputs: "planned", unknown: ["sg"], composed: true }]);
|
|
177
|
+
expect(rootReads("estates/network")).toBeUndefined();
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
test("an output known at plan time is not listed as unknown", () => {
|
|
181
|
+
const known = terraformReport({ ...withReads, plan: { ...withReads.plan, output_changes: {} } }).report as any;
|
|
182
|
+
expect(known.roots.find((x: any) => x.path === "estates/app").reads[0].unknown).toEqual(["subnet_id"]);
|
|
183
|
+
const cfg = JSON.parse(JSON.stringify(CONFIG));
|
|
184
|
+
cfg.root_module.module_calls.app.module.resources[1].expressions.vpc_id.references = ["data.terraform_estate_outputs.net.values.cidr", "data.terraform_estate_outputs.net.values"];
|
|
185
|
+
const only = terraformReport({ ...withReads, plan: { ...PLAN, configuration: cfg } }).report as any;
|
|
186
|
+
expect(only.roots.find((x: any) => x.path === "estates/app").reads[0].unknown).toBeUndefined();
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
test("the composed root's planned outputs name unknowns too", () => {
|
|
190
|
+
const plan = { ...PLAN, configuration: { root_module: { module_calls: { app: CONFIG.root_module.module_calls.app } } }, output_changes: { network__vpc_id: { actions: ["create"], after_unknown: true } } };
|
|
191
|
+
const cfg = JSON.parse(JSON.stringify(plan.configuration));
|
|
192
|
+
cfg.root_module.module_calls.app.module.resources[1].expressions.vpc_id.references = ["data.terraform_estate_outputs.net.values.vpc_id", "data.terraform_estate_outputs.net.values"];
|
|
193
|
+
const out = terraformReport({ ...withReads, plan: { ...plan, configuration: cfg } }).report as any;
|
|
194
|
+
expect(out.roots.find((x: any) => x.path === "estates/app").reads[0].unknown).toEqual(["vpc_id"]);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
test("with no estates, or a plan without configuration, no root has reads", () => {
|
|
198
|
+
const none = terraformReport({ ...base, stage: "tf-plan" }).report as any;
|
|
199
|
+
expect(none.roots.some((x: any) => "reads" in x)).toBe(false);
|
|
200
|
+
const bare = terraformReport({ ...base, stage: "tf-plan", estates: ESTATES }).report as any;
|
|
201
|
+
expect(bare.roots.some((x: any) => "reads" in x)).toBe(false);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
test("the estates come from each module's live block", () => {
|
|
205
|
+
const repo = mkdtempSync(join(tmpdir(), "tf-estates-"));
|
|
206
|
+
for (const [m, body] of Object.entries({
|
|
207
|
+
network: 'terraform {\n live {\n estate = "tgc-network"\n record_store "s3" { bucket = "b" }\n }\n}\n',
|
|
208
|
+
app: '# live { estate = "wrong" }\nterraform {\n live {\n estate = "tgc-app"\n }\n}\n',
|
|
209
|
+
edge: "resource \"x\" \"y\" {}\n",
|
|
210
|
+
})) {
|
|
211
|
+
mkdirSync(join(repo, "estates", m), { recursive: true });
|
|
212
|
+
writeFileSync(join(repo, "estates", m, "main.tf"), body);
|
|
213
|
+
}
|
|
214
|
+
expect(moduleEstates(repo, "estates", ["network", "app", "edge", "gone"])).toEqual({ network: "tgc-network", app: "tgc-app" });
|
|
215
|
+
expect(estateOfDir(join(repo, "nowhere"))).toBeUndefined();
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
describe("reads from an Atmos stack's !terraform.output", () => {
|
|
220
|
+
const STACK = [
|
|
221
|
+
"# One stack, three components.",
|
|
222
|
+
"vars:",
|
|
223
|
+
" stage: dev",
|
|
224
|
+
"components:",
|
|
225
|
+
" terraform:",
|
|
226
|
+
" network:",
|
|
227
|
+
" vars:",
|
|
228
|
+
" subnet_a_cidr: 10.0.1.0/24",
|
|
229
|
+
" app:",
|
|
230
|
+
" settings:",
|
|
231
|
+
" depends_on:",
|
|
232
|
+
" 1:",
|
|
233
|
+
" component: network",
|
|
234
|
+
" vars:",
|
|
235
|
+
" vpc_id: !terraform.output network vpc_id",
|
|
236
|
+
" subnet_id: !terraform.output network dev '.subnet_id' # with a stack",
|
|
237
|
+
" edge:",
|
|
238
|
+
" vars:",
|
|
239
|
+
" listener_port: !terraform.output app listener_port",
|
|
240
|
+
" cidr: !terraform.output network subnet_a_cidr",
|
|
241
|
+
" ports:",
|
|
242
|
+
" - !terraform.output app admin_port",
|
|
243
|
+
" edge-blue:",
|
|
244
|
+
" metadata:",
|
|
245
|
+
" component: edge",
|
|
246
|
+
" vars:",
|
|
247
|
+
" extra: !terraform.output network vpc_id",
|
|
248
|
+
"",
|
|
249
|
+
].join("\n");
|
|
250
|
+
|
|
251
|
+
test("each component's reads, by the component directory, outputs sorted", () => {
|
|
252
|
+
expect(atmosOutputReads(STACK)).toEqual({
|
|
253
|
+
app: { network: ["subnet_id", "vpc_id"] },
|
|
254
|
+
edge: { app: ["admin_port", "listener_port"], network: ["subnet_a_cidr", "vpc_id"] },
|
|
255
|
+
});
|
|
256
|
+
expect(atmosOutputReads("components:\n terraform:\n a:\n vars:\n x: 1\n")).toEqual({});
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
test("the stack manifests under atmos.yaml's stacks.base_path, and none without atmos.yaml", () => {
|
|
260
|
+
const repo = mkdtempSync(join(tmpdir(), "tf-atmos-"));
|
|
261
|
+
expect(atmosStackReads(repo)).toEqual({});
|
|
262
|
+
writeFileSync(join(repo, "atmos.yaml"), "base_path: .\ncomponents:\n terraform:\n base_path: components/terraform\nstacks:\n base_path: my-stacks\n name_template: '{{ .vars.stage }}'\n");
|
|
263
|
+
mkdirSync(join(repo, "my-stacks", "deploy"), { recursive: true });
|
|
264
|
+
writeFileSync(join(repo, "my-stacks", "deploy", "dev.yaml"), STACK);
|
|
265
|
+
expect(atmosStackReads(repo).app).toEqual({ network: ["subnet_id", "vpc_id"] });
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
test("a read is an edge to the upstream's root, planned and composed, with the unknown outputs it reads", () => {
|
|
269
|
+
const plan = {
|
|
270
|
+
...PLAN,
|
|
271
|
+
output_changes: { network__vpc_id: { actions: ["no-op"], after: "vpc-1", after_unknown: false }, network__subnet_id: { actions: ["create"], after_unknown: true } },
|
|
272
|
+
};
|
|
273
|
+
const r = terraformReport({ ...base, rootDir: "components/terraform", plan, stage: "tf-plan", componentReads: atmosOutputReads(STACK) }).report as any;
|
|
274
|
+
const reads = (root: string) => r.roots.find((x: any) => x.path === root).reads;
|
|
275
|
+
expect(reads("components/terraform/app")).toEqual([
|
|
276
|
+
{ upstream: "components/terraform/network", data: "network", outputs: "planned", unknown: ["subnet_id"], why: "!terraform.output network: subnet_id, vpc_id", composed: true },
|
|
277
|
+
]);
|
|
278
|
+
expect(reads("components/terraform/edge").map((x: any) => x.upstream)).toEqual(["components/terraform/app", "components/terraform/network"]);
|
|
279
|
+
expect(reads("components/terraform/network")).toBeUndefined();
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
test("an upstream that is no module of the run has no edge", () => {
|
|
283
|
+
const r = terraformReport({ ...base, stage: "tf-plan", componentReads: { app: { vault: ["x"] } } }).report as any;
|
|
284
|
+
expect(r.roots.some((x: any) => "reads" in x)).toBe(false);
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
describe("writing", () => {
|
|
289
|
+
test("report.json, the project's index and the prefix's, merged with an earlier row", async () => {
|
|
290
|
+
const dir = mkdtempSync(join(tmpdir(), "tf-report-"));
|
|
291
|
+
const store = dirStore(dir);
|
|
292
|
+
const plan = terraformReport({ ...base, stage: "tf-plan" });
|
|
293
|
+
const apply = terraformReport({ ...base, stage: "tf-apply", applied: AFTER, finished: "2026-10-24T10:05:00Z" });
|
|
294
|
+
expect(await writeReport(store, plan)).toEqual([`${RUN.project}/2026/10/abc123/tf-plan/report.json`, `${RUN.project}/2026/10/abc123/tf-plan/change-set.json`, `${RUN.project}/index.json`, "index.json"]);
|
|
295
|
+
await writeReport(store, apply);
|
|
296
|
+
await writeReport(store, apply);
|
|
297
|
+
const project = JSON.parse(readFileSync(join(dir, RUN.project, "index.json"), "utf8"));
|
|
298
|
+
expect(project.schema).toBe("terragucci.report-index/v1");
|
|
299
|
+
expect(project.reports.map((x: any) => [x.stage, x.path])).toEqual([["tf-apply", "2026/10/abc123/tf-apply"], ["tf-plan", "2026/10/abc123/tf-plan"]]);
|
|
300
|
+
const top = JSON.parse(readFileSync(join(dir, "index.json"), "utf8"));
|
|
301
|
+
expect(top.reports[1].path).toBe(`${RUN.project}/2026/10/abc123/tf-plan`);
|
|
302
|
+
const stored = JSON.parse(readFileSync(join(dir, RUN.project, "2026/10/abc123/tf-apply/report.json"), "utf8"));
|
|
303
|
+
expect(stored.run.stage).toBe("tf-apply");
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
test("an unreadable index starts again from the row", () => {
|
|
307
|
+
expect(addToIndex("{nope", terraformReport({ ...base, stage: "tf-plan" }).row).reports).toHaveLength(1);
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
test("the http store reads a 404 as no object and puts unsigned", async () => {
|
|
311
|
+
const seen: string[] = [];
|
|
312
|
+
const objects = new Map<string, string>();
|
|
313
|
+
const fake = (async (url: string, init?: RequestInit) => {
|
|
314
|
+
seen.push(`${init?.method ?? "GET"} ${url}`);
|
|
315
|
+
if (init?.method === "PUT") {
|
|
316
|
+
objects.set(url, String(init.body));
|
|
317
|
+
return new Response("", { status: 200 });
|
|
318
|
+
}
|
|
319
|
+
return objects.has(url) ? new Response(objects.get(url)!) : new Response("", { status: 404 });
|
|
320
|
+
}) as unknown as typeof fetch;
|
|
321
|
+
const store = httpStore("http://floci:4566/demo-reports/demo/", fake);
|
|
322
|
+
await writeReport(store, terraformReport({ ...base, stage: "tf-plan" }));
|
|
323
|
+
expect(seen[0]).toBe("PUT http://floci:4566/demo-reports/demo/forgejo%3A3000/admin/demo-terragrunt-choudoufu/2026/10/abc123/tf-plan/report.json");
|
|
324
|
+
expect(seen).toContain("GET http://floci:4566/demo-reports/demo/index.json");
|
|
325
|
+
expect(JSON.parse(objects.get("http://floci:4566/demo-reports/demo/index.json")!).reports).toHaveLength(1);
|
|
326
|
+
});
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
const SCHEMA_PATH = join(import.meta.dirname, "..", "..", "..", "packages", "core", "src", "workspace", "change-set.schema.json");
|
|
330
|
+
const { validate: validateChangeSet } = contract(JSON.parse(readFileSync(SCHEMA_PATH, "utf8")));
|
|
331
|
+
const FIXTURE_DIR = join(import.meta.dirname, "__fixtures__", "report");
|
|
332
|
+
|
|
333
|
+
/** The change set must validate against chant's schema and be the document the report's digest names. */
|
|
334
|
+
function expectChangeSet(doc: any, report: any): void {
|
|
335
|
+
expect(validateChangeSet(doc), JSON.stringify(validateChangeSet.errors, null, 2)).toBe(true);
|
|
336
|
+
expect(verifyChangeSetDigest(doc)).toBe(true);
|
|
337
|
+
expect(report.change_set).toBe(doc.digest);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
describe("change-set.json beside the report", () => {
|
|
341
|
+
const apply = { ...base, stage: "tf-apply" as const, applied: AFTER, finished: "2026-10-24T10:05:00Z" };
|
|
342
|
+
|
|
343
|
+
test.each([["tf-plan", { ...base, stage: "tf-plan" as const }], ["tf-apply", apply]])("%s: the document validates and its digest is the report's", (_stage, input) => {
|
|
344
|
+
const r = terraformReport(input);
|
|
345
|
+
expectChangeSet(r.changeSet, r.report);
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
test("--out writes it next to report.json for both stages", async () => {
|
|
349
|
+
const dir = mkdtempSync(join(tmpdir(), "tf-report-cs-"));
|
|
350
|
+
const store = dirStore(dir);
|
|
351
|
+
for (const input of [{ ...base, stage: "tf-plan" as const }, apply]) {
|
|
352
|
+
const r = terraformReport(input);
|
|
353
|
+
await writeReport(store, r);
|
|
354
|
+
const at = join(dir, RUN.project, r.path);
|
|
355
|
+
expect(readdirSync(at).sort()).toEqual(["change-set.json", "report.json"]);
|
|
356
|
+
expectChangeSet(JSON.parse(readFileSync(join(at, "change-set.json"), "utf8")), JSON.parse(readFileSync(join(at, "report.json"), "utf8")));
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
test("--to puts it next to report.json for both stages", async () => {
|
|
361
|
+
const objects = new Map<string, string>();
|
|
362
|
+
const fake = (async (url: string, init?: RequestInit) => {
|
|
363
|
+
if (init?.method === "PUT") {
|
|
364
|
+
objects.set(url, String(init.body));
|
|
365
|
+
return new Response("", { status: 200 });
|
|
366
|
+
}
|
|
367
|
+
return objects.has(url) ? new Response(objects.get(url)!) : new Response("", { status: 404 });
|
|
368
|
+
}) as unknown as typeof fetch;
|
|
369
|
+
const store = httpStore("http://floci:4566/demo-reports/demo", fake);
|
|
370
|
+
for (const input of [{ ...base, stage: "tf-plan" as const }, apply]) {
|
|
371
|
+
const r = terraformReport(input);
|
|
372
|
+
await writeReport(store, r);
|
|
373
|
+
const at = `http://floci:4566/demo-reports/demo/${encodeURIComponent("forgejo:3000").replace(/%3A/g, "%3A")}/admin/demo-terragrunt-choudoufu/${r.path}`;
|
|
374
|
+
expectChangeSet(JSON.parse(objects.get(`${at}/change-set.json`)!), JSON.parse(objects.get(`${at}/report.json`)!));
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
describe("the report fixture behold renders", () => {
|
|
380
|
+
const read = (name: string): any => JSON.parse(readFileSync(join(FIXTURE_DIR, name), "utf8"));
|
|
381
|
+
|
|
382
|
+
test("is what the generator writes now; regenerate with `npx tsx lexicons/terraform/src/__fixtures__/report/generate.ts`", async () => {
|
|
383
|
+
const files = await generateReportFixture();
|
|
384
|
+
expect(Object.keys(files).sort()).toEqual(["tf-apply/change-set.json", "tf-apply/report.json", "tf-plan/change-set.json", "tf-plan/report.json"]);
|
|
385
|
+
for (const [name, body] of Object.entries(files)) expect(readFileSync(join(FIXTURE_DIR, name), "utf8"), `${name} is stale`).toBe(body);
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
test("both stages validate, and each digest is its report's", () => {
|
|
389
|
+
for (const stage of ["tf-plan", "tf-apply"]) expectChangeSet(read(`${stage}/change-set.json`), read(`${stage}/report.json`));
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
test("three members, two composed reads", () => {
|
|
393
|
+
const plan = read("tf-plan/report.json");
|
|
394
|
+
expect(read("tf-plan/change-set.json").members.map((m: any) => m.member)).toEqual(["estates/app", "estates/edge", "estates/network"]);
|
|
395
|
+
const reads = plan.roots.flatMap((r: any) => r.reads ?? []);
|
|
396
|
+
expect(reads.filter((r: any) => r.composed === true).length).toBeGreaterThanOrEqual(2);
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
test("an attribute unknown at plan has its value after the apply", () => {
|
|
400
|
+
const attr = (stage: string) => read(`${stage}/report.json`).roots.find((r: any) => r.path === "estates/network").changes.find((c: any) => c.address === "aws_subnet.new").attributes.find((a: any) => a.path === "id");
|
|
401
|
+
expect(attr("tf-plan")).toEqual({ path: "id", unknown: true });
|
|
402
|
+
expect(attr("tf-apply")).toEqual({ path: "id", after: "subnet-0a1b" });
|
|
403
|
+
});
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
describe("the run's facts and the verb's flags", () => {
|
|
407
|
+
test("a Forgejo environment names the project as terragucci does", () => {
|
|
408
|
+
const f = runFactsFromEnv({ GITHUB_REPOSITORY: "admin/demo", GITHUB_SERVER_URL: "http://forgejo:3000", GITHUB_SHA: "deadbeef", GITHUB_RUN_ID: "9", FORGEJO_ACTIONS: "true" }, { pullRequest: "12" });
|
|
409
|
+
expect(f).toEqual({
|
|
410
|
+
project: "forgejo:3000/admin/demo", commit: "deadbeef", job_url: "http://forgejo:3000/admin/demo/actions/runs/9",
|
|
411
|
+
commit_url: "http://forgejo:3000/admin/demo/commit/deadbeef", pull_request: "12", pull_request_url: "http://forgejo:3000/admin/demo/pulls/12",
|
|
412
|
+
});
|
|
413
|
+
expect(() => runFactsFromEnv({})).toThrow(/--project and --commit/);
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
test("flags", () => {
|
|
417
|
+
expect(parseReportArgs(["--stage", "tf-plan", "--plan", "p.json", "--out", "d"]).values.get("--out")).toBe("d");
|
|
418
|
+
expect(() => parseReportArgs(["--stage", "tf-apply", "--plan", "p.json", "--out", "d"])).toThrow(/--applied/);
|
|
419
|
+
expect(() => parseReportArgs(["--stage", "tf-plan", "--plan", "p.json"])).toThrow(/--out/);
|
|
420
|
+
expect(() => parseReportArgs(["--stage", "tf-plan", "--plan", "p.json", "--out", "d", "--to", "u"])).toThrow(/--out/);
|
|
421
|
+
expect(() => parseReportArgs(["--bogus"])).toThrow();
|
|
422
|
+
});
|
|
423
|
+
});
|