@intentius/chant-lexicon-terraform 0.124.88 → 0.124.90
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/engine-runner.d.ts +86 -0
- package/dist/engine-runner.d.ts.map +1 -0
- package/dist/engine-runner.js +134 -0
- package/dist/integrity.json +2 -2
- package/dist/live-roots.d.ts +50 -0
- package/dist/live-roots.d.ts.map +1 -1
- package/dist/live-roots.js +99 -1
- package/dist/manifest.json +1 -1
- package/dist/op/command-hook.d.ts +10 -0
- package/dist/op/command-hook.d.ts.map +1 -1
- package/dist/reach.d.ts +76 -0
- package/dist/reach.d.ts.map +1 -0
- package/dist/reach.js +193 -0
- package/dist/terragrunt/run.d.ts +23 -0
- package/dist/terragrunt/run.d.ts.map +1 -1
- package/dist/terragrunt/run.js +107 -3
- package/package.json +2 -2
- package/src/engine-runner.test.ts +261 -0
- package/src/engine-runner.ts +191 -0
- package/src/live-record-store.test.ts +76 -0
- package/src/live-roots.ts +104 -1
- package/src/op/command-hook.ts +7 -0
- package/src/reach.test.ts +72 -0
- package/src/reach.ts +196 -0
- package/src/terragrunt/run.ts +128 -4
|
@@ -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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C1I,GAAG,CAAC,EAAE,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
|
+
}
|
package/dist/integrity.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"algorithm": "sha256",
|
|
3
3
|
"artifacts": {
|
|
4
|
-
"manifest.json": "
|
|
4
|
+
"manifest.json": "214cf8ced5b52ba25016f9d9221fa826357931365c2b0aee9bee4d6b897d2901",
|
|
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": "
|
|
62
|
+
"composite": "4cc20a5426a9c3aa740be85866c49d15634406d55463a57ba6359cf57a9974f8"
|
|
63
63
|
}
|
package/dist/live-roots.d.ts
CHANGED
|
@@ -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. */
|
package/dist/live-roots.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"live-roots.d.ts","sourceRoot":"","sources":["../src/live-roots.ts"],"names":[],"mappings":"
|
|
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,8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5E,wBAAgB,WAAW,CAAC,CAAC,EAAE,SAAS,GAAG,MAAM,CAKhD;AAED,8FAA8F;AAC9F,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,GAAG,MAAM,CAKhE;AAED,gFAAgF;AAChF,eAAO,MAAM,YAAY,UAAW,SAAS,KAAG,OAAwC,CAAC;AAEzF;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,EAAE,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG;IAAE,MAAM,EAAE,YAAY,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAyBlK;AAED,yDAAyD;AACzD,MAAM,MAAM,aAAa,GAAG;IAAE,OAAO,EAAE,YAAY,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAE5E;;;;;GAKG;AACH,wBAAsB,gBAAgB,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"}
|
package/dist/live-roots.js
CHANGED
|
@@ -17,14 +17,22 @@
|
|
|
17
17
|
* {@link checkStoreBucket} and {@link bucketLines}: the setup as a log line,
|
|
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`,
|
|
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",
|
package/dist/manifest.json
CHANGED
|
@@ -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,4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,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAGxF;AAED,0EAA0E;AAC1E,wBAAgB,mBAAmB,IAAI,YAAY,GAAG,SAAS,CAE9D;AAED,yEAAyE;AACzE,wBAAgB,aAAa,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAAC,gBAAgB,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,GAAG,QAAQ,CAAC,CAOrH;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CA6B7D;AAKD,6GAA6G;AAC7G,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAqBnD"}
|
package/dist/reach.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a change reaches (#4984), beside ./changed-roots.ts: the roots,
|
|
3
|
+
* Terragrunt units, Atmos instances or synthesized roots a change from
|
|
4
|
+
* `from` to `to` reaches, read from git alone. Moved from terragucci's
|
|
5
|
+
* `reachedRoots`, `reachedUnits`, `reachedInstances` and
|
|
6
|
+
* `reachedSynthesized` (comment-apply.ts), for a product's reach line
|
|
7
|
+
* (`productPlan.reach`, #4979): the lock job and the decision before merge
|
|
8
|
+
* run it at the target branch's commit, so none of the change's code runs.
|
|
9
|
+
*
|
|
10
|
+
* Each follows what reads a reached target: a root that reads a reached
|
|
11
|
+
* root's state, a unit that names a reached unit in a `dependency` or
|
|
12
|
+
* `dependencies` block, an instance that depends on a reached one, followed
|
|
13
|
+
* through. The product hands the reads it knows (terragucci's
|
|
14
|
+
* `terraform_remote_state` edges and `waves.after`, Atmos's dependencies);
|
|
15
|
+
* the Terragrunt unit reads are parsed here, at both ends of the range.
|
|
16
|
+
* Markdown files reach nothing. When a change can reach anything, or git
|
|
17
|
+
* cannot diff the range, every target is reached and `every` says why.
|
|
18
|
+
*/
|
|
19
|
+
/** Git in a checkout: an argv after `git`, and what it answered. */
|
|
20
|
+
export type ReachGit = (args: string[]) => {
|
|
21
|
+
status: number | null;
|
|
22
|
+
stdout: string;
|
|
23
|
+
stderr: string;
|
|
24
|
+
};
|
|
25
|
+
/** What a change reaches, sorted, and why it is every target when it is. */
|
|
26
|
+
export interface Reach {
|
|
27
|
+
targets: string[];
|
|
28
|
+
every?: string;
|
|
29
|
+
}
|
|
30
|
+
/** The targets each target reads, so a change to one of those reaches it too. */
|
|
31
|
+
export type ReachReads = ReadonlyMap<string, ReadonlySet<string>>;
|
|
32
|
+
/** Changed files that reach nothing: documentation. */
|
|
33
|
+
export declare const READS_NOTHING: RegExp;
|
|
34
|
+
/** The files the change from `from` to `to` changes (`git diff --name-only from...to`), or undefined when git cannot say. */
|
|
35
|
+
export declare function changedFilesBetween(git: ReachGit, from: string, to: string): string[] | undefined;
|
|
36
|
+
/** Add to `selected` every target that reads a selected one, followed through. */
|
|
37
|
+
export declare function followReads(selected: Set<string>, reads: ReachReads | undefined): void;
|
|
38
|
+
/**
|
|
39
|
+
* The plain roots a change reaches: the roots whose files it changes, by
|
|
40
|
+
* chant's path rules (./changed-roots.ts: a root's directory, the local
|
|
41
|
+
* modules it calls, its var files), and every root that reads one of those.
|
|
42
|
+
* Every root when git cannot diff the range.
|
|
43
|
+
*/
|
|
44
|
+
export declare function reachedRoots(repo: string, git: ReachGit, from: string, to: string, roots: readonly string[], reads?: ReachReads): Reach;
|
|
45
|
+
/**
|
|
46
|
+
* The paths a unit's `terragrunt.hcl` names in its `dependency` blocks'
|
|
47
|
+
* `config_path` and its `dependencies` block's `paths`, when each is a plain
|
|
48
|
+
* string. A path built with a function or an interpolation is not read:
|
|
49
|
+
* only Terragrunt can evaluate it, and no Terragrunt runs on a change's
|
|
50
|
+
* files before a review.
|
|
51
|
+
*/
|
|
52
|
+
export declare function literalTerragruntDependencies(text: string): string[];
|
|
53
|
+
/**
|
|
54
|
+
* The Terragrunt units a change reaches. A unit is reached when a file
|
|
55
|
+
* under its directory changes (the deepest unit holding the file), and so
|
|
56
|
+
* is every unit that names a reached one with a plain path, at either end
|
|
57
|
+
* of the range. A changed file under no unit's directory (`root.hcl`, a
|
|
58
|
+
* module, a stack template) may change any unit, so it reaches every one.
|
|
59
|
+
*/
|
|
60
|
+
export declare function reachedUnits(git: ReachGit, from: string, to: string, units: readonly string[]): Reach;
|
|
61
|
+
/**
|
|
62
|
+
* The Atmos instances a change reaches. `componentOf` names each instance's
|
|
63
|
+
* component directory. A changed file under one reaches that component's
|
|
64
|
+
* instances; any other file (a stack manifest, a catalog, `atmos.yaml`) can
|
|
65
|
+
* change any instance's vars or backend, so it reaches every instance.
|
|
66
|
+
* Instances that read a reached one follow.
|
|
67
|
+
*/
|
|
68
|
+
export declare function reachedInstances(git: ReachGit, from: string, to: string, instances: readonly string[], componentOf: ReadonlyMap<string, string | undefined>, reads?: ReachReads): Reach;
|
|
69
|
+
/**
|
|
70
|
+
* The roots a change reaches when a command writes them (`synth`, CDK
|
|
71
|
+
* Terrain's stacks). The roots are not in git, so no diff names them, and
|
|
72
|
+
* the command is the change's own code: any changed file that is not
|
|
73
|
+
* Markdown can change any root.
|
|
74
|
+
*/
|
|
75
|
+
export declare function reachedSynthesized(git: ReachGit, from: string, to: string, roots: readonly string[]): Reach;
|
|
76
|
+
//# sourceMappingURL=reach.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reach.d.ts","sourceRoot":"","sources":["../src/reach.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAKH,oEAAoE;AACpE,MAAM,MAAM,QAAQ,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK;IAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAErG,4EAA4E;AAC5E,MAAM,WAAW,KAAK;IACpB,OAAO,E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