@intentius/chant-lexicon-terraform 0.124.87 → 0.124.89

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.
Files changed (82) hide show
  1. package/dist/action-ops.d.ts.map +1 -1
  2. package/dist/action-ops.js +3 -1
  3. package/dist/chant-floors.d.ts +30 -0
  4. package/dist/chant-floors.d.ts.map +1 -0
  5. package/dist/chant-floors.js +29 -0
  6. package/dist/components/capability-plugin.d.ts +15 -1
  7. package/dist/components/capability-plugin.d.ts.map +1 -1
  8. package/dist/components/capability-plugin.js +13 -5
  9. package/dist/components/compose-group.d.ts +5 -1
  10. package/dist/components/compose-group.d.ts.map +1 -1
  11. package/dist/components/compose-group.js +7 -4
  12. package/dist/engine-runner.d.ts +86 -0
  13. package/dist/engine-runner.d.ts.map +1 -0
  14. package/dist/engine-runner.js +134 -0
  15. package/dist/engine-timings.d.ts +249 -0
  16. package/dist/engine-timings.d.ts.map +1 -0
  17. package/dist/engine-timings.js +569 -0
  18. package/dist/integrity.json +2 -2
  19. package/dist/live-roots.d.ts +143 -0
  20. package/dist/live-roots.d.ts.map +1 -0
  21. package/dist/live-roots.js +304 -0
  22. package/dist/manifest.json +1 -1
  23. package/dist/migration-history.d.ts +105 -0
  24. package/dist/migration-history.d.ts.map +1 -0
  25. package/dist/migration-history.js +159 -0
  26. package/dist/module-catalog/index.d.ts +1 -0
  27. package/dist/module-catalog/index.d.ts.map +1 -1
  28. package/dist/module-catalog/index.js +3 -1
  29. package/dist/op/activities/live-detect.d.ts +15 -0
  30. package/dist/op/activities/live-detect.d.ts.map +1 -1
  31. package/dist/op/activities/live-detect.js +94 -0
  32. package/dist/op/activities/terraform.d.ts +1 -65
  33. package/dist/op/activities/terraform.d.ts.map +1 -1
  34. package/dist/op/activities/terraform.js +4 -54
  35. package/dist/op/command-hook.d.ts +98 -0
  36. package/dist/op/command-hook.d.ts.map +1 -0
  37. package/dist/op/command-hook.js +115 -0
  38. package/dist/registry/index.d.ts +1 -0
  39. package/dist/registry/index.d.ts.map +1 -1
  40. package/dist/registry/index.js +1 -0
  41. package/dist/state/exec.d.ts +23 -0
  42. package/dist/state/exec.d.ts.map +1 -1
  43. package/dist/state/exec.js +38 -0
  44. package/dist/state-ops.d.ts.map +1 -1
  45. package/dist/state-ops.js +3 -1
  46. package/dist/terragrunt/index.d.ts +3 -1
  47. package/dist/terragrunt/index.d.ts.map +1 -1
  48. package/dist/terragrunt/index.js +3 -1
  49. package/dist/terragrunt/place.d.ts +27 -0
  50. package/dist/terragrunt/place.d.ts.map +1 -0
  51. package/dist/terragrunt/place.js +52 -0
  52. package/dist/terragrunt/run.d.ts +23 -0
  53. package/dist/terragrunt/run.d.ts.map +1 -1
  54. package/dist/terragrunt/run.js +107 -3
  55. package/package.json +2 -2
  56. package/src/action-ops.ts +3 -1
  57. package/src/chant-floors.ts +32 -0
  58. package/src/components/capability-plugin.ts +27 -6
  59. package/src/components/compose-group.test.ts +29 -0
  60. package/src/components/compose-group.ts +12 -5
  61. package/src/components/terraform-apply-command-hook.test.ts +43 -0
  62. package/src/engine-runner.test.ts +261 -0
  63. package/src/engine-runner.ts +191 -0
  64. package/src/engine-timings.test.ts +203 -0
  65. package/src/engine-timings.ts +718 -0
  66. package/src/live-record-store.test.ts +76 -0
  67. package/src/live-roots.test.ts +80 -0
  68. package/src/live-roots.ts +347 -0
  69. package/src/migration-history.test.ts +83 -0
  70. package/src/migration-history.ts +199 -0
  71. package/src/module-catalog/index.ts +4 -1
  72. package/src/op/activities/live-detect.ts +87 -0
  73. package/src/op/activities/terraform.ts +12 -111
  74. package/src/op/command-hook.ts +189 -0
  75. package/src/registry/index.ts +1 -0
  76. package/src/state/engine-env.test.ts +18 -0
  77. package/src/state/exec.ts +38 -0
  78. package/src/state-ops.ts +3 -1
  79. package/src/terragrunt/index.ts +3 -1
  80. package/src/terragrunt/place.test.ts +42 -0
  81. package/src/terragrunt/place.ts +75 -0
  82. package/src/terragrunt/run.ts +128 -4
@@ -0,0 +1,143 @@
1
+ import { type BucketReport, type BucketTarget } from "@intentius/chant/bucket-check";
2
+ import { type BinaryExec } from "./state/exec.js";
3
+ export { declaresLive, detectLiveEstate, estateOutputReads } from "./op/activities/live-detect.js";
4
+ /** The roots of `roots` (paths under `repo`) that keep their resources under choudoufu's live markers, in the order given. */
5
+ export declare function liveRoots(repo: string, roots: readonly string[], binary?: string): string[];
6
+ /** A root's estate, as its sidecar or `live` block names it, and the estates whose recorded outputs it reads. */
7
+ export declare function estateOf(dir: string, binary?: string): {
8
+ estate?: string;
9
+ reads: string[];
10
+ };
11
+ /** Where choudoufu's estate name came from: the live block, the configuration's tags, the backend key, or the root's path. */
12
+ export type EstateSource = "explicit" | "tags" | "backend_key" | "root_path" | "none";
13
+ /** The record store choudoufu resolved, as `live-check -json` prints it. */
14
+ export interface LiveStore {
15
+ /** `local`, `s3`, `gcs`, `azurerm` or `kubernetes`. */
16
+ kind: string;
17
+ /** The s3 or gcs bucket, `<account>/<container>` for azurerm, the namespace for kubernetes, the directory for local. */
18
+ bucket: string;
19
+ /** Where this estate's records go, with one trailing slash. */
20
+ prefix: string;
21
+ /** `record_store` (written by the author), `backend` (derived from the backend block) or `implied` (the local store). */
22
+ source: string;
23
+ /** `file:line` of the block that decided it. */
24
+ declaredAt?: string;
25
+ /** Why a backend that was there was not used. */
26
+ note?: string;
27
+ }
28
+ /** What choudoufu resolves for one root. */
29
+ export interface LiveSetup {
30
+ estate?: string;
31
+ estateSource: string;
32
+ store?: LiveStore;
33
+ }
34
+ /** The setup in a `live-check -json` document, or undefined when the document is not JSON or comes from a choudoufu that does not print `estate_source`. */
35
+ export declare function parseLiveSetup(stdout: string): LiveSetup | undefined;
36
+ /** Keep what choudoufu resolved for a root's directory, for the readers below. */
37
+ export declare function rememberLiveSetup(dir: string, setup: LiveSetup): void;
38
+ /** What choudoufu resolved for a root's directory in this process, if it was read. */
39
+ export declare function knownLiveSetup(dir: string): LiveSetup | undefined;
40
+ /** For tests: forget every setup read so far. */
41
+ export declare function forgetLiveSetups(): void;
42
+ /**
43
+ * `choudoufu live-check -json <dir>` for one root, run in the directory, and
44
+ * the setup it prints, remembered for the process. Undefined when the binary
45
+ * prints none (an older release, a root it cannot read, or no binary at
46
+ * all); the caller then reads the files. A root that live-check blocks still
47
+ * prints its setup, so the exit code is not read.
48
+ */
49
+ export declare function readLiveSetup(dir: string, options?: {
50
+ binary?: string;
51
+ exec?: BinaryExec;
52
+ env?: NodeJS.ProcessEnv;
53
+ }): Promise<LiveSetup | undefined>;
54
+ /** A live root's estate: choudoufu's resolved name when it was read, else the name its files write. */
55
+ export declare function resolvedEstate(dir: string, binary?: string): string | undefined;
56
+ /**
57
+ * Where a live root's records are, for a product that lists them
58
+ * (chant#4954): an S3 bucket, a directory, or a store it does not read
59
+ * (`name` is its kind). `prefix` has one trailing slash.
60
+ */
61
+ export type RecordStore = {
62
+ kind: "s3";
63
+ bucket: string;
64
+ prefix: string;
65
+ region?: string;
66
+ } | {
67
+ kind: "local";
68
+ dir: string;
69
+ prefix: string;
70
+ } | {
71
+ kind: "unread";
72
+ name: string;
73
+ };
74
+ /**
75
+ * The text of a root's `live` block, comments blanked: its `estate.chdf.hcl`
76
+ * sidecar whole, else the `live` block in a `terraform` block of its HCL
77
+ * files. Undefined when it has neither.
78
+ */
79
+ export declare function liveBlockText(dir: string, binary?: string): string | undefined;
80
+ /**
81
+ * The record store a live root's files write for `estate` (chant#4954): the
82
+ * `record_store "<kind>"` block in its `live` block or sidecar, its
83
+ * `key_prefix` (default `tofu-records/<estate>/`), an s3 store's `bucket` and
84
+ * `region`, a local store's `path` (default `.tofu-records`, beside the
85
+ * root). No `record_store` block is the local store. Undefined when the root
86
+ * has no live block. Lifted from terragucci's `recordStoreOf`
87
+ * (cdf-records.ts).
88
+ */
89
+ export declare function writtenRecordStore(dir: string, estate: string, binary?: string): RecordStore | undefined;
90
+ /**
91
+ * The string attributes of a root's backend block as its code writes them
92
+ * (chant#4954), for the bucket check's s3 region and azurerm subscription
93
+ * and resource group. Empty for a `cloud` block or no backend. Read with
94
+ * {@link declaredBackend}, without the job's `-backend-config` flags.
95
+ */
96
+ export declare function rootBackendAttrs(dir: string, binary?: string): Record<string, string>;
97
+ /**
98
+ * A live root's record store (chant#4954): choudoufu's resolved store when
99
+ * {@link readLiveSetup} read it for the root, else the one its files write
100
+ * ({@link writtenRecordStore}). An s3 store's region, which `live-check
101
+ * -json` does not print, comes from the `record_store` block, else the
102
+ * backend block. Undefined when the root has no live block. Lifted from
103
+ * terragucci's `resolvedRecordStore` (live-setup.ts).
104
+ */
105
+ export declare function liveRecordStore(dir: string, estate: string, binary?: string): RecordStore | undefined;
106
+ /** The store as one phrase: `s3 bucket "acme" under tofu-records/prod/`. */
107
+ export declare function storePhrase(s: LiveStore): string;
108
+ /** A root's setup on one line: where its records go, where that came from, and its estate. */
109
+ export declare function setupLine(root: string, setup: LiveSetup): string;
110
+ /** The setup's store is the local directory, which is empty on every CI run. */
111
+ export declare const onLocalStore: (setup: LiveSetup) => boolean;
112
+ /**
113
+ * The bucket core's check reads for a resolved store, or why there is none.
114
+ * `backend` is the root's backend block's string attributes, for the s3
115
+ * region and the azurerm subscription and resource group. s3 takes the
116
+ * region from there or the job, and an emulator's endpoint and keys from the
117
+ * job; gcs an emulator from `STORAGE_EMULATOR_HOST`; azurerm needs the
118
+ * subscription and resource group, from the backend block or
119
+ * `ARM_SUBSCRIPTION_ID`.
120
+ */
121
+ export declare function bucketTarget(s: LiveStore, backend?: Record<string, string>, env?: NodeJS.ProcessEnv): {
122
+ target: BucketTarget;
123
+ } | {
124
+ skip: string;
125
+ };
126
+ /** What the bucket check said about one root's store. */
127
+ export type BucketOutcome = {
128
+ checked: BucketReport;
129
+ } | {
130
+ skipped: string;
131
+ };
132
+ /**
133
+ * Core's bucket check on a root's resolved store: the settings choudoufu
134
+ * refuses to open the bucket without. It reads only. A store with no bucket,
135
+ * or a check that cannot run, is skipped with the reason; nothing here throws.
136
+ * `check` is injectable for tests.
137
+ */
138
+ export declare function checkStoreBucket(s: LiveStore, backend?: Record<string, string>, env?: NodeJS.ProcessEnv, check?: (target: BucketTarget, options: {
139
+ namespaces: string[];
140
+ }) => Promise<BucketReport>): Promise<BucketOutcome>;
141
+ /** The bucket check's outcome as lines: one for a correct bucket, else one per setting that did not pass, with its fix. */
142
+ export declare function bucketLines(root: string, outcome: BucketOutcome): string[];
143
+ //# sourceMappingURL=live-roots.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"live-roots.d.ts","sourceRoot":"","sources":["../src/live-roots.ts"],"names":[],"mappings":"AA+BA,OAAO,EAAe,KAAK,YAAY,EAAE,KAAK,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAIlG,OAAO,EAAa,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1D,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAEhG,8HAA8H;AAC9H,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,MAAM,SAAc,GAAG,MAAM,EAAE,CAEhG;AAED,iHAAiH;AACjH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,SAAc,GAAG;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,CAGhG;AAED,8HAA8H;AAC9H,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG,MAAM,GAAG,aAAa,GAAG,WAAW,GAAG,MAAM,CAAC;AAEtF,4EAA4E;AAC5E,MAAM,WAAW,SAAS;IACxB,uDAAuD;IACvD,IAAI,EAAE,MAAM,CAAC;IACb,wHAAwH;IACxH,MAAM,EAAE,MAAM,CAAC;IACf,+DAA+D;IAC/D,MAAM,EAAE,MAAM,CAAC;IACf,yHAAyH;IACzH,MAAM,EAAE,MAAM,CAAC;IACf,gDAAgD;IAChD,UAAU,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,CACpC,CAAC,EAAE,SAAS,EACZ,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,EACpC,GAAG,GAAE,MAAM,CAAC,UAAwB,EACpC,KAAK,GAAE,CAAC,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE;IAAE,UAAU,EAAE,MAAM,EAAE,CAAA;CAAE,KAAK,OAAO,CAAC,YAAY,CAAe,GACtG,OAAO,CAAC,aAAa,CAAC,CASxB;AAED,2HAA2H;AAC3H,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,MAAM,EAAE,CAO1E"}
@@ -0,0 +1,304 @@
1
+ /**
2
+ * Which roots are choudoufu live roots, their estates, and the setup
3
+ * choudoufu resolves for each (chant#4910).
4
+ *
5
+ * - {@link liveRoots}: the roots that keep their resources under choudoufu's
6
+ * live markers, a `live` block in a `terraform` block or an
7
+ * `estate.chdf.hcl` sidecar.
8
+ * - {@link estateOf}: a root's estate as its files name it, and the estates
9
+ * whose recorded outputs it reads through `data "terraform_estate_outputs"`.
10
+ * - {@link readLiveSetup}: the record store and estate choudoufu resolves
11
+ * for a root, from `choudoufu live-check -json` (its `estate`,
12
+ * `estate_source` and `record_store` fields), remembered for the process,
13
+ * and {@link resolvedEstate}, which prefers it to the files' own name. A
14
+ * choudoufu release that prints no `estate_source` gives no setup, and the
15
+ * readers fall back to the files.
16
+ * - {@link setupLine}, {@link storePhrase}, {@link bucketTarget},
17
+ * {@link checkStoreBucket} and {@link bucketLines}: the setup as a log line,
18
+ * and core's bucket check (`@intentius/chant/bucket-check`, chant#4558) on
19
+ * the resolved store.
20
+ * - {@link liveRecordStore}: where a live root's records are, choudoufu's
21
+ * resolved store over the one its files write ({@link writtenRecordStore}),
22
+ * and {@link rootBackendAttrs}, the backend block's strings the bucket
23
+ * check and an s3 store's region read (chant#4954).
24
+ *
25
+ * Text reads, as `./op/activities/live-detect.ts` does them: no HCL parser
26
+ * is loaded. Lifted from terragucci's `detect.ts` (`liveRoots`, `estateOf`)
27
+ * and `live-setup.ts`, and `cdf-records.ts` (`recordStoreOf`), so
28
+ * terragucci deletes its copies.
29
+ */
30
+ import { existsSync, readFileSync } from "node:fs";
31
+ import { join, resolve } from "node:path";
32
+ import { checkBucket } from "@intentius/chant/bucket-check";
33
+ import { blankComments, blockBody, hclAttr, rootTexts } from "./compose/hcl.js";
34
+ import { declaresLive, detectLiveEstate, estateOutputReads } from "./op/activities/live-detect.js";
35
+ import { declaredBackend } from "./state/backend.js";
36
+ import { runBinary } from "./state/exec.js";
37
+ export { declaresLive, detectLiveEstate, estateOutputReads } from "./op/activities/live-detect.js";
38
+ /** The roots of `roots` (paths under `repo`) that keep their resources under choudoufu's live markers, in the order given. */
39
+ export function liveRoots(repo, roots, binary = "choudoufu") {
40
+ return roots.filter((r) => declaresLive(join(repo, r), binary));
41
+ }
42
+ /** A root's estate, as its sidecar or `live` block names it, and the estates whose recorded outputs it reads. */
43
+ export function estateOf(dir, binary = "choudoufu") {
44
+ const estate = detectLiveEstate(dir, binary);
45
+ return { ...(estate ? { estate } : {}), reads: estateOutputReads(dir, binary).map((r) => r.estate) };
46
+ }
47
+ const str = (v) => (typeof v === "string" && v !== "" ? v : undefined);
48
+ /** The setup in a `live-check -json` document, or undefined when the document is not JSON or comes from a choudoufu that does not print `estate_source`. */
49
+ export function parseLiveSetup(stdout) {
50
+ let doc;
51
+ try {
52
+ doc = JSON.parse(stdout);
53
+ }
54
+ catch {
55
+ return undefined;
56
+ }
57
+ if (!doc || typeof doc !== "object" || typeof doc.estate_source !== "string")
58
+ return undefined;
59
+ const rs = doc.record_store && typeof doc.record_store === "object" ? doc.record_store : undefined;
60
+ const kind = str(rs?.kind);
61
+ const store = rs && kind
62
+ ? {
63
+ kind,
64
+ bucket: str(rs.bucket) ?? "",
65
+ prefix: str(rs.prefix) ?? "",
66
+ source: str(rs.source) ?? "",
67
+ ...(str(rs.declared_at) ? { declaredAt: str(rs.declared_at) } : {}),
68
+ ...(str(rs.note) ? { note: str(rs.note) } : {}),
69
+ }
70
+ : undefined;
71
+ const estate = str(doc.estate);
72
+ return { ...(estate ? { estate } : {}), estateSource: doc.estate_source, ...(store ? { store } : {}) };
73
+ }
74
+ const known = new Map();
75
+ /** Keep what choudoufu resolved for a root's directory, for the readers below. */
76
+ export function rememberLiveSetup(dir, setup) {
77
+ known.set(resolve(dir), setup);
78
+ }
79
+ /** What choudoufu resolved for a root's directory in this process, if it was read. */
80
+ export function knownLiveSetup(dir) {
81
+ return known.get(resolve(dir));
82
+ }
83
+ /** For tests: forget every setup read so far. */
84
+ export function forgetLiveSetups() {
85
+ known.clear();
86
+ }
87
+ /**
88
+ * `choudoufu live-check -json <dir>` for one root, run in the directory, and
89
+ * the setup it prints, remembered for the process. Undefined when the binary
90
+ * prints none (an older release, a root it cannot read, or no binary at
91
+ * all); the caller then reads the files. A root that live-check blocks still
92
+ * prints its setup, so the exit code is not read.
93
+ */
94
+ export async function readLiveSetup(dir, options = {}) {
95
+ const at = resolve(dir);
96
+ const had = known.get(at);
97
+ if (had)
98
+ return had;
99
+ const exec = options.exec ?? runBinary;
100
+ let stdout;
101
+ try {
102
+ stdout = (await exec(options.binary ?? "choudoufu", ["live-check", "-json", at], at, options.env ?? process.env)).stdout;
103
+ }
104
+ catch {
105
+ return undefined;
106
+ }
107
+ const setup = parseLiveSetup(stdout);
108
+ if (setup)
109
+ known.set(at, setup);
110
+ return setup;
111
+ }
112
+ /** A live root's estate: choudoufu's resolved name when it was read, else the name its files write. */
113
+ export function resolvedEstate(dir, binary = "choudoufu") {
114
+ return knownLiveSetup(dir)?.estate ?? estateOf(dir, binary).estate;
115
+ }
116
+ /** A key namespace with exactly one trailing slash, as choudoufu's NamespacePrefix makes it. */
117
+ const namespace = (prefix) => `${prefix.replace(/\/+$/, "")}/`;
118
+ /**
119
+ * The text of a root's `live` block, comments blanked: its `estate.chdf.hcl`
120
+ * sidecar whole, else the `live` block in a `terraform` block of its HCL
121
+ * files. Undefined when it has neither.
122
+ */
123
+ export function liveBlockText(dir, binary = "choudoufu") {
124
+ const sidecar = join(dir, "estate.chdf.hcl");
125
+ if (existsSync(sidecar))
126
+ return blankComments(readFileSync(sidecar, "utf-8"));
127
+ for (const { text, json } of rootTexts(dir, binary)) {
128
+ if (json)
129
+ continue;
130
+ for (const t of text.matchAll(/^\s*terraform\s*\{/gm)) {
131
+ const body = blockBody(text, t.index);
132
+ const live = body.match(/\blive\s*\{/);
133
+ if (live)
134
+ return blockBody(body, live.index);
135
+ }
136
+ }
137
+ return undefined;
138
+ }
139
+ /**
140
+ * The record store a live root's files write for `estate` (chant#4954): the
141
+ * `record_store "<kind>"` block in its `live` block or sidecar, its
142
+ * `key_prefix` (default `tofu-records/<estate>/`), an s3 store's `bucket` and
143
+ * `region`, a local store's `path` (default `.tofu-records`, beside the
144
+ * root). No `record_store` block is the local store. Undefined when the root
145
+ * has no live block. Lifted from terragucci's `recordStoreOf`
146
+ * (cdf-records.ts).
147
+ */
148
+ export function writtenRecordStore(dir, estate, binary = "choudoufu") {
149
+ const live = liveBlockText(dir, binary);
150
+ if (live === undefined)
151
+ return undefined;
152
+ const m = /\brecord_store\s+"([^"]+)"\s*\{/.exec(live);
153
+ const attr = m ? hclAttr(blockBody(live, m.index)) : () => undefined;
154
+ const str = (name) => {
155
+ const v = attr(name);
156
+ return typeof v === "string" ? v : undefined;
157
+ };
158
+ const prefix = namespace(str("key_prefix") ?? `tofu-records/${estate}`);
159
+ const kind = m?.[1] ?? "local";
160
+ if (kind === "s3") {
161
+ const bucket = str("bucket");
162
+ if (!bucket)
163
+ return { kind: "unread", name: "s3" };
164
+ const region = str("region");
165
+ return { kind: "s3", bucket, prefix, ...(region ? { region } : {}) };
166
+ }
167
+ if (kind === "local")
168
+ return { kind: "local", dir: join(dir, str("path") ?? ".tofu-records"), prefix };
169
+ return { kind: "unread", name: kind };
170
+ }
171
+ /**
172
+ * The string attributes of a root's backend block as its code writes them
173
+ * (chant#4954), for the bucket check's s3 region and azurerm subscription
174
+ * and resource group. Empty for a `cloud` block or no backend. Read with
175
+ * {@link declaredBackend}, without the job's `-backend-config` flags.
176
+ */
177
+ export function rootBackendAttrs(dir, binary = "choudoufu") {
178
+ const b = declaredBackend(dir, { binary, env: {} });
179
+ if (!b || b.type === "cloud")
180
+ return {};
181
+ return Object.fromEntries(Object.entries(b.config).filter((e) => typeof e[1] === "string"));
182
+ }
183
+ /**
184
+ * A live root's record store (chant#4954): choudoufu's resolved store when
185
+ * {@link readLiveSetup} read it for the root, else the one its files write
186
+ * ({@link writtenRecordStore}). An s3 store's region, which `live-check
187
+ * -json` does not print, comes from the `record_store` block, else the
188
+ * backend block. Undefined when the root has no live block. Lifted from
189
+ * terragucci's `resolvedRecordStore` (live-setup.ts).
190
+ */
191
+ export function liveRecordStore(dir, estate, binary = "choudoufu") {
192
+ if (liveBlockText(dir, binary) === undefined)
193
+ return undefined;
194
+ const s = knownLiveSetup(dir)?.store;
195
+ if (!s)
196
+ return writtenRecordStore(dir, estate, binary);
197
+ if (s.kind === "local")
198
+ return { kind: "local", dir: resolve(dir, s.bucket || ".tofu-records"), prefix: s.prefix };
199
+ if (s.kind === "s3" && s.bucket) {
200
+ const written = writtenRecordStore(dir, estate, binary);
201
+ const region = (written?.kind === "s3" ? written.region : undefined) ?? rootBackendAttrs(dir, binary).region;
202
+ return { kind: "s3", bucket: s.bucket, prefix: s.prefix, ...(region ? { region } : {}) };
203
+ }
204
+ return { kind: "unread", name: s.kind };
205
+ }
206
+ const STORE_FROM = {
207
+ record_store: "from its record_store block",
208
+ backend: "derived from its backend block",
209
+ implied: "the local store, since no backend block gives one",
210
+ };
211
+ const ESTATE_FROM = {
212
+ explicit: "named by its live block",
213
+ tags: "from its tofu-estate tags",
214
+ backend_key: "from the backend key",
215
+ root_path: "from the root's path",
216
+ none: "none resolves",
217
+ };
218
+ /** The store as one phrase: `s3 bucket "acme" under tofu-records/prod/`. */
219
+ export function storePhrase(s) {
220
+ if (s.kind === "local")
221
+ return `the local directory ${s.bucket || ".tofu-records"} under ${s.prefix}`;
222
+ if (s.kind === "azurerm")
223
+ return `azurerm container ${s.bucket} under ${s.prefix}`;
224
+ if (s.kind === "kubernetes")
225
+ return `kubernetes namespace ${s.bucket} under ${s.prefix}`;
226
+ return `${s.kind} bucket "${s.bucket}" under ${s.prefix}`;
227
+ }
228
+ /** A root's setup on one line: where its records go, where that came from, and its estate. */
229
+ export function setupLine(root, setup) {
230
+ const s = setup.store;
231
+ const where = s ? `records in ${storePhrase(s)} (${STORE_FROM[s.source] ?? s.source}${s.declaredAt ? ` at ${s.declaredAt}` : ""})` : "no record store resolved";
232
+ const estate = setup.estate ? `estate "${setup.estate}" (${ESTATE_FROM[setup.estateSource] ?? setup.estateSource})` : "no estate resolves";
233
+ return `${root}: ${where}; ${estate}${s?.note ? `; ${s.note}` : ""}`;
234
+ }
235
+ /** The setup's store is the local directory, which is empty on every CI run. */
236
+ export const onLocalStore = (setup) => setup.store?.kind === "local";
237
+ /**
238
+ * The bucket core's check reads for a resolved store, or why there is none.
239
+ * `backend` is the root's backend block's string attributes, for the s3
240
+ * region and the azurerm subscription and resource group. s3 takes the
241
+ * region from there or the job, and an emulator's endpoint and keys from the
242
+ * job; gcs an emulator from `STORAGE_EMULATOR_HOST`; azurerm needs the
243
+ * subscription and resource group, from the backend block or
244
+ * `ARM_SUBSCRIPTION_ID`.
245
+ */
246
+ export function bucketTarget(s, backend = {}, env = process.env) {
247
+ if (s.kind === "s3") {
248
+ const region = backend.region ?? env.AWS_REGION ?? env.AWS_DEFAULT_REGION;
249
+ if (!region)
250
+ return { skip: "no region: set region in the backend block or AWS_REGION" };
251
+ const endpoint = env.AWS_ENDPOINT_URL_S3 ?? env.AWS_ENDPOINT_URL;
252
+ const keys = env.AWS_ACCESS_KEY_ID && env.AWS_SECRET_ACCESS_KEY
253
+ ? { accessKeyId: env.AWS_ACCESS_KEY_ID, secretAccessKey: env.AWS_SECRET_ACCESS_KEY, ...(env.AWS_SESSION_TOKEN ? { sessionToken: env.AWS_SESSION_TOKEN } : {}) }
254
+ : undefined;
255
+ if (endpoint && !keys)
256
+ return { skip: "AWS_ENDPOINT_URL is set with no AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY" };
257
+ return { target: { store: "s3", bucket: s.bucket, region, ...(endpoint ? { endpoint, credentials: keys } : {}) } };
258
+ }
259
+ if (s.kind === "gcs") {
260
+ const emulator = env.STORAGE_EMULATOR_HOST;
261
+ return { target: { store: "gcs", bucket: s.bucket, ...(emulator ? { endpoint: /^https?:\/\//.test(emulator) ? emulator : `http://${emulator}`, token: null } : {}) } };
262
+ }
263
+ if (s.kind === "azurerm") {
264
+ const [account, container] = s.bucket.split("/");
265
+ const subscriptionId = backend.subscription_id ?? env.ARM_SUBSCRIPTION_ID;
266
+ const resourceGroup = backend.resource_group_name;
267
+ if (!account || !container)
268
+ return { skip: "the store names no storage account and container" };
269
+ if (!subscriptionId || !resourceGroup)
270
+ return { skip: "the bucket check needs the subscription and resource group: set resource_group_name in the backend block, and subscription_id there or ARM_SUBSCRIPTION_ID" };
271
+ return { target: { store: "azblob", subscriptionId, resourceGroup, account, container } };
272
+ }
273
+ return { skip: `a ${s.kind} store has no bucket to check` };
274
+ }
275
+ /**
276
+ * Core's bucket check on a root's resolved store: the settings choudoufu
277
+ * refuses to open the bucket without. It reads only. A store with no bucket,
278
+ * or a check that cannot run, is skipped with the reason; nothing here throws.
279
+ * `check` is injectable for tests.
280
+ */
281
+ export async function checkStoreBucket(s, backend = {}, env = process.env, check = checkBucket) {
282
+ if (s.kind === "local")
283
+ return { skipped: "the local store has no bucket" };
284
+ const t = bucketTarget(s, backend, env);
285
+ if ("skip" in t)
286
+ return { skipped: t.skip };
287
+ try {
288
+ return { checked: await check(t.target, { namespaces: s.prefix ? [s.prefix] : [] }) };
289
+ }
290
+ catch (e) {
291
+ return { skipped: `the bucket could not be checked: ${e.message}` };
292
+ }
293
+ }
294
+ /** The bucket check's outcome as lines: one for a correct bucket, else one per setting that did not pass, with its fix. */
295
+ export function bucketLines(root, outcome) {
296
+ if ("skipped" in outcome)
297
+ return [`${root}: bucket not checked: ${outcome.skipped}`];
298
+ const r = outcome.checked;
299
+ if (r.correct)
300
+ return [`${root}: bucket ${r.bucket} has every setting choudoufu needs (${r.settings.map((f) => f.setting).join(", ")})`];
301
+ return r.settings
302
+ .filter((f) => f.verdict !== "ok")
303
+ .map((f) => `${root}: bucket ${r.bucket}: ${f.setting} ${f.verdict === "unreadable" ? "could not be read" : "fails"}: ${f.found}${f.unwaivable ? " (no allow_insecure reaches this one)" : ""}${f.fix ? `; fix: ${f.fix}` : ""}`);
304
+ }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "terraform",
3
- "version": "0.124.87",
3
+ "version": "0.124.89",
4
4
  "chantVersion": ">=0.1.0",
5
5
  "namespace": "Terraform"
6
6
  }
@@ -0,0 +1,105 @@
1
+ /**
2
+ * A state migration's history, read back from the lines chant wrote
3
+ * (chant#4910): each `finished` line of the migration's gated requests
4
+ * (`_gates/<op>/applied.jsonl` on `chant/lifecycle`, written by core's
5
+ * `runStateMigration` with `migrationFacts`), as one history line per run,
6
+ * and the revert of a migration that applied, each root back to the version
7
+ * the migration recorded before it wrote.
8
+ *
9
+ * The history line is the form terragucci's `done.jsonl` has always held,
10
+ * so a product that kept such a file before chant ran its gate reads the two
11
+ * together ({@link migrationHistory}). Besides core's facts, a finished
12
+ * line's detail may carry the product's `file_digest`, its change
13
+ * (`migration_change`, else `change`) and the migration a revert put back
14
+ * (`revert`); they are read when there.
15
+ *
16
+ * Lifted from terragucci's `finishedMigrationLines`, `migrationHistory` and
17
+ * `revertMigration` (migrate.ts), so terragucci deletes its copies and keeps
18
+ * its file's words.
19
+ */
20
+ import { type Restore } from "./state-migration.js";
21
+ /** One root of a history line: where its state is, and its version and digest before and after. */
22
+ export interface MigrationHistoryRoot {
23
+ root: string;
24
+ location: string | null;
25
+ before: string | null;
26
+ after: string | null;
27
+ before_digest: string | null;
28
+ after_digest: string | null;
29
+ /** A backend move's source, and the version read there. */
30
+ source?: string | null;
31
+ source_version?: string | null;
32
+ }
33
+ /** One run of a migration, as its history holds it. */
34
+ export interface MigrationHistoryLine {
35
+ version: 1;
36
+ kind: "migration";
37
+ op: string;
38
+ /** The migration's name. */
39
+ gate: string;
40
+ timestamp: string;
41
+ planDigest?: string;
42
+ file_digest?: string;
43
+ /** `applied` or `failed`. A run refused under the locks wrote nothing and has no line. */
44
+ result: string;
45
+ approvedBy?: string;
46
+ /** The migration's change: `moves`, `backends`, `revert`, `retag`, `adopt`, as the product's detail names it. */
47
+ change: string | null;
48
+ /** The migration a revert put back. */
49
+ revert?: string;
50
+ roots: MigrationHistoryRoot[];
51
+ error?: string;
52
+ /** `finished`: read from a gated request's finished line. */
53
+ source?: string;
54
+ }
55
+ /**
56
+ * The finished lines of a migration op's `applied.jsonl` as history lines,
57
+ * oldest first. A line without a `result` is skipped (the migration threw
58
+ * before it ended), and so is a run refused under the lock, which wrote
59
+ * nothing.
60
+ */
61
+ export declare function finishedMigrationLines(appliedText: string, op: string): MigrationHistoryLine[];
62
+ /** Where a migration op's history is kept on `chant/lifecycle`: chant's `applied.jsonl`, and the product's own earlier file, if it kept one. */
63
+ export interface MigrationHistoryFiles {
64
+ op: string;
65
+ /** The product's file of history lines written before chant ran the gate, such as `_gates/tf-migrate/done.jsonl`. */
66
+ earlier?: string;
67
+ }
68
+ /**
69
+ * A migration op's history as history-line text, one JSON line each: the
70
+ * product's earlier lines first, then each finished line of chant's gated
71
+ * requests. The newest line of a migration wins. `show` reads a path on
72
+ * `chant/lifecycle` as the caller wants it read (the remote ref as last
73
+ * fetched, say), answering "" for a path that is not there.
74
+ */
75
+ export declare function migrationHistory(show: (path: string) => string, files: MigrationHistoryFiles): string;
76
+ /** The newest line of each migration that ran its writes, by name. */
77
+ export declare function doneMigrations(history: string): Map<string, {
78
+ status: string;
79
+ file_digest?: string;
80
+ timestamp: string;
81
+ }>;
82
+ /** The name a revert of `name` takes. */
83
+ export declare const revertName: (name: string) => string;
84
+ /** A revert of a migration that applied: its name, each root's restore, and the migration file that asks for it. */
85
+ export interface MigrationRevert {
86
+ name: string;
87
+ restores: Restore[];
88
+ /** The file, `revert:` and `restores:`, under the caller's comment lines. */
89
+ text: string;
90
+ }
91
+ /**
92
+ * The revert of a migration that applied, from its newest applied line in
93
+ * `history`: each root back to the version the migration recorded before it
94
+ * wrote, from the version it recorded after (the write is refused when a
95
+ * state moved past it). A backend move, a revert, an estate retag or an
96
+ * estate adoption is not put back this way, and a root whose bucket kept no
97
+ * version cannot be put back: each throws {@link MigrationError} naming why.
98
+ * `where` names the history in the refusal; `header` are the file's comment
99
+ * lines, without their `# `.
100
+ */
101
+ export declare function revertMigration(name: string, history: string, options?: {
102
+ where?: string;
103
+ header?: readonly string[];
104
+ }): MigrationRevert;
105
+ //# sourceMappingURL=migration-history.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration-history.d.ts","sourceRoot":"","sources":["../src/migration-history.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAkB,KAAK,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEjE,mGAAmG;AACnG,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,2DAA2D;IAC3D,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAED,uDAAuD;AACvD,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,CAAC,CAAC;IACX,IAAI,EAAE,WAAW,C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