@intentius/chant-lexicon-terraform 0.124.54 → 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/README.md +7 -4
- package/dist/ci-setup.d.ts +11 -0
- package/dist/ci-setup.d.ts.map +1 -0
- package/dist/ci-setup.js +41 -0
- package/dist/components/capability-plugin.d.ts +40 -6
- package/dist/components/capability-plugin.d.ts.map +1 -1
- package/dist/components/capability-plugin.js +167 -30
- package/dist/components/compose-group.d.ts +1 -1
- package/dist/components/compose-group.d.ts.map +1 -1
- package/dist/components/compose-group.js +1 -1
- package/dist/components/release-inputs.d.ts +29 -0
- package/dist/components/release-inputs.d.ts.map +1 -0
- package/dist/components/release-inputs.js +57 -0
- package/dist/components/trace-facts.d.ts +16 -0
- package/dist/components/trace-facts.d.ts.map +1 -0
- package/dist/components/trace-facts.js +19 -0
- package/dist/cone.d.ts +53 -0
- package/dist/cone.d.ts.map +1 -0
- package/dist/cone.js +119 -0
- package/dist/cost-hold.d.ts +27 -0
- package/dist/cost-hold.d.ts.map +1 -0
- package/dist/cost-hold.js +21 -0
- package/dist/drift-rows.d.ts +61 -0
- package/dist/drift-rows.d.ts.map +1 -0
- package/dist/drift-rows.js +108 -0
- package/dist/exit-codes.d.ts +55 -0
- package/dist/exit-codes.d.ts.map +1 -0
- package/dist/exit-codes.js +48 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/integrity.json +7 -4
- package/dist/lint/audit-catalog.d.ts.map +1 -1
- package/dist/lint/audit-catalog.js +27 -3
- package/dist/lint/audit-lineage.d.ts +14 -2
- package/dist/lint/audit-lineage.d.ts.map +1 -1
- package/dist/lint/post-synth/index.d.ts.map +1 -1
- package/dist/lint/post-synth/index.js +4 -0
- package/dist/lint/post-synth/record-store.d.ts +54 -0
- package/dist/lint/post-synth/record-store.d.ts.map +1 -0
- package/dist/lint/post-synth/record-store.js +104 -0
- package/dist/lint/post-synth/tf001.d.ts +2 -2
- package/dist/lint/post-synth/tf001.js +2 -2
- package/dist/lint/post-synth/tf024.d.ts +35 -11
- package/dist/lint/post-synth/tf024.d.ts.map +1 -1
- package/dist/lint/post-synth/tf024.js +92 -20
- package/dist/lint/post-synth/tf046.d.ts +64 -0
- package/dist/lint/post-synth/tf046.d.ts.map +1 -0
- package/dist/lint/post-synth/tf046.js +175 -0
- package/dist/lint/post-synth/tf047.d.ts +36 -0
- package/dist/lint/post-synth/tf047.d.ts.map +1 -0
- package/dist/lint/post-synth/tf047.js +94 -0
- package/dist/lock-rows.d.ts +36 -0
- package/dist/lock-rows.d.ts.map +1 -0
- package/dist/lock-rows.js +60 -0
- package/dist/lock-timeout.d.ts +22 -0
- package/dist/lock-timeout.d.ts.map +1 -0
- package/dist/lock-timeout.js +32 -0
- package/dist/manifest.json +1 -1
- package/dist/module-catalog/index.d.ts +69 -0
- package/dist/module-catalog/index.d.ts.map +1 -0
- package/dist/module-catalog/index.js +110 -0
- package/dist/module-catalog/refresh-cli.d.ts +4 -0
- package/dist/module-catalog/refresh-cli.d.ts.map +1 -0
- package/dist/module-catalog/refresh-cli.js +64 -0
- package/dist/module-catalog/static-tier.d.ts +6 -0
- package/dist/module-catalog/static-tier.d.ts.map +1 -0
- package/dist/module-catalog/static-tier.js +1650 -0
- package/dist/module-catalog/types.d.ts +65 -0
- package/dist/module-catalog/types.d.ts.map +1 -0
- package/dist/module-catalog/types.js +33 -0
- package/dist/okf/index.md +3 -1
- package/dist/okf/rules/TF024.md +2 -2
- package/dist/okf/rules/TF046.md +11 -0
- package/dist/okf/rules/TF047.md +11 -0
- package/dist/op/activities/terraform.d.ts +29 -0
- package/dist/op/activities/terraform.d.ts.map +1 -1
- package/dist/op/activities/terraform.js +19 -4
- package/dist/pin/consumers.d.ts +35 -0
- package/dist/pin/consumers.d.ts.map +1 -0
- package/dist/pin/consumers.js +70 -0
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +5 -0
- package/dist/registry/address.d.ts +63 -0
- package/dist/registry/address.d.ts.map +1 -0
- package/dist/registry/address.js +65 -0
- package/dist/registry/catalog-read.d.ts +14 -0
- package/dist/registry/catalog-read.d.ts.map +1 -0
- package/dist/registry/catalog-read.js +58 -0
- package/dist/registry/deprecated.d.ts +37 -0
- package/dist/registry/deprecated.d.ts.map +1 -0
- package/dist/registry/deprecated.js +43 -0
- package/dist/registry/docs.d.ts +96 -0
- package/dist/registry/docs.d.ts.map +1 -0
- package/dist/registry/docs.js +210 -0
- package/dist/registry/edge/edge.d.ts +46 -0
- package/dist/registry/edge/edge.d.ts.map +1 -0
- package/dist/registry/edge/edge.js +194 -0
- package/dist/registry/edge/index.d.ts +11 -0
- package/dist/registry/edge/index.d.ts.map +1 -0
- package/dist/registry/edge/index.js +10 -0
- package/dist/registry/edge/lambda-edge.d.ts +76 -0
- package/dist/registry/edge/lambda-edge.d.ts.map +1 -0
- package/dist/registry/edge/lambda-edge.js +95 -0
- package/dist/registry/edge/sigv4-web.d.ts +33 -0
- package/dist/registry/edge/sigv4-web.d.ts.map +1 -0
- package/dist/registry/edge/sigv4-web.js +56 -0
- package/dist/registry/edge/token-source.d.ts +73 -0
- package/dist/registry/edge/token-source.d.ts.map +1 -0
- package/dist/registry/edge/token-source.js +115 -0
- package/dist/registry/edge/worker.d.ts +45 -0
- package/dist/registry/edge/worker.d.ts.map +1 -0
- package/dist/registry/edge/worker.js +26 -0
- package/dist/registry/handler.d.ts +25 -0
- package/dist/registry/handler.d.ts.map +1 -0
- package/dist/registry/handler.js +75 -0
- package/dist/registry/headers-file.d.ts +21 -0
- package/dist/registry/headers-file.d.ts.map +1 -0
- package/dist/registry/headers-file.js +57 -0
- package/dist/registry/index.d.ts +31 -0
- package/dist/registry/index.d.ts.map +1 -0
- package/dist/registry/index.js +30 -0
- package/dist/registry/mirror-paths.d.ts +9 -0
- package/dist/registry/mirror-paths.d.ts.map +1 -0
- package/dist/registry/mirror-paths.js +8 -0
- package/dist/registry/mirror.d.ts +130 -0
- package/dist/registry/mirror.d.ts.map +1 -0
- package/dist/registry/mirror.js +319 -0
- package/dist/registry/proxies.d.ts +73 -0
- package/dist/registry/proxies.d.ts.map +1 -0
- package/dist/registry/proxies.js +111 -0
- package/dist/registry/reader.d.ts +57 -0
- package/dist/registry/reader.d.ts.map +1 -0
- package/dist/registry/reader.js +198 -0
- package/dist/registry/semver.d.ts +16 -0
- package/dist/registry/semver.d.ts.map +1 -0
- package/dist/registry/semver.js +24 -0
- package/dist/registry/serve.d.ts +24 -0
- package/dist/registry/serve.d.ts.map +1 -0
- package/dist/registry/serve.js +64 -0
- package/dist/registry/source-forms.d.ts +79 -0
- package/dist/registry/source-forms.d.ts.map +1 -0
- package/dist/registry/source-forms.js +202 -0
- package/dist/registry/targets/artifactory.d.ts +28 -0
- package/dist/registry/targets/artifactory.d.ts.map +1 -0
- package/dist/registry/targets/artifactory.js +206 -0
- package/dist/registry/targets/fake-artifactory.d.ts +30 -0
- package/dist/registry/targets/fake-artifactory.d.ts.map +1 -0
- package/dist/registry/targets/fake-artifactory.js +142 -0
- package/dist/registry/targets/fake-gitlab.d.ts +39 -0
- package/dist/registry/targets/fake-gitlab.d.ts.map +1 -0
- package/dist/registry/targets/fake-gitlab.js +136 -0
- package/dist/registry/targets/fake-hcp.d.ts +50 -0
- package/dist/registry/targets/fake-hcp.d.ts.map +1 -0
- package/dist/registry/targets/fake-hcp.js +202 -0
- package/dist/registry/targets/fake-http.d.ts +31 -0
- package/dist/registry/targets/fake-http.d.ts.map +1 -0
- package/dist/registry/targets/fake-http.js +87 -0
- package/dist/registry/targets/fake-nexus.d.ts +27 -0
- package/dist/registry/targets/fake-nexus.d.ts.map +1 -0
- package/dist/registry/targets/fake-nexus.js +137 -0
- package/dist/registry/targets/gitlab.d.ts +53 -0
- package/dist/registry/targets/gitlab.d.ts.map +1 -0
- package/dist/registry/targets/gitlab.js +187 -0
- package/dist/registry/targets/hcp.d.ts +29 -0
- package/dist/registry/targets/hcp.d.ts.map +1 -0
- package/dist/registry/targets/hcp.js +310 -0
- package/dist/registry/targets/hosted.d.ts +62 -0
- package/dist/registry/targets/hosted.d.ts.map +1 -0
- package/dist/registry/targets/hosted.js +74 -0
- package/dist/registry/targets/index.d.ts +18 -0
- package/dist/registry/targets/index.d.ts.map +1 -0
- package/dist/registry/targets/index.js +17 -0
- package/dist/registry/targets/module-target.d.ts +68 -0
- package/dist/registry/targets/module-target.d.ts.map +1 -0
- package/dist/registry/targets/module-target.js +63 -0
- package/dist/registry/targets/nexus.d.ts +43 -0
- package/dist/registry/targets/nexus.d.ts.map +1 -0
- package/dist/registry/targets/nexus.js +250 -0
- package/dist/registry/targets/zip.d.ts +55 -0
- package/dist/registry/targets/zip.d.ts.map +1 -0
- package/dist/registry/targets/zip.js +278 -0
- package/dist/registry/writer.d.ts +101 -0
- package/dist/registry/writer.d.ts.map +1 -0
- package/dist/registry/writer.js +109 -0
- package/dist/rules/record-store.ts +122 -0
- package/dist/rules/tf001.ts +2 -2
- package/dist/rules/tf024.ts +105 -22
- package/dist/rules/tf046.ts +204 -0
- package/dist/rules/tf047.ts +114 -0
- package/dist/state/azure-blob.d.ts +8 -67
- package/dist/state/azure-blob.d.ts.map +1 -1
- package/dist/state/azure-blob.js +6 -199
- package/dist/state/gcs.d.ts +7 -61
- package/dist/state/gcs.d.ts.map +1 -1
- package/dist/state/gcs.js +5 -222
- package/dist/state/object-store.d.ts +4 -33
- package/dist/state/object-store.d.ts.map +1 -1
- package/dist/state/object-store.js +4 -17
- package/dist/state/s3.d.ts +11 -58
- package/dist/state/s3.d.ts.map +1 -1
- package/dist/state/s3.js +10 -161
- package/dist/state/store.js +2 -2
- package/dist/state-ops.d.ts +255 -0
- package/dist/state-ops.d.ts.map +1 -0
- package/dist/state-ops.js +305 -0
- package/dist/state-reads.d.ts +57 -0
- package/dist/state-reads.d.ts.map +1 -0
- package/dist/state-reads.js +104 -0
- package/dist/used-sources.d.ts +54 -0
- package/dist/used-sources.d.ts.map +1 -0
- package/dist/used-sources.js +157 -0
- package/package.json +19 -3
- package/src/__fixtures__/drift-record/README.md +5 -0
- package/src/__fixtures__/drift-rows/live-root-plan.json +70 -0
- package/src/__fixtures__/drift-rows/refresh-plan.json +61 -0
- package/src/__fixtures__/used-sources/root/extra.tofu +1 -0
- package/src/__fixtures__/used-sources/root/main.tf +31 -0
- package/src/__fixtures__/used-sources/root/modules/net/main.tf +14 -0
- package/src/__fixtures__/used-sources/root/modules/net/versions.tf.json +7 -0
- package/src/__fixtures__/used-sources/unit/terragrunt.hcl +3 -0
- package/src/ci-setup.ts +42 -0
- package/src/components/capability-plugin.test.ts +26 -14
- package/src/components/capability-plugin.ts +178 -31
- package/src/components/compose-group.ts +1 -1
- package/src/components/pr-loop-compose.tofu.e2e.test.ts +1 -1
- package/src/components/pr-loop.tofu.test.ts +1 -1
- package/src/components/release-inputs.ts +69 -0
- package/src/components/trace-facts.test.ts +21 -0
- package/src/components/trace-facts.ts +27 -0
- package/src/cone.ts +138 -0
- package/src/cost-hold.ts +29 -0
- package/src/describe-resources.engine-facts.test.ts +2 -3
- package/src/drift-rows.test.ts +135 -0
- package/src/drift-rows.ts +137 -0
- package/src/exit-codes.test.ts +23 -0
- package/src/exit-codes.ts +59 -0
- package/src/index.ts +3 -0
- package/src/lint/audit-catalog.ts +29 -3
- package/src/lint/audit-lineage.ts +14 -2
- package/src/lint/post-synth/fixtures/TF024/live-with-record-store/main.tf +18 -0
- package/src/lint/post-synth/fixtures/TF024/sidecar-with-backend/estate.chdf.hcl +1 -0
- package/src/lint/post-synth/fixtures/TF024/sidecar-with-backend/main.tf +10 -0
- package/src/lint/post-synth/fixtures/TF046/azurerm-no-resource-group/main.tf +15 -0
- package/src/lint/post-synth/fixtures/TF046/backend-config-only/main.tf +14 -0
- package/src/lint/post-synth/fixtures/TF046/derived-s3/backend.tf +7 -0
- package/src/lint/post-synth/fixtures/TF046/derived-s3/main.tf +9 -0
- package/src/lint/post-synth/fixtures/TF046/explicit-local/main.tf +16 -0
- package/src/lint/post-synth/fixtures/TF046/explicit-s3-beside-local-backend/main.tf +15 -0
- package/src/lint/post-synth/fixtures/TF046/implied-local/main.tf +9 -0
- package/src/lint/post-synth/fixtures/TF046/sidecar-implied/estate.chdf.hcl +1 -0
- package/src/lint/post-synth/fixtures/TF046/sidecar-implied/main.tf +5 -0
- package/src/lint/post-synth/fixtures/TF047/clear/main.tf +12 -0
- package/src/lint/post-synth/fixtures/TF047/refused/main.tf +12 -0
- package/src/lint/post-synth/fixtures/TF047/unknown-module/main.tf +12 -0
- package/src/lint/post-synth/fixtures/TF047/unknown-version/main.tf +12 -0
- package/src/lint/post-synth/index.ts +4 -0
- package/src/lint/post-synth/record-store.ts +122 -0
- package/src/lint/post-synth/tf001.ts +2 -2
- package/src/lint/post-synth/tf024.test.ts +26 -5
- package/src/lint/post-synth/tf024.ts +105 -22
- package/src/lint/post-synth/tf046.test.ts +137 -0
- package/src/lint/post-synth/tf046.ts +204 -0
- package/src/lint/post-synth/tf047.test.ts +56 -0
- package/src/lint/post-synth/tf047.ts +114 -0
- package/src/lock-rows.test.ts +70 -0
- package/src/lock-rows.ts +82 -0
- package/src/lock-timeout.ts +34 -0
- package/src/module-catalog/index.test.ts +93 -0
- package/src/module-catalog/index.ts +159 -0
- package/src/module-catalog/refresh-cli.ts +68 -0
- package/src/module-catalog/static-tier.ts +1659 -0
- package/src/module-catalog/types.ts +88 -0
- package/src/op/activities/terraform.ts +46 -5
- package/src/op-wave-step.test.ts +109 -0
- package/src/pin/__fixtures__/consumers/live/dev/main.tf +4 -0
- package/src/pin/__fixtures__/consumers/live/prod/main.tf +21 -0
- package/src/pin/__fixtures__/consumers/units/vpc/terragrunt.hcl +7 -0
- package/src/pin/consumers.test.ts +57 -0
- package/src/pin/consumers.ts +95 -0
- package/src/plugin.ts +6 -0
- package/src/registry/__fixtures__/docs/documented/.terraform-docs.yml +3 -0
- package/src/registry/__fixtures__/docs/documented/README.md +1 -0
- package/src/registry/__fixtures__/docs/documented/main.tf +8 -0
- package/src/registry/__fixtures__/docs/json/main.tf.json +14 -0
- package/src/registry/__fixtures__/docs/vpc/README.md +3 -0
- package/src/registry/__fixtures__/docs/vpc/examples/complete/main.tf +5 -0
- package/src/registry/__fixtures__/docs/vpc/examples/simple/README.md +1 -0
- package/src/registry/__fixtures__/docs/vpc/examples/simple/main.tf +4 -0
- package/src/registry/__fixtures__/docs/vpc/main.tf +14 -0
- package/src/registry/__fixtures__/docs/vpc/outputs.tf +9 -0
- package/src/registry/__fixtures__/docs/vpc/variables.tf +16 -0
- package/src/registry/__fixtures__/proxied-root/main.tf +12 -0
- package/src/registry/address.ts +100 -0
- package/src/registry/catalog-read.ts +56 -0
- package/src/registry/deprecated.test.ts +139 -0
- package/src/registry/deprecated.ts +76 -0
- package/src/registry/docs.test.ts +140 -0
- package/src/registry/docs.ts +299 -0
- package/src/registry/edge/bundle.test.ts +50 -0
- package/src/registry/edge/edge.test.ts +176 -0
- package/src/registry/edge/edge.ts +211 -0
- package/src/registry/edge/index.ts +10 -0
- package/src/registry/edge/lambda-edge.ts +127 -0
- package/src/registry/edge/sigv4-web.ts +79 -0
- package/src/registry/edge/token-source.test.ts +258 -0
- package/src/registry/edge/token-source.ts +169 -0
- package/src/registry/edge/worker.ts +61 -0
- package/src/registry/handler.ts +89 -0
- package/src/registry/headers-file.ts +61 -0
- package/src/registry/index.ts +31 -0
- package/src/registry/mirror-paths.ts +10 -0
- package/src/registry/mirror.test.ts +198 -0
- package/src/registry/mirror.ts +395 -0
- package/src/registry/proxies.test.ts +153 -0
- package/src/registry/proxies.ts +132 -0
- package/src/registry/reader.ts +225 -0
- package/src/registry/registry.test.ts +262 -0
- package/src/registry/semver.ts +34 -0
- package/src/registry/serve.ts +82 -0
- package/src/registry/source-forms.test.ts +87 -0
- package/src/registry/source-forms.ts +216 -0
- package/src/registry/targets/artifactory.test.ts +248 -0
- package/src/registry/targets/artifactory.ts +257 -0
- package/src/registry/targets/fake-artifactory.ts +158 -0
- package/src/registry/targets/fake-gitlab.ts +161 -0
- package/src/registry/targets/fake-hcp.ts +233 -0
- package/src/registry/targets/fake-http.ts +97 -0
- package/src/registry/targets/fake-nexus.ts +152 -0
- package/src/registry/targets/gitlab.test.ts +208 -0
- package/src/registry/targets/gitlab.ts +223 -0
- package/src/registry/targets/hcp.test.ts +230 -0
- package/src/registry/targets/hcp.ts +360 -0
- package/src/registry/targets/hosted.ts +117 -0
- package/src/registry/targets/index.ts +17 -0
- package/src/registry/targets/module-target.ts +131 -0
- package/src/registry/targets/nexus.test.ts +220 -0
- package/src/registry/targets/nexus.ts +314 -0
- package/src/registry/targets/zip.test.ts +65 -0
- package/src/registry/targets/zip.ts +287 -0
- package/src/registry/writer.ts +155 -0
- package/src/state/azure-blob.ts +6 -221
- package/src/state/gcs.ts +5 -252
- package/src/state/object-store.ts +4 -32
- package/src/state/s3.ts +10 -182
- package/src/state/store.ts +2 -2
- package/src/state-ops.test.ts +182 -0
- package/src/state-ops.ts +462 -0
- package/src/state-reads.ts +116 -0
- package/src/used-sources.test.ts +75 -0
- package/src/used-sources.ts +204 -0
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TF046: a live root's record store is local, and the lint runs in CI.
|
|
3
|
+
*
|
|
4
|
+
* A live root keeps its records (what binds a record-backed resource to the
|
|
5
|
+
* estate) in a record store. With nothing to say otherwise that store is a
|
|
6
|
+
* directory beside the module (choudoufu `live/STORAGE.md`), and on a CI
|
|
7
|
+
* runner the directory is empty on every run: an ordinary resource still binds
|
|
8
|
+
* by its marker, but a record-backed one is proposed for create again.
|
|
9
|
+
*
|
|
10
|
+
* "Local" is what choudoufu resolves, read here through `./record-store.ts`,
|
|
11
|
+
* the same resolution TF024 names in its message (INTENTIUS/choudoufu#2293):
|
|
12
|
+
*
|
|
13
|
+
* - an explicit `record_store "local"` fires;
|
|
14
|
+
* - an explicit `record_store` of any other kind is quiet, whatever backend
|
|
15
|
+
* sits beside it;
|
|
16
|
+
* - with no `record_store`, an ignored `backend "s3"`, `"gcs"` or `"azurerm"`
|
|
17
|
+
* block that names its bucket as a literal gives a derived store and is
|
|
18
|
+
* quiet;
|
|
19
|
+
* - with no `record_store` and no backend, or a backend with no counterpart
|
|
20
|
+
* (`local`, `consul`, `http`), or one whose bucket comes only from
|
|
21
|
+
* `-backend-config`, the store is implied local and the rule fires, naming
|
|
22
|
+
* the reason choudoufu would print.
|
|
23
|
+
*
|
|
24
|
+
* A root that is also a Terragrunt unit with a `remote_state`, a `generate`
|
|
25
|
+
* block that writes a backend, or an `include` of a parent config gets its
|
|
26
|
+
* backend file at run time, so what chant reads is not what choudoufu sees.
|
|
27
|
+
* The rule stays quiet there rather than guess; TF044 still reports a
|
|
28
|
+
* Terragrunt `backend = "local"`.
|
|
29
|
+
*
|
|
30
|
+
* CI is read from the environment chant runs in: `CI` set to anything but
|
|
31
|
+
* `false` or `0`, or `GITHUB_ACTIONS`, `GITLAB_CI`, `FORGEJO_ACTIONS`,
|
|
32
|
+
* `GITEA_ACTIONS` or `TF_BUILD` (Azure Pipelines) set to `true`. Outside CI the
|
|
33
|
+
* local store is a reasonable choice for one person or a demo, and the rule
|
|
34
|
+
* says nothing.
|
|
35
|
+
*
|
|
36
|
+
* Opt-outs, for emulator and test lanes that use the local store on purpose:
|
|
37
|
+
* `CHANT_ALLOW_LOCAL_RECORD_STORE=1` in the lane's environment, or
|
|
38
|
+
* `# chant-ignore-block: TF046` above the `terraform` block holding `live`
|
|
39
|
+
* for one root, or
|
|
40
|
+
* `lint.rules: { TF046: "off" }` for a whole project.
|
|
41
|
+
*
|
|
42
|
+
* The rule is `report-only` in the audit catalog, so it is off under the
|
|
43
|
+
* `recommended` preset: terragucci switches it on and holds the product
|
|
44
|
+
* wording (chant#4561 placement).
|
|
45
|
+
*
|
|
46
|
+
* One diagnostic per root. It fires from the `terraform` block that holds the
|
|
47
|
+
* `live` block, since suppression comments anchor on top-level blocks only,
|
|
48
|
+
* and from the sidecar's `Terraform::Live` entity for a sidecar estate, where
|
|
49
|
+
* `# chant-ignore-file: TF046` in `estate.chdf.hcl` suppresses it.
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
import type {
|
|
53
|
+
PostSynthCheck,
|
|
54
|
+
PostSynthContext,
|
|
55
|
+
PostSynthDiagnostic,
|
|
56
|
+
} from "@intentius/chant/lint/post-synth";
|
|
57
|
+
import { isResourceDeclarable, type ResourceDeclarable } from "@intentius/chant/declarable";
|
|
58
|
+
import {
|
|
59
|
+
LIVE_TYPE,
|
|
60
|
+
TERRAFORM_TYPE,
|
|
61
|
+
TERRAGRUNT_CONFIG_TYPE,
|
|
62
|
+
TERRAGRUNT_GENERATE_TYPE,
|
|
63
|
+
TERRAGRUNT_REMOTE_STATE_TYPE,
|
|
64
|
+
type BlockBody,
|
|
65
|
+
} from "../../hcl/parse";
|
|
66
|
+
import { isRootScoped } from "./scope";
|
|
67
|
+
import { resolveRecordStore, type ResolvedRecordStore } from "./record-store";
|
|
68
|
+
|
|
69
|
+
/** The environment variable an emulator or test lane sets to keep the local store without a finding. */
|
|
70
|
+
export const ALLOW_LOCAL_RECORD_STORE_ENV = "CHANT_ALLOW_LOCAL_RECORD_STORE";
|
|
71
|
+
|
|
72
|
+
type Env = Readonly<Record<string, string | undefined>>;
|
|
73
|
+
|
|
74
|
+
const truthy = (v: string | undefined): boolean => v !== undefined && v !== "" && v !== "0" && v.toLowerCase() !== "false";
|
|
75
|
+
|
|
76
|
+
/** Whether the environment is a CI job. */
|
|
77
|
+
export function isCiEnvironment(env: Env): boolean {
|
|
78
|
+
if (truthy(env.CI)) return true;
|
|
79
|
+
for (const name of ["GITHUB_ACTIONS", "GITLAB_CI", "FORGEJO_ACTIONS", "GITEA_ACTIONS", "TF_BUILD"]) {
|
|
80
|
+
if (env[name]?.toLowerCase() === "true") return true;
|
|
81
|
+
}
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const bodyOf = (entity: ResourceDeclarable): BlockBody => {
|
|
86
|
+
const props = entity.props as { body?: unknown };
|
|
87
|
+
return (typeof props.body === "object" && props.body !== null ? props.body : {}) as BlockBody;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const rootOf = (entity: ResourceDeclarable): string => {
|
|
91
|
+
const root = (entity.props as { root?: unknown }).root;
|
|
92
|
+
return typeof root === "string" ? root : "";
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
interface LiveRoot {
|
|
96
|
+
/** Entity key the finding anchors on: the live declaration's entity, until a `terraform` block holding it is seen. */
|
|
97
|
+
anchor: string;
|
|
98
|
+
liveBodies: BlockBody[];
|
|
99
|
+
terraformBodies: BlockBody[];
|
|
100
|
+
/** A Terragrunt unit whose backend file is written at run time. */
|
|
101
|
+
runtimeBackend: boolean;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Whether a Terragrunt block in this root writes a backend file at run time. */
|
|
105
|
+
function writesRuntimeBackend(entity: ResourceDeclarable): boolean {
|
|
106
|
+
const body = bodyOf(entity);
|
|
107
|
+
switch (entity.entityType) {
|
|
108
|
+
case TERRAGRUNT_REMOTE_STATE_TYPE:
|
|
109
|
+
return body.backend !== "local";
|
|
110
|
+
case TERRAGRUNT_GENERATE_TYPE: {
|
|
111
|
+
const contents = typeof body.contents === "string" ? body.contents : "";
|
|
112
|
+
return /\bbackend\s+"(?!local")/.test(contents);
|
|
113
|
+
}
|
|
114
|
+
case TERRAGRUNT_CONFIG_TYPE:
|
|
115
|
+
return Array.isArray(body.includes) && body.includes.length > 0;
|
|
116
|
+
default:
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function liveRoots(ctx: PostSynthContext): Map<string, LiveRoot> {
|
|
122
|
+
const roots = new Map<string, LiveRoot>();
|
|
123
|
+
const terraform = new Map<string, BlockBody[]>();
|
|
124
|
+
/** Per root, the key of the first `terraform` block that holds a `live` block. */
|
|
125
|
+
const holder = new Map<string, string>();
|
|
126
|
+
const runtime = new Set<string>();
|
|
127
|
+
|
|
128
|
+
for (const [key, entity] of ctx.entities) {
|
|
129
|
+
if (!isResourceDeclarable(entity) || !isRootScoped(entity)) continue;
|
|
130
|
+
const root = rootOf(entity);
|
|
131
|
+
if (entity.entityType === TERRAFORM_TYPE) {
|
|
132
|
+
const list = terraform.get(root) ?? [];
|
|
133
|
+
const body = bodyOf(entity);
|
|
134
|
+
list.push(body);
|
|
135
|
+
terraform.set(root, list);
|
|
136
|
+
if (body.live !== undefined && !holder.has(root)) holder.set(root, key);
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
if (entity.entityType === LIVE_TYPE) {
|
|
140
|
+
if ((entity.props as { mode?: unknown }).mode !== "live") continue;
|
|
141
|
+
const found = roots.get(root);
|
|
142
|
+
if (found) found.liveBodies.push(bodyOf(entity));
|
|
143
|
+
else roots.set(root, { anchor: key, liveBodies: [bodyOf(entity)], terraformBodies: [], runtimeBackend: false });
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (writesRuntimeBackend(entity)) runtime.add(root);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
for (const [root, live] of roots) {
|
|
150
|
+
live.terraformBodies = terraform.get(root) ?? [];
|
|
151
|
+
live.anchor = holder.get(root) ?? live.anchor;
|
|
152
|
+
live.runtimeBackend = runtime.has(root);
|
|
153
|
+
}
|
|
154
|
+
return roots;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function message(root: string, store: ResolvedRecordStore): string {
|
|
158
|
+
const why =
|
|
159
|
+
store.source === "record_store"
|
|
160
|
+
? 'Its live declaration names record_store "local", a directory beside the module.'
|
|
161
|
+
: store.note
|
|
162
|
+
? `It declares no record_store, and no store is derived from its backend: ${store.note}.`
|
|
163
|
+
: store.backend
|
|
164
|
+
? `It declares no record_store, and its backend "${store.backend}" block keeps state on local disk, so choudoufu uses the local store.`
|
|
165
|
+
: "It declares no record_store and has no backend block to derive one from, so choudoufu uses the local store.";
|
|
166
|
+
return (
|
|
167
|
+
`Live root "${root}" keeps its records in the local store, and this is a CI run. ${why} ` +
|
|
168
|
+
"A CI runner starts with an empty directory every run, so each record-backed resource is proposed " +
|
|
169
|
+
"for create again. Keep or add a backend \"s3\", \"gcs\" or \"azurerm\" block with a literal bucket " +
|
|
170
|
+
"(choudoufu derives the store from it), or declare a record_store in the live block or " +
|
|
171
|
+
`estate.chdf.hcl. A lane that uses the local store on purpose sets ${ALLOW_LOCAL_RECORD_STORE_ENV}=1.`
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* TF046 against an explicit environment. `tf046.check` passes `process.env`;
|
|
177
|
+
* tests pass their own.
|
|
178
|
+
*/
|
|
179
|
+
export function checkLocalRecordStore(ctx: PostSynthContext, env: Env): PostSynthDiagnostic[] {
|
|
180
|
+
if (!isCiEnvironment(env) || truthy(env[ALLOW_LOCAL_RECORD_STORE_ENV])) return [];
|
|
181
|
+
const diagnostics: PostSynthDiagnostic[] = [];
|
|
182
|
+
for (const [root, live] of liveRoots(ctx)) {
|
|
183
|
+
if (live.runtimeBackend) continue;
|
|
184
|
+
const store = resolveRecordStore(live.terraformBodies, live.liveBodies);
|
|
185
|
+
if (store.kind !== "local") continue;
|
|
186
|
+
diagnostics.push({
|
|
187
|
+
checkId: "TF046",
|
|
188
|
+
severity: "error",
|
|
189
|
+
message: message(root, store),
|
|
190
|
+
entity: live.anchor,
|
|
191
|
+
lexicon: "terraform",
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
return diagnostics;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export const tf046: PostSynthCheck = {
|
|
198
|
+
id: "TF046",
|
|
199
|
+
description: "Live root resolves to the local record store in a CI run",
|
|
200
|
+
|
|
201
|
+
check(ctx: PostSynthContext): PostSynthDiagnostic[] {
|
|
202
|
+
return checkLocalRecordStore(ctx, process.env);
|
|
203
|
+
},
|
|
204
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { dirname, join } from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { describe, expect, test } from "vitest";
|
|
4
|
+
import type { PostSynthContext } from "@intentius/chant/lint/post-synth";
|
|
5
|
+
import { parseTerraformRootDir } from "../../hcl/parse";
|
|
6
|
+
import { terraformPlugin } from "../../plugin";
|
|
7
|
+
import { tf047 } from "./tf047";
|
|
8
|
+
|
|
9
|
+
const fixtures = join(dirname(fileURLToPath(import.meta.url)), "fixtures", "TF047");
|
|
10
|
+
|
|
11
|
+
async function ctxFor(fixture: string, binary: "choudoufu" | "terraform" = "choudoufu"): Promise<PostSynthContext> {
|
|
12
|
+
const entities = await parseTerraformRootDir(join(fixtures, fixture), "estate", undefined, { binary });
|
|
13
|
+
return { outputs: new Map(), entities } as unknown as PostSynthContext;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
describe("TF047: live root pins a module version the catalog has no row for, or one with refusals", () => {
|
|
17
|
+
test("warns on a version whose static rows are refused, with IDs, links and the tier", async () => {
|
|
18
|
+
const diags = tf047.check(await ctxFor("refused"));
|
|
19
|
+
expect(diags).toHaveLength(1);
|
|
20
|
+
expect(diags[0]).toMatchObject({ checkId: "TF047", severity: "warning", entity: "estate/module.eks" });
|
|
21
|
+
expect(diags[0].message).toContain("terraform-aws-modules/eks/aws 21.29.0");
|
|
22
|
+
expect(diags[0].message).toContain("6 of 6 examples");
|
|
23
|
+
expect(diags[0].message).toContain("static tier");
|
|
24
|
+
expect(diags[0].message).toContain("https://github.com/INTENTIUS/choudoufu/blob/main/live/LIMITATIONS.md#");
|
|
25
|
+
expect(diags[0].message).not.toMatch(/gauntlet/i);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test("is quiet when every example at the version is clear", async () => {
|
|
29
|
+
expect(tf047.check(await ctxFor("clear"))).toEqual([]);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test("reports a version with no row at info, naming the measured versions", async () => {
|
|
33
|
+
const diags = tf047.check(await ctxFor("unknown-version"));
|
|
34
|
+
expect(diags).toHaveLength(1);
|
|
35
|
+
expect(diags[0].severity).toBe("info");
|
|
36
|
+
expect(diags[0].message).toContain("no row at this version");
|
|
37
|
+
expect(diags[0].message).toContain("6.6.1");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("reports a module with no row at info", async () => {
|
|
41
|
+
const diags = tf047.check(await ctxFor("unknown-module"));
|
|
42
|
+
expect(diags).toHaveLength(1);
|
|
43
|
+
expect(diags[0].severity).toBe("info");
|
|
44
|
+
expect(diags[0].message).toContain("no row for this module");
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("skips a stock root: the table measures choudoufu", async () => {
|
|
48
|
+
expect(tf047.check(await ctxFor("refused", "terraform"))).toEqual([]);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("is off by default: in the all preset, not in recommended", () => {
|
|
52
|
+
const presets = terraformPlugin.lintPresets!();
|
|
53
|
+
expect(presets.all).toContain("TF047");
|
|
54
|
+
expect(presets.recommended).not.toContain("TF047");
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TF047: a live root pins a registry module version the known-module catalog
|
|
3
|
+
* has no row for, or one whose row carries refusals.
|
|
4
|
+
*
|
|
5
|
+
* The catalog is choudoufu's module compatibility table, vendored in
|
|
6
|
+
* `../../module-catalog/` (chant#4560, choudoufu#2292). It has one static
|
|
7
|
+
* row per terraform-aws-modules example at one tag, measured offline in the
|
|
8
|
+
* onboarded form. A module call on a root whose binary is choudoufu (the
|
|
9
|
+
* root's `mode` is `live`) with an exact `version` is looked up there:
|
|
10
|
+
*
|
|
11
|
+
* - no row for the module, or none at the pinned version: `info`, naming the
|
|
12
|
+
* versions the static tier did measure;
|
|
13
|
+
* - at least one example at that version refused: `warning`, with each
|
|
14
|
+
* refusal ID, its site count, the examples that carry it and its
|
|
15
|
+
* `live/LIMITATIONS.md` link;
|
|
16
|
+
* - every example clear: quiet.
|
|
17
|
+
*
|
|
18
|
+
* Every message names the tier. The catalog holds the static tier only, and
|
|
19
|
+
* no figure here counts a gauntlet run (choudoufu#2292 ruling: two tiers,
|
|
20
|
+
* never mixed).
|
|
21
|
+
*
|
|
22
|
+
* A stock root (`mode: "state"`) is skipped: the table measures choudoufu.
|
|
23
|
+
* A range is TF039's finding and a missing `version` TF004's, so both are
|
|
24
|
+
* skipped here. A `//subdir` source is looked up by its module repository.
|
|
25
|
+
*
|
|
26
|
+
* Off by default: `report-only` in the audit catalog, as TF039 is.
|
|
27
|
+
* terragucci turns it on and holds the product wording (terragucci#1286).
|
|
28
|
+
*
|
|
29
|
+
* Scope: root and child modules of a live root alike.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
import type {
|
|
33
|
+
PostSynthCheck,
|
|
34
|
+
PostSynthContext,
|
|
35
|
+
PostSynthDiagnostic,
|
|
36
|
+
} from "@intentius/chant/lint/post-synth";
|
|
37
|
+
import { isResourceDeclarable } from "@intentius/chant/declarable";
|
|
38
|
+
import { MODULE_TYPE, type BlockBody } from "../../hcl/parse";
|
|
39
|
+
import { classifyModuleSource, isExactVersionConstraint } from "./module-source";
|
|
40
|
+
import {
|
|
41
|
+
MODULE_CATALOG_SOURCE,
|
|
42
|
+
MODULE_COMPATIBILITY_PAGE,
|
|
43
|
+
moduleCompatibility,
|
|
44
|
+
type ModuleCompatibility,
|
|
45
|
+
} from "../../module-catalog";
|
|
46
|
+
|
|
47
|
+
const tierNote = (): string =>
|
|
48
|
+
`static tier of choudoufu's module table, measured ${MODULE_CATALOG_SOURCE.date} with hashicorp/aws ${MODULE_CATALOG_SOURCE.awsProvider}`;
|
|
49
|
+
|
|
50
|
+
/** The TF047 message for one module call, or undefined when the call is clear. */
|
|
51
|
+
export function catalogMessage(address: string, c: ModuleCompatibility): string | undefined {
|
|
52
|
+
const pin = `${c.module} ${c.version}`;
|
|
53
|
+
switch (c.status) {
|
|
54
|
+
case "clear":
|
|
55
|
+
return undefined;
|
|
56
|
+
case "unknown-module":
|
|
57
|
+
return (
|
|
58
|
+
`Module "${address}" pins ${pin}, and the ${tierNote()} has no row for this module. ` +
|
|
59
|
+
`Run \`choudoufu live-check\` on the root to see whether it plans. The table: ${MODULE_COMPATIBILITY_PAGE}`
|
|
60
|
+
);
|
|
61
|
+
case "unknown-version":
|
|
62
|
+
return (
|
|
63
|
+
`Module "${address}" pins ${pin}, and the ${tierNote()} has no row at this version. ` +
|
|
64
|
+
`It measured ${c.measuredVersions.join(", ")}. ` +
|
|
65
|
+
`Run \`choudoufu live-check\` on the root, or pin a measured version. The table: ${MODULE_COMPATIBILITY_PAGE}`
|
|
66
|
+
);
|
|
67
|
+
case "refused": {
|
|
68
|
+
const ids = c.refusals
|
|
69
|
+
.map((r) => `${r.id} (${r.sites} site${r.sites === 1 ? "" : "s"} in ${r.examples.join(", ")}; ${r.docsUrl})`)
|
|
70
|
+
.join("; ");
|
|
71
|
+
return (
|
|
72
|
+
`Module "${address}" pins ${pin}. In the ${tierNote()}, ${c.refusedExamples} of ${c.examples} ` +
|
|
73
|
+
`examples at this version are refused: ${ids}. ` +
|
|
74
|
+
"A call that uses the same features is refused the same way; `choudoufu live-check` names each site in this root."
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export const tf047: PostSynthCheck = {
|
|
81
|
+
id: "TF047",
|
|
82
|
+
description: "Live root pins a module version the known-module catalog has no row for, or one with refusals",
|
|
83
|
+
|
|
84
|
+
check(ctx: PostSynthContext): PostSynthDiagnostic[] {
|
|
85
|
+
const diagnostics: PostSynthDiagnostic[] = [];
|
|
86
|
+
|
|
87
|
+
for (const [key, entity] of ctx.entities) {
|
|
88
|
+
if (entity.entityType !== MODULE_TYPE || !isResourceDeclarable(entity)) continue;
|
|
89
|
+
const props = entity.props as { address?: unknown; body?: unknown; mode?: unknown };
|
|
90
|
+
if (props.mode !== "live") continue;
|
|
91
|
+
const body = (typeof props.body === "object" && props.body !== null ? props.body : {}) as BlockBody;
|
|
92
|
+
const source = typeof body.source === "string" ? body.source : undefined;
|
|
93
|
+
if (source === undefined || classifyModuleSource(source).kind !== "registry") continue;
|
|
94
|
+
const version = body.version;
|
|
95
|
+
if (typeof version !== "string" || !isExactVersionConstraint(version)) continue;
|
|
96
|
+
|
|
97
|
+
const compat = moduleCompatibility(source, version);
|
|
98
|
+
if (compat === undefined) continue;
|
|
99
|
+
const address = typeof props.address === "string" ? props.address : key;
|
|
100
|
+
const message = catalogMessage(address, compat);
|
|
101
|
+
if (message === undefined) continue;
|
|
102
|
+
|
|
103
|
+
diagnostics.push({
|
|
104
|
+
checkId: "TF047",
|
|
105
|
+
severity: compat.status === "refused" ? "warning" : "info",
|
|
106
|
+
message,
|
|
107
|
+
entity: key,
|
|
108
|
+
lexicon: "terraform",
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return diagnostics;
|
|
113
|
+
},
|
|
114
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #4552: a choudoufu root's rows keep terragucci's format (`planRows` in
|
|
3
|
+
* terragucci's apply-rows.ts), and Terraform, tofu and Terragrunt keep the
|
|
4
|
+
* target grain and refuse the resource grain by name.
|
|
5
|
+
*/
|
|
6
|
+
import { describe, expect, test } from "vitest";
|
|
7
|
+
import type { ChangeSetPart } from "@intentius/chant/change-set";
|
|
8
|
+
import { terraformDefaultLockGrain, terraformLockGrainRefusal, terraformLockRows, terraformLockRowsFromPart } from "./lock-rows";
|
|
9
|
+
|
|
10
|
+
const plan = {
|
|
11
|
+
resource_changes: [
|
|
12
|
+
{ address: "aws_s3_bucket.logs", mode: "managed", change: { actions: ["update"], before: { id: "logs-1" } } },
|
|
13
|
+
{ address: "aws_sqs_queue.jobs", mode: "managed", change: { actions: ["create"], before: null } },
|
|
14
|
+
{ address: "aws_iam_role.app", previous_address: "aws_iam_role.old", mode: "managed", change: { actions: ["no-op"], before: { id: "app" } } },
|
|
15
|
+
{ address: "aws_iam_role.svc", previous_address: "aws_iam_role.legacy", mode: "managed", change: { actions: ["delete", "create"], before: { id: "svc" } } },
|
|
16
|
+
{ address: "data.aws_caller_identity.me", mode: "data", change: { actions: ["read"] } },
|
|
17
|
+
],
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
describe("terraformLockRows", () => {
|
|
21
|
+
test("estate rows, the previous address of a moved instance, and object rows for anything but a create", () => {
|
|
22
|
+
expect(terraformLockRows("net", "e01", plan).map((r) => r.key)).toEqual([
|
|
23
|
+
"estate e01 aws_iam_role.legacy",
|
|
24
|
+
"estate e01 aws_iam_role.svc",
|
|
25
|
+
"estate e01 aws_s3_bucket.logs",
|
|
26
|
+
"estate e01 aws_sqs_queue.jobs",
|
|
27
|
+
"object logs-1",
|
|
28
|
+
"object svc",
|
|
29
|
+
]);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test("a root with no estate is keyed by its path", () => {
|
|
33
|
+
expect(terraformLockRows("live/net", undefined, plan).map((r) => r.key)).toEqual([
|
|
34
|
+
"object logs-1",
|
|
35
|
+
"object svc",
|
|
36
|
+
"root live/net aws_iam_role.legacy",
|
|
37
|
+
"root live/net aws_iam_role.svc",
|
|
38
|
+
"root live/net aws_s3_bucket.logs",
|
|
39
|
+
"root live/net aws_sqs_queue.jobs",
|
|
40
|
+
]);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test("from a change-set part: the same keys less the previous address", () => {
|
|
44
|
+
const part: ChangeSetPart = {
|
|
45
|
+
member: { member: "net", lexicon: "terraform", planner: "choudoufu", scope: "e01", status: "planned", planDigest: "sha256:x", holes: [] },
|
|
46
|
+
entries: [
|
|
47
|
+
{ member: "net", lexicon: "terraform", planner: "choudoufu", address: "aws_s3_bucket.logs", type: "aws_s3_bucket", id: "logs-1", action: "update", attributes: [] },
|
|
48
|
+
{ member: "net", lexicon: "terraform", planner: "choudoufu", address: "aws_sqs_queue.jobs", type: "aws_sqs_queue", action: "no-op", attributes: [] },
|
|
49
|
+
],
|
|
50
|
+
};
|
|
51
|
+
expect(terraformLockRowsFromPart("net", part).map((r) => r.key)).toEqual(["estate e01 aws_s3_bucket.logs", "object logs-1"]);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe("the grain", () => {
|
|
56
|
+
test("resource under choudoufu, the root under Terraform and tofu", () => {
|
|
57
|
+
expect(terraformDefaultLockGrain("choudoufu")).toBe("resource");
|
|
58
|
+
expect(terraformDefaultLockGrain("terraform")).toBe("target");
|
|
59
|
+
expect(terraformDefaultLockGrain("tofu")).toBe("target");
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("resource is refused by engine name off choudoufu; target and repo are not", () => {
|
|
63
|
+
expect(terraformLockGrainRefusal("resource", "choudoufu")).toBeUndefined();
|
|
64
|
+
expect(terraformLockGrainRefusal("resource", "terraform")).toMatch(/^Terraform keeps/);
|
|
65
|
+
expect(terraformLockGrainRefusal("resource", "tofu")).toMatch(/^tofu keeps/);
|
|
66
|
+
expect(terraformLockGrainRefusal("resource", "terraform", "/usr/local/bin/terragrunt")).toMatch(/^Terragrunt keeps/);
|
|
67
|
+
expect(terraformLockGrainRefusal("target", "terraform")).toBeUndefined();
|
|
68
|
+
expect(terraformLockGrainRefusal("repo", "tofu")).toBeUndefined();
|
|
69
|
+
});
|
|
70
|
+
});
|
package/src/lock-rows.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The terraform lexicon's lock grain (#4552) and the rows a choudoufu apply
|
|
3
|
+
* holds on the resource grain, in terragucci's format (`planRows` in
|
|
4
|
+
* terragucci's `apply-rows.ts` at 18f6431), unchanged:
|
|
5
|
+
*
|
|
6
|
+
* - `estate <estate> <address>` for every resource instance the apply acts
|
|
7
|
+
* on (a create, update, delete, replace or forget), or `root <root>
|
|
8
|
+
* <address>` when the root has no estate;
|
|
9
|
+
* - the same for `previous_address` on a moved instance;
|
|
10
|
+
* - `object <id>` for anything but a create, from the object's id before,
|
|
11
|
+
* so two estates that meet on one object meet on its row.
|
|
12
|
+
*
|
|
13
|
+
* Data reads and no-ops hold nothing.
|
|
14
|
+
*
|
|
15
|
+
* The grain: `resource` for choudoufu, which keeps one record per resource,
|
|
16
|
+
* writes each conditionally and refuses a plan one of whose changes moved;
|
|
17
|
+
* `target` (the root, or the Terragrunt unit) for Terraform, tofu and
|
|
18
|
+
* Terragrunt, whose state is one file the backend's lock keeps whole. Those
|
|
19
|
+
* three refuse `resource` by name, since nothing in their state is per
|
|
20
|
+
* resource.
|
|
21
|
+
*/
|
|
22
|
+
import type { ChangeSetPart, ChangeSetPlanner } from "@intentius/chant/change-set";
|
|
23
|
+
import { objectRowKey, sortedLockRows, type LockGrain, type LockRow } from "@intentius/chant/lifecycle/lock-rows";
|
|
24
|
+
|
|
25
|
+
const CHANGING = new Set(["create", "update", "delete", "forget"]);
|
|
26
|
+
|
|
27
|
+
/** The scope a root's rows are keyed in: its estate, else its path. */
|
|
28
|
+
function rowScope(root: string, estate: string | undefined): string {
|
|
29
|
+
return estate ? `estate ${estate}` : `root ${root}`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The rows a plan's changes key, from `show -json`'s `resource_changes` (terragucci's `planRows`). */
|
|
33
|
+
export function terraformLockRows(root: string, estate: string | undefined, plan: unknown): LockRow[] {
|
|
34
|
+
const scope = rowScope(root, estate);
|
|
35
|
+
const rows: LockRow[] = [];
|
|
36
|
+
const changes = (plan as { resource_changes?: unknown[] } | undefined)?.resource_changes ?? [];
|
|
37
|
+
for (const c of changes as Array<Record<string, any>>) {
|
|
38
|
+
if (c?.mode === "data" || typeof c?.address !== "string") continue;
|
|
39
|
+
const actions: string[] = Array.isArray(c.change?.actions) ? c.change.actions : [];
|
|
40
|
+
if (!actions.some((a) => CHANGING.has(a))) continue;
|
|
41
|
+
const address = c.address as string;
|
|
42
|
+
rows.push({ key: `${scope} ${address}`, target: root, address });
|
|
43
|
+
if (typeof c.previous_address === "string" && c.previous_address !== address) rows.push({ key: `${scope} ${c.previous_address}`, target: root, address });
|
|
44
|
+
// The live object an update or a delete acts on: two estates that meet on one object meet here.
|
|
45
|
+
const id = c.change?.before?.id;
|
|
46
|
+
if (actions.some((a) => a !== "create") && (typeof id === "string" || typeof id === "number") && String(id) !== "") rows.push({ key: objectRowKey(String(id)), target: root, address });
|
|
47
|
+
}
|
|
48
|
+
return sortedLockRows(rows);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The rows from a member's change-set part, when the plan document is not
|
|
53
|
+
* at hand: the same keys, less the previous address of a moved instance,
|
|
54
|
+
* which the part does not carry. The part's `scope` is the estate.
|
|
55
|
+
*/
|
|
56
|
+
export function terraformLockRowsFromPart(root: string, part: ChangeSetPart): LockRow[] {
|
|
57
|
+
const scope = rowScope(root, part.member.planner === "choudoufu" ? part.member.scope : undefined);
|
|
58
|
+
const rows: LockRow[] = [];
|
|
59
|
+
for (const e of part.entries) {
|
|
60
|
+
if (e.action === "no-op" || e.action === "read") continue;
|
|
61
|
+
rows.push({ key: `${scope} ${e.address}`, target: root, address: e.address });
|
|
62
|
+
if (e.action !== "create" && e.id) rows.push({ key: objectRowKey(e.id), target: root, address: e.address });
|
|
63
|
+
}
|
|
64
|
+
return sortedLockRows(rows);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Whether a binary's name is Terragrunt's. */
|
|
68
|
+
function isTerragrunt(binary: string | undefined): boolean {
|
|
69
|
+
return /^terragrunt(\.exe)?$/.test((binary ?? "").split(/[\\/]/).pop() ?? "");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** The grain a root takes by default: `resource` under choudoufu, `target` under every other binary. */
|
|
73
|
+
export function terraformDefaultLockGrain(planner: ChangeSetPlanner | undefined): LockGrain {
|
|
74
|
+
return planner === "choudoufu" ? "resource" : "target";
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Why a root cannot take `grain`, by engine name, or undefined when it can. */
|
|
78
|
+
export function terraformLockGrainRefusal(grain: LockGrain, planner: ChangeSetPlanner | undefined, binary?: string): string | undefined {
|
|
79
|
+
if (grain !== "resource" || planner === "choudoufu") return undefined;
|
|
80
|
+
const engine = isTerragrunt(binary) ? "Terragrunt" : planner === "tofu" ? "tofu" : "Terraform";
|
|
81
|
+
return `${engine} keeps a root's state in one file that its backend's lock keeps whole, so nothing in it is per resource; the resource grain needs choudoufu (ci.lockGrain: target)`;
|
|
82
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* State-lock waits for a plan or an apply (#4545): how long `plan` and
|
|
3
|
+
* `apply` wait for another run's state lock before failing. Taken from
|
|
4
|
+
* terragucci's waves, where two jobs of one pipeline can reach the same
|
|
5
|
+
* backend a moment apart and a failed lock fails the wave for nothing.
|
|
6
|
+
*
|
|
7
|
+
* A job that already sets `-lock-timeout` through `TF_CLI_ARGS` or
|
|
8
|
+
* `TF_CLI_ARGS_<command>` keeps its own: the flag is added only when neither
|
|
9
|
+
* names one. Terragrunt waves pass the same flag after `--`
|
|
10
|
+
* (`./terragrunt/wave.ts`, `extra`).
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** How long a plan or an apply waits for a state lock unless the job set a `-lock-timeout` of its own. */
|
|
14
|
+
export const DEFAULT_LOCK_TIMEOUT = "5m";
|
|
15
|
+
|
|
16
|
+
/** A duration terraform's `-lock-timeout` takes: `0s`, `30s`, `5m`, `1h30m`. */
|
|
17
|
+
const DURATION = /^(\d+(ms|s|m|h))+$/;
|
|
18
|
+
|
|
19
|
+
/** Whether `value` is a `-lock-timeout` duration. */
|
|
20
|
+
export function isLockTimeout(value: unknown): value is string {
|
|
21
|
+
return typeof value === "string" && DURATION.test(value);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The `-lock-timeout` flag a `command` takes: `-lock-timeout=<timeout>`, or
|
|
26
|
+
* nothing when `TF_CLI_ARGS` or `TF_CLI_ARGS_<command>` in `env` already
|
|
27
|
+
* names one, or `timeout` is `false`. Throws on a duration terraform refuses.
|
|
28
|
+
*/
|
|
29
|
+
export function lockTimeoutArgs(command: "plan" | "apply", timeout: string | false = DEFAULT_LOCK_TIMEOUT, env: Record<string, string | undefined> = process.env): string[] {
|
|
30
|
+
if (timeout === false) return [];
|
|
31
|
+
if (!isLockTimeout(timeout)) throw new Error(`lockTimeout "${timeout}" is not a duration terraform takes, such as "5m" or "30s"`);
|
|
32
|
+
const set = `${env.TF_CLI_ARGS ?? ""} ${env[`TF_CLI_ARGS_${command}`] ?? ""}`;
|
|
33
|
+
return /(^|\s)-{1,2}lock-timeout[=\s]/.test(set) ? [] : [`-lock-timeout=${timeout}`];
|
|
34
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
MODULE_CATALOG_SOURCE,
|
|
4
|
+
exactModuleVersion,
|
|
5
|
+
moduleCompatibility,
|
|
6
|
+
registryModuleAddress,
|
|
7
|
+
staticRows,
|
|
8
|
+
} from "./index";
|
|
9
|
+
import { renderStaticTier } from "./refresh-cli";
|
|
10
|
+
import { parseModuleCompat } from "./types";
|
|
11
|
+
import { SOURCE_COMMIT, STATIC_MEASUREMENT } from "./static-tier";
|
|
12
|
+
|
|
13
|
+
describe("known-module catalog (chant#4560)", () => {
|
|
14
|
+
test("vendors the static tier only, with its source commit", () => {
|
|
15
|
+
expect(MODULE_CATALOG_SOURCE.path).toBe("live/module-compat.json");
|
|
16
|
+
expect(MODULE_CATALOG_SOURCE.commit).toMatch(/^[0-9a-f]{40}$/);
|
|
17
|
+
expect(staticRows.length).toBeGreaterThan(0);
|
|
18
|
+
expect(staticRows.every((r) => r.tier === "static")).toBe(true);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test("every vendored row passes the refresh check", () => {
|
|
22
|
+
expect(() =>
|
|
23
|
+
parseModuleCompat({ schema: 1, static_measurement: STATIC_MEASUREMENT, static: [...staticRows] }),
|
|
24
|
+
).not.toThrow();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test("the vendored file is what the refresh script writes", () => {
|
|
28
|
+
const rendered = renderStaticTier(SOURCE_COMMIT, STATIC_MEASUREMENT, staticRows);
|
|
29
|
+
expect(rendered).toContain(`at commit\n// ${SOURCE_COMMIT}`);
|
|
30
|
+
expect(rendered).toContain("static tier only");
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test("refuses a row whose verdict disagrees with its refusals", () => {
|
|
34
|
+
const row = { ...staticRows[0], verdict: "refused" as const, refusals: [] };
|
|
35
|
+
expect(() => parseModuleCompat({ schema: 1, static_measurement: STATIC_MEASUREMENT, static: [row] })).toThrow(
|
|
36
|
+
/refused with 0 refusals/,
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test.each([
|
|
41
|
+
["terraform-aws-modules/vpc/aws", "terraform-aws-modules/vpc/aws"],
|
|
42
|
+
["registry.terraform.io/terraform-aws-modules/vpc/aws", "terraform-aws-modules/vpc/aws"],
|
|
43
|
+
["terraform-aws-modules/iam/aws//modules/iam-role", "terraform-aws-modules/iam/aws"],
|
|
44
|
+
["./modules/vpc", undefined],
|
|
45
|
+
["git::https://example.com/vpc.git?ref=v1", undefined],
|
|
46
|
+
])("registryModuleAddress(%s)", (source, want) => {
|
|
47
|
+
expect(registryModuleAddress(source)).toBe(want);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test.each([
|
|
51
|
+
["1.4.0", "1.4.0"],
|
|
52
|
+
["= 1.4.0", "1.4.0"],
|
|
53
|
+
["v1.4.0", "1.4.0"],
|
|
54
|
+
["~> 1.4", undefined],
|
|
55
|
+
])("exactModuleVersion(%s)", (version, want) => {
|
|
56
|
+
expect(exactModuleVersion(version)).toBe(want);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test("a clear version", () => {
|
|
60
|
+
expect(moduleCompatibility("terraform-aws-modules/sqs/aws", "5.2.2")).toMatchObject({
|
|
61
|
+
tier: "static",
|
|
62
|
+
status: "clear",
|
|
63
|
+
examples: 1,
|
|
64
|
+
clearExamples: 1,
|
|
65
|
+
refusedExamples: 0,
|
|
66
|
+
refusals: [],
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test("a refused version sums sites per refusal ID and lists its examples", () => {
|
|
71
|
+
const c = moduleCompatibility("terraform-aws-modules/eks/aws", "= 21.29.0")!;
|
|
72
|
+
expect(c.status).toBe("refused");
|
|
73
|
+
expect(c.refusedExamples).toBe(c.examples);
|
|
74
|
+
expect(c.refusals.length).toBeGreaterThan(0);
|
|
75
|
+
for (const r of c.refusals) {
|
|
76
|
+
expect(r.sites).toBeGreaterThan(0);
|
|
77
|
+
expect(r.examples.length).toBeGreaterThan(0);
|
|
78
|
+
expect(r.docsUrl).toMatch(/LIMITATIONS\.md#/);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("unknown module and unknown version", () => {
|
|
83
|
+
expect(moduleCompatibility("cloudposse/label/null", "0.25.0")?.status).toBe("unknown-module");
|
|
84
|
+
const v = moduleCompatibility("terraform-aws-modules/vpc/aws", "5.0.0")!;
|
|
85
|
+
expect(v.status).toBe("unknown-version");
|
|
86
|
+
expect(v.measuredVersions).toContain("6.6.1");
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test("a range or a non-registry source has no answer", () => {
|
|
90
|
+
expect(moduleCompatibility("terraform-aws-modules/vpc/aws", "~> 6.0")).toBeUndefined();
|
|
91
|
+
expect(moduleCompatibility("./modules/vpc", "1.0.0")).toBeUndefined();
|
|
92
|
+
});
|
|
93
|
+
});
|