@intentius/chant-lexicon-terraform 0.124.88 → 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.
@@ -0,0 +1,86 @@
1
+ import { type OtlpSpan, type OtlpTrace } from "@intentius/chant/otlp";
2
+ import { type TerraformCommand, type TerraformCommandHook } from "./op/command-hook.js";
3
+ import { type BinaryExec, type Ran } from "./state/exec.js";
4
+ import type { TerragruntExec } from "./terragrunt/run.js";
5
+ export { withTerraformCommandHook, asUpstreamCommands, type TerraformCommand, type TerraformCommandHook, type TerraformCommandResult, type TerraformCommandRun } from "./op/command-hook.js";
6
+ /** A run of the binary that blocks: `-chdir=<dir>`, `TF_IN_AUTOMATION=1`, as {@link runBinary} runs it. */
7
+ export type BinaryExecSync = (binary: string, args: string[], dir: string, env: NodeJS.ProcessEnv) => Ran;
8
+ /** What {@link engineRunner} takes. */
9
+ export interface EngineRunnerOptions {
10
+ /** The product's own token variables, left out beside chant's forge token variables (terragucci's `TG_TOKEN`, `TG_MERGE_TOKEN`). */
11
+ tokens?: readonly string[];
12
+ /** The run under `exec`, for tests. Default {@link runBinary}. */
13
+ exec?: BinaryExec;
14
+ }
15
+ /** The product's runners of the engine, every one with the forge's tokens left out (chant#4954). */
16
+ export interface EngineRunner {
17
+ /** The token variables left out: chant's forge token variables and the product's. */
18
+ readonly tokens: readonly string[];
19
+ /** `env` less every forge token, by name and by value ({@link engineEnv}). */
20
+ env(env: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
21
+ /**
22
+ * The binary, run without blocking. Inside `withTerraformCommandHook(hook,
23
+ * { root, method })` each run goes through `hook` as a command for that
24
+ * root, as `terraform-apply`'s own do; outside one it just runs.
25
+ */
26
+ exec: BinaryExec;
27
+ /** The binary, run to its end before it returns, for a caller that cannot wait. Goes through no hook. */
28
+ execSync: BinaryExecSync;
29
+ /** Terragrunt, as `planTerragruntWave` and the other Terragrunt calls take it, with the job's environment under the call's. */
30
+ terragrunt: TerragruntExec;
31
+ /**
32
+ * The path of a script named as `binary` under `dir` that leaves the forge
33
+ * tokens `env` holds out, by name and by value, then runs `binary` with
34
+ * what it was given: for a step chant runs with the job's environment
35
+ * (`terraform-apply`'s `resolveRoot`), or a `TG_TF_PATH`. A bare name is
36
+ * resolved on `env.PATH` first, so the script never runs itself. One
37
+ * script per binary and set of variables; written once.
38
+ */
39
+ script(dir: string, binary: string, env: NodeJS.ProcessEnv): string;
40
+ }
41
+ /**
42
+ * The runners of the engine for a product whose own token variables are
43
+ * `tokens` (chant#4954). A product makes one and runs the binary and
44
+ * Terragrunt only through it.
45
+ */
46
+ export declare function engineRunner(options?: EngineRunnerOptions): EngineRunner;
47
+ /**
48
+ * The variables a command run inside `span` gets (chant#4954): `TRACEPARENT`,
49
+ * so the engine's spans join the trace where it reads it (OpenTofu and
50
+ * choudoufu), the trace's and span's ids and the root as resource attributes
51
+ * (`<prefix>.trace_id`, `<prefix>.span_id`, `<prefix>.root`) over the
52
+ * `OTEL_RESOURCE_ATTRIBUTES` `env` has, so a binary that ignores
53
+ * `TRACEPARENT` still names the span that ran it, and `OTEL_TRACES_EXPORTER`
54
+ * `otlp` unless `env` chose one (`none` keeps it off). Lifted from
55
+ * terragucci's `binaryEnv` (telemetry.ts).
56
+ */
57
+ export declare function commandTraceEnv(env: NodeJS.ProcessEnv, trace: OtlpTrace, span: OtlpSpan, options: {
58
+ prefix: string;
59
+ root: string;
60
+ }): Record<string, string>;
61
+ /** What {@link commandTrace} takes. */
62
+ export interface CommandTraceOptions {
63
+ /** The run's trace. */
64
+ trace: OtlpTrace;
65
+ /** The product, which names the resource attributes (`terragucci.trace_id`). */
66
+ prefix: string;
67
+ /** The span a command's span hangs under, such as the product's span for its root. Undefined, or no function, hangs it under the trace's parent. */
68
+ parent?: (command: TerraformCommand) => OtlpSpan | undefined;
69
+ /** The environment the commands run over, whose `OTEL_RESOURCE_ATTRIBUTES` and `OTEL_TRACES_EXPORTER` are kept. Default `process.env`. */
70
+ env?: NodeJS.ProcessEnv;
71
+ /** Trace an upstream's reads for a root too. Default false: they are the upstream's, not the root's. */
72
+ upstreams?: boolean;
73
+ }
74
+ /**
75
+ * A command hook that traces each engine command (chant#4954): a span
76
+ * `<binary> <name>` (kind client, with `process.executable.name` and
77
+ * `process.command_args`) under `parent(command)`, the variables
78
+ * {@link commandTraceEnv} gives for it, and the span ended with
79
+ * `process.exit.code` once the command ends, failed unless it exited 0 (or 2
80
+ * for a `plan`, `-detailed-exitcode`'s changes). A command timed apart from
81
+ * its call (`at`, a Terragrunt unit's plan) spans the time it ran. Pass it as
82
+ * `engineTimings({ inner })`, so the engine's spans join the trace and reach
83
+ * the timings' receiver.
84
+ */
85
+ export declare function commandTrace(options: CommandTraceOptions): TerraformCommandHook;
86
+ //# sourceMappingURL=engine-runner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine-runner.d.ts","sourceRoot":"","sources":["../src/engine-runner.ts"],"names":[],"mappings":"AAgCA,OAAO,EAAmC,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvG,OAAO,EAAoB,KAAK,gBAAgB,EAAE,KAAK,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACvG,OAAO,EAA6C,KAAK,UAAU,EAAE,KAAK,GAAG,EAAE,MAAM,cAAc,CAAC;AACpG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,KAAK,gBAAgB,EAAE,KAAK,oBAAoB,EAAE,KAAK,sBAAsB,EAAE,KAAK,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAE1L,2GAA2G;AAC3G,MAAM,MAAM,cAAc,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,UAAU,KAAK,GAAG,CAAC;AAE1G,uCA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AAE,MAAM,CAAC,UAAU,CAAC;IACxB,wGAAwG;IACxG,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,oBAAoB,CAa/E"}
@@ -0,0 +1,134 @@
1
+ /**
2
+ * One runner of the engine for a product (chant#4954): every way a product
3
+ * runs tofu, terraform, choudoufu or Terragrunt, with the forge's tokens left
4
+ * out of its environment ({@link engineEnv}), and the trace parent each
5
+ * engine command gets.
6
+ *
7
+ * - {@link engineRunner} gives the runners for one set of product token
8
+ * variables: `exec`, a `BinaryExec` whose runs go through the command hook
9
+ * of the step call they run in (`withTerraformCommandHook`, chant#4865), so
10
+ * a product's plan stage sends its own `init`, `plan` and `show` through
11
+ * the same `onCommand` as `terraform-apply`'s; `execSync`, the same run
12
+ * for a caller that cannot wait; `terragrunt`, a `TerragruntExec`;
13
+ * `script`, a same-named script that drops the tokens and runs the binary,
14
+ * for a step chant runs with the job's environment; and `env`.
15
+ * - {@link commandTrace} is a `TerraformCommandHook` that opens a span per
16
+ * engine command under the product's span for its root, and gives the
17
+ * command `TRACEPARENT` and the resource attributes that name the span
18
+ * ({@link commandTraceEnv}). Pass it as `engineTimings({ inner })`.
19
+ *
20
+ * A Terragrunt unit's plan reaches the same hook through
21
+ * `planTerragruntWave({ onCommand })` (`./terragrunt/run.ts`).
22
+ *
23
+ * Lifted from terragucci's `binary-env.ts` (`binaryEnv`, `tokenlessBinary`,
24
+ * `terragruntExec`), the runs of the binary in its `action.ts`, `apply.ts`,
25
+ * `ephemeral.ts`, `unlock.ts` and `plan.ts`, and the trace half of its
26
+ * `telemetry.ts` (`binaryEnv`) and `report/observe.ts` (`commandHook`).
27
+ */
28
+ import { execFile, spawnSync } from "node:child_process";
29
+ import { createHash } from "node:crypto";
30
+ import { accessSync, constants, existsSync, mkdirSync, statSync, writeFileSync } from "node:fs";
31
+ import { basename, delimiter, join } from "node:path";
32
+ import { FORGE_TOKEN_VARS } from "@intentius/chant/ci-handover";
33
+ import { formatOtlpPairs, parseOtlpPairs } from "@intentius/chant/otlp";
34
+ import { hookedBinaryExec } from "./op/command-hook.js";
35
+ import { engineEnv, runBinary, tokenlessBinaryExec } from "./state/exec.js";
36
+ export { withTerraformCommandHook, asUpstreamCommands } from "./op/command-hook.js";
37
+ /** Whether `p` is a file this process may run. */
38
+ function runnable(p) {
39
+ try {
40
+ accessSync(p, constants.X_OK);
41
+ return statSync(p).isFile();
42
+ }
43
+ catch {
44
+ return false;
45
+ }
46
+ }
47
+ /** A word single-quoted for `sh`. */
48
+ const shq = (s) => `'${s.replace(/'/g, `'\\''`)}'`;
49
+ /**
50
+ * The runners of the engine for a product whose own token variables are
51
+ * `tokens` (chant#4954). A product makes one and runs the binary and
52
+ * Terragrunt only through it.
53
+ */
54
+ export function engineRunner(options = {}) {
55
+ const own = [...(options.tokens ?? [])];
56
+ const tokens = [...new Set([...own, ...FORGE_TOKEN_VARS])];
57
+ const env = (e) => engineEnv(e, own);
58
+ // The hook's variables are laid over the run's before the tokens are taken out, so no hook puts one back.
59
+ const exec = hookedBinaryExec(tokenlessBinaryExec(own, options.exec ?? runBinary));
60
+ const execSync = (binary, args, dir, given) => {
61
+ const p = spawnSync(binary, [`-chdir=${dir}`, ...args], { encoding: "utf-8", env: { ...env(given), TF_IN_AUTOMATION: "1" }, maxBuffer: 512 * 1024 * 1024 });
62
+ const stdout = p.stdout ?? "";
63
+ return { code: p.error && p.status === null ? 127 : (p.status ?? 1), stdout, out: `${stdout}${p.stderr ?? ""}${p.error ? p.error.message : ""}` };
64
+ };
65
+ const terragrunt = (file, args, opts) => new Promise((done) => {
66
+ execFile(file, [...args], { cwd: opts.cwd, env: env({ ...process.env, ...opts.env }), maxBuffer: 256 * 1024 * 1024 }, (err, stdout, stderr) => {
67
+ const code = err ? (typeof err.code === "number" ? err.code : null) : 0;
68
+ done({ code, stdout: String(stdout), stderr: err && code === null ? `${String(stderr)}${err.message}` : String(stderr) });
69
+ });
70
+ });
71
+ const script = (dir, given, e) => {
72
+ const binary = given.includes("/") ? given : ((e.PATH ?? "").split(delimiter).map((d) => join(d, given)).find((p) => runnable(p)) ?? given);
73
+ const kept = env(e);
74
+ const drop = [...new Set([...tokens, ...Object.keys(e).filter((k) => !(k in kept))])].filter((k) => /^[A-Za-z_][A-Za-z0-9_]*$/.test(k)).sort();
75
+ const at = join(dir, createHash("sha256").update(`${binary}\n${drop.join(" ")}`).digest("hex").slice(0, 16));
76
+ const path = join(at, basename(binary) || "terraform");
77
+ if (!existsSync(path)) {
78
+ mkdirSync(at, { recursive: true });
79
+ writeFileSync(path, `#!/bin/sh\nexec env ${drop.map((k) => `-u ${k}`).join(" ")} ${shq(binary)} "$@"\n`, { mode: 0o755 });
80
+ }
81
+ return path;
82
+ };
83
+ return { tokens, env, exec, execSync, terragrunt, script };
84
+ }
85
+ /**
86
+ * The variables a command run inside `span` gets (chant#4954): `TRACEPARENT`,
87
+ * so the engine's spans join the trace where it reads it (OpenTofu and
88
+ * choudoufu), the trace's and span's ids and the root as resource attributes
89
+ * (`<prefix>.trace_id`, `<prefix>.span_id`, `<prefix>.root`) over the
90
+ * `OTEL_RESOURCE_ATTRIBUTES` `env` has, so a binary that ignores
91
+ * `TRACEPARENT` still names the span that ran it, and `OTEL_TRACES_EXPORTER`
92
+ * `otlp` unless `env` chose one (`none` keeps it off). Lifted from
93
+ * terragucci's `binaryEnv` (telemetry.ts).
94
+ */
95
+ export function commandTraceEnv(env, trace, span, options) {
96
+ const resource = {
97
+ ...parseOtlpPairs(env.OTEL_RESOURCE_ATTRIBUTES),
98
+ [`${options.prefix}.trace_id`]: trace.traceId,
99
+ [`${options.prefix}.span_id`]: span.spanId,
100
+ [`${options.prefix}.root`]: options.root,
101
+ };
102
+ return {
103
+ TRACEPARENT: trace.traceparent(span),
104
+ OTEL_TRACES_EXPORTER: env.OTEL_TRACES_EXPORTER || "otlp",
105
+ OTEL_RESOURCE_ATTRIBUTES: formatOtlpPairs(resource),
106
+ };
107
+ }
108
+ /**
109
+ * A command hook that traces each engine command (chant#4954): a span
110
+ * `<binary> <name>` (kind client, with `process.executable.name` and
111
+ * `process.command_args`) under `parent(command)`, the variables
112
+ * {@link commandTraceEnv} gives for it, and the span ended with
113
+ * `process.exit.code` once the command ends, failed unless it exited 0 (or 2
114
+ * for a `plan`, `-detailed-exitcode`'s changes). A command timed apart from
115
+ * its call (`at`, a Terragrunt unit's plan) spans the time it ran. Pass it as
116
+ * `engineTimings({ inner })`, so the engine's spans join the trace and reach
117
+ * the timings' receiver.
118
+ */
119
+ export function commandTrace(options) {
120
+ return (c) => {
121
+ if (c.upstream !== undefined && !options.upstreams)
122
+ return;
123
+ const span = options.trace.start(`${c.binary} ${c.name}`, options.parent?.(c), { "process.executable.name": c.binary, "process.command_args": c.args.join(" ") }, { kind: 3 });
124
+ return {
125
+ env: commandTraceEnv({ ...(options.env ?? process.env), ...c.env }, options.trace, span, { prefix: options.prefix, root: c.root }),
126
+ after: (r) => {
127
+ if (r.at)
128
+ span.start = BigInt(Math.round(r.at.start)) * 1000000n;
129
+ const ok = r.code === 0 || (c.name === "plan" && r.code === 2);
130
+ options.trace.end(span, { "process.exit.code": r.code ?? -1 }, ok ? undefined : `exit ${r.code}`, r.at?.end);
131
+ },
132
+ };
133
+ };
134
+ }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "algorithm": "sha256",
3
3
  "artifacts": {
4
- "manifest.json": "74df8d4dde6b23128cb0e27a730ddc02a9b6ac2b5da83f03dccc3965c5620520",
4
+ "manifest.json": "b80640df1f7db7ee804395be7c62b0c61385a8378fa126ec2b8e3d020edbf0ca",
5
5
  "meta.json": "ca3d163bab055381827226140568f3bef7eaac187cebd76878e0b63e9e442356",
6
6
  "types/index.d.ts": "022927e6a7b351cc4cf52d5f973f60ccd140e5810e17b32fb8868965aa1db161",
7
7
  "rules/plan-before-apply.ts": "7c10245b2c3335253b48ee7d8b075d89f43116bde20313a5d1031b343fef1282",
@@ -59,5 +59,5 @@
59
59
  "rules/tf047.ts": "bfa86f85c4c5efff297280fc2f15104d6319fa96dfc444a31829fb7353224092",
60
60
  "skills/chant-terraform.md": "53dd11c7b289652f92fdaf2c03766abda46d8964e31fe709e8b142ced4f19c50"
61
61
  },
62
- "composite": "d6062b4171ec80f83b7ff48a66a868fd0192778d6cf185e0a68656fb8345ebe4"
62
+ "composite": "c8d1a67d1fa734dea44c7de54f1054e3db52613eb24c60ebfb83373a70833e5d"
63
63
  }
@@ -53,6 +53,56 @@ export declare function readLiveSetup(dir: string, options?: {
53
53
  }): Promise<LiveSetup | undefined>;
54
54
  /** A live root's estate: choudoufu's resolved name when it was read, else the name its files write. */
55
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;
56
106
  /** The store as one phrase: `s3 bucket "acme" under tofu-records/prod/`. */
57
107
  export declare function storePhrase(s: LiveStore): string;
58
108
  /** A root's setup on one line: where its records go, where that came from, and its estate. */
@@ -1 +1 @@
1
- {"version":3,"file":"live-roots.d.ts","sourceRoot":"","sources":["../src/live-roots.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAe,KAAK,YAAY,EAAE,KAAK,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAElG,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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
18
18
  * and core's bucket check (`@intentius/chant/bucket-check`, chant#4558) on
19
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).
20
24
  *
21
25
  * Text reads, as `./op/activities/live-detect.ts` does them: no HCL parser
22
26
  * is loaded. Lifted from terragucci's `detect.ts` (`liveRoots`, `estateOf`)
23
- * and `live-setup.ts`, so terragucci deletes its copies.
27
+ * and `live-setup.ts`, and `cdf-records.ts` (`recordStoreOf`), so
28
+ * terragucci deletes its copies.
24
29
  */
30
+ import { existsSync, readFileSync } from "node:fs";
25
31
  import { join, resolve } from "node:path";
26
32
  import { checkBucket } from "@intentius/chant/bucket-check";
33
+ import { blankComments, blockBody, hclAttr, rootTexts } from "./compose/hcl.js";
27
34
  import { declaresLive, detectLiveEstate, estateOutputReads } from "./op/activities/live-detect.js";
35
+ import { declaredBackend } from "./state/backend.js";
28
36
  import { runBinary } from "./state/exec.js";
29
37
  export { declaresLive, detectLiveEstate, estateOutputReads } from "./op/activities/live-detect.js";
30
38
  /** The roots of `roots` (paths under `repo`) that keep their resources under choudoufu's live markers, in the order given. */
@@ -105,6 +113,96 @@ export async function readLiveSetup(dir, options = {}) {
105
113
  export function resolvedEstate(dir, binary = "choudoufu") {
106
114
  return knownLiveSetup(dir)?.estate ?? estateOf(dir, binary).estate;
107
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
+ }
108
206
  const STORE_FROM = {
109
207
  record_store: "from its record_store block",
110
208
  backend: "derived from its backend block",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "terraform",
3
- "version": "0.124.88",
3
+ "version": "0.124.89",
4
4
  "chantVersion": ">=0.1.0",
5
5
  "namespace": "Terraform"
6
6
  }
@@ -37,6 +37,16 @@ export interface TerraformCommandResult {
37
37
  seconds: number;
38
38
  stdout: string;
39
39
  stderr: string;
40
+ /**
41
+ * When it ran, in Unix milliseconds, for a command timed apart from its
42
+ * call (chant#4954): a Terragrunt unit's plan, from Terragrunt's run
43
+ * report, whose `after` is called once the whole wave ends. Unset, it ran
44
+ * from the hook's call to its `after`.
45
+ */
46
+ at?: {
47
+ start: number;
48
+ end: number;
49
+ };
40
50
  }
41
51
  /** What a {@link TerraformCommandHook} answers for one command (chant#4865). */
42
52
  export interface TerraformCommandRun {
@@ -1 +1 @@
1
- {"version":3,"file":"command-hook.d.ts","sourceRoot":"","sources":["../../src/op/command-hook.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,UAAU,EAAO,MAAM,eAAe,CAAC;AAErD;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,4CAA4C;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,kGAAkG;IAClG,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,4EAA4E;IAC5E,MAAM,EAAE,MAAM,CAAC;IACf,gDAAgD;IAChD,MAAM,EAAE,MAAM,CAAC;IACf,sIAAsI;IACtI,IAAI,EAAE,MAAM,CAAC;IACb,gDAAgD;IAChD,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,6CAA6C;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,gCAAgC;IAChC,GAAG,EAAE,MAAM,CAAC;IACZ,8IAA8I;IAC9I,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC7B;AAED,oFAAoF;AACpF,MAAM,WAAW,sBAAsB;IACrC,0GAA0G;IAC1G,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,mCAAmC;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,gFAAgF;AAChF,MAAM,WAAW,mBAAmB;IAClC,mGAAmG;IACnG,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,wFAAwF;IACxF,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,sBAAsB,KAAK,IAAI,GAAG,O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
9
+ import type { TerraformCommandHook } from "../op/command-hook.js";
9
10
  import { type TerragruntFindOptions, type TerragruntUnit } from "./units.js";
10
11
  import { type TerragruntMockRead } from "./mocks.js";
11
12
  import { type TerragruntUnitResult } from "./wave.js";
@@ -75,7 +76,29 @@ export interface TerragruntWaveRunInput extends TerragruntRunOptions {
75
76
  * the plan, which fails the unit with its report row as before.
76
77
  */
77
78
  initTurn?: <T>(fn: () => Promise<T>) => Promise<T>;
79
+ /**
80
+ * The product's hook around each unit's plan (chant#4954), the
81
+ * `TerraformCommandHook` `terraform-apply` takes as `onCommand`, such as
82
+ * `engineTimings().onCommand`. Terragrunt runs the binary itself, so the
83
+ * hook is asked for every unit of the wave before `run --all`, as a `plan`
84
+ * command for that unit (`root` is the unit's path, `method` is `plan`).
85
+ * The variables it answers reach that unit's plan alone, through a
86
+ * `TG_TF_PATH` wrapper that matches the `-out` path Terragrunt gives it.
87
+ * Once the wave ends, each unit's `after` gets its time (`at`) and result
88
+ * from the run report. Needs `binary`: without it Terragrunt picks the
89
+ * binary per unit, and the hook is not called.
90
+ */
91
+ onCommand?: TerraformCommandHook;
78
92
  }
93
+ /**
94
+ * The `TG_TF_PATH` wrapper for one wave (chant#4954): a shell script that
95
+ * runs `binary` with the variables of the unit whose plan it runs.
96
+ * Terragrunt hands each unit's plan `-out=<out-dir>/<unit>/tfplan.tfplan`,
97
+ * which names the unit; every other call (init, show, output, version) runs
98
+ * the binary as it is. `outDirs` are the wave's plan directory as given and
99
+ * as its real path. Lifted from terragucci's `unitWrapper` (report/stage.ts).
100
+ */
101
+ export declare function terragruntUnitWrapper(binary: string, outDirs: readonly string[], units: ReadonlyMap<string, Record<string, string>>): string;
79
102
  /**
80
103
  * Thrown when a wave's plans would read `mock_outputs` (#3416). Nothing in
81
104
  * the wave was planned, so there is nothing to gate. `reads` names each unit,
@@ -1 +1 @@
1
- {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../src/terragrunt/run.ts"],"names":[],"mappings":"AAAA;;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