@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
@@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-apply`
3
+ * runs (chant#4865), and the async-local scope that carries it to the
4
+ * activities that run the binary. Kept apart from
5
+ * `./activities/terraform.ts` so the composed group's runs
6
+ * (`../components/compose-group.ts`, through `BinaryExec`) and the engine
7
+ * timings (`../engine-timings.ts`) read the same scope (chant#4887).
8
+ */
9
+ import { AsyncLocalStorage } from "node:async_hooks";
10
+ /**
11
+ * The command scope of the step call that runs the engine (chant#4865). An
12
+ * async-local store, so each root a wave runs at once (chant#4864) sees its
13
+ * own, and the activities need no hook argument threaded through.
14
+ */
15
+ const commandScope = new AsyncLocalStorage();
16
+ /**
17
+ * Run `fn` with every engine command it runs going through `hook`, as
18
+ * commands for `scope.root` (chant#4865). Inside another scope, a field this
19
+ * one leaves out (`upstream`, `members`) is not kept from the outer.
20
+ */
21
+ export function withTerraformCommandHook(hook, scope, fn) {
22
+ if (!hook)
23
+ return fn();
24
+ return commandScope.run({ hook, ...scope }, fn);
25
+ }
26
+ /** Run `fn` with the commands it runs marked as a read of `upstream`'s state for the scope's root (chant#4865). Outside a scope, `fn` as it is. */
27
+ export function asUpstreamCommands(upstream, fn) {
28
+ const scope = commandScope.getStore();
29
+ return scope ? commandScope.run({ ...scope, upstream }, fn) : fn();
30
+ }
31
+ /** The scope the current async call runs in, or undefined outside one. */
32
+ export function currentCommandScope() {
33
+ return commandScope.getStore();
34
+ }
35
+ /** The fields of a {@link TerraformCommand} that come from the scope. */
36
+ export function scopedCommand(scope) {
37
+ return {
38
+ root: scope.root,
39
+ ...(scope.upstream !== undefined ? { upstream: scope.upstream } : {}),
40
+ ...(scope.members !== undefined ? { members: [...scope.members] } : {}),
41
+ method: scope.method,
42
+ };
43
+ }
44
+ /**
45
+ * `exec` with each run going through the command hook of the step call it
46
+ * runs in (chant#4887), as the activities' own commands do: a composed
47
+ * group's `init`, `plan`, `show` and `apply`, and the `version` its estate
48
+ * check asks. The hook sees the variables the run sets over the job's
49
+ * environment, its variables are laid over the run's, and its `after` gets
50
+ * the exit code, time and output. Outside a scope, `exec` as it is.
51
+ */
52
+ export function hookedBinaryExec(exec) {
53
+ return async (binary, args, dir, env, io) => {
54
+ const scope = commandScope.getStore();
55
+ if (!scope)
56
+ return exec(binary, args, dir, env, io);
57
+ const own = { TF_IN_AUTOMATION: "1" };
58
+ for (const [k, v] of Object.entries(env))
59
+ if (v !== undefined && process.env[k] !== v)
60
+ own[k] = v;
61
+ const command = {
62
+ ...scopedCommand(scope),
63
+ binary,
64
+ name: args.find((a) => !a.startsWith("-")) ?? "",
65
+ args: [...args],
66
+ line: [binary, `-chdir=${dir}`, ...args].map((w) => (/^[\w@%+=:,./-]+$/.test(w) ? w : quoteWord(w))).join(" "),
67
+ cwd: dir,
68
+ env: own,
69
+ };
70
+ const given = (await scope.hook(command)) ?? {};
71
+ const start = performance.now();
72
+ let ran;
73
+ try {
74
+ ran = await exec(binary, args, dir, given.env ? { ...env, ...given.env } : env, io);
75
+ }
76
+ catch (err) {
77
+ await given.after?.({ code: null, seconds: (performance.now() - start) / 1000, stdout: "", stderr: err instanceof Error ? err.message : String(err) });
78
+ throw err;
79
+ }
80
+ // `out` holds stdout and stderr together, as they came; stderr alone is what is left once stdout is taken out of it.
81
+ const stderr = ran.out.startsWith(ran.stdout) ? ran.out.slice(ran.stdout.length) : ran.out;
82
+ await given.after?.({ code: ran.code, seconds: (performance.now() - start) / 1000, stdout: ran.stdout, stderr });
83
+ return ran;
84
+ };
85
+ }
86
+ /** A word single-quoted for a shell, as `quoteArg` writes it. */
87
+ const quoteWord = (w) => `'${w.replace(/'/g, `'\\''`)}'`;
88
+ /** The words of a command line the builders here wrote: plain words, and `quoteArg`'s single-quoted ones. */
89
+ export function commandWords(line) {
90
+ const words = [];
91
+ let word;
92
+ for (let i = 0; i < line.length; i++) {
93
+ const c = line[i];
94
+ if (c === " ") {
95
+ if (word !== undefined)
96
+ words.push(word);
97
+ word = undefined;
98
+ }
99
+ else if (c === "'") {
100
+ const end = line.indexOf("'", i + 1);
101
+ const stop = end < 0 ? line.length : end;
102
+ word = (word ?? "") + line.slice(i + 1, stop);
103
+ i = stop;
104
+ }
105
+ else if (c === "\\" && i + 1 < line.length) {
106
+ word = (word ?? "") + line[++i];
107
+ }
108
+ else {
109
+ word = (word ?? "") + c;
110
+ }
111
+ }
112
+ if (word !== undefined)
113
+ words.push(word);
114
+ return words;
115
+ }
@@ -28,4 +28,5 @@ export * from "./source-forms.js";
28
28
  export * from "./proxies.js";
29
29
  export { moduleConsumers, isLocalSource, type ModuleConsumer } from "../pin/consumers.js";
30
30
  export { usedSources, type UsedSource, type UnreadSource, type UsedSourcesOptions } from "../used-sources.js";
31
+ export { MODULE_CONSUMERS_FLOOR, USED_SOURCES_FLOOR } from "../chant-floors.js";
31
32
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/registry/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvF,OAAO,EAAE,WAAW,EAAE,KAAK,UAAU,EAAE,KAAK,YAAY,EAAE,KAAK,kBAAkB,EAAE,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/registry/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvF,OAAO,EAAE,WAAW,EAAE,KAAK,UAAU,EAAE,KAAK,YAAY,EAAE,KAAK,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAC3G,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC"}
@@ -28,3 +28,4 @@ export * from "./source-forms.js";
28
28
  export * from "./proxies.js";
29
29
  export { moduleConsumers, isLocalSource } from "../pin/consumers.js";
30
30
  export { usedSources } from "../used-sources.js";
31
+ export { MODULE_CONSUMERS_FLOOR, USED_SOURCES_FLOOR } from "../chant-floors.js";
@@ -12,6 +12,29 @@ export interface BinaryIo {
12
12
  export type BinaryExec = (binary: string, args: string[], dir: string, env: NodeJS.ProcessEnv, io?: BinaryIo) => Promise<Ran>;
13
13
  /** The binary run with `-chdir=<dir>` and `TF_IN_AUTOMATION=1`. */
14
14
  export declare const runBinary: BinaryExec;
15
+ /**
16
+ * `env` without the forge's tokens, for the engine (chant#4910): the
17
+ * providers, modules and external data sources the binary runs are the
18
+ * change's own code, and none of it needs the forge's API. Left out: chant's
19
+ * {@link FORGE_TOKEN_VARS}, the product's own token variables (`tokens`,
20
+ * such as terragucci's `TG_TOKEN` and `TG_MERGE_TOKEN`), and any other
21
+ * variable holding the same value as one of them (GitLab's `GITLAB_TOKEN`
22
+ * set from the product's, or a variable a product's `token_env` names). A
23
+ * variable whose name starts with `TF_` is passed as set, so a backend
24
+ * password or a `TF_VAR_` given to the binary on purpose still reaches it.
25
+ *
26
+ * Lifted from terragucci's `binaryEnv` (binary-env.ts).
27
+ */
28
+ export declare function engineEnv(env: NodeJS.ProcessEnv, tokens?: readonly string[]): NodeJS.ProcessEnv;
29
+ /**
30
+ * {@link runBinary} with the forge's tokens left out of the binary's
31
+ * environment ({@link engineEnv}), `tokens` naming the product's own
32
+ * (chant#4910). A product that ran the binary through its own wrapper over
33
+ * `runBinary` passes this one wherever a `BinaryExec` is taken. `runBinary`
34
+ * itself still passes the environment as given, since a project's provider
35
+ * may read a forge token on purpose (the GitHub provider reads `GITHUB_TOKEN`).
36
+ */
37
+ export declare function tokenlessBinaryExec(tokens?: readonly string[], exec?: BinaryExec): BinaryExec;
15
38
  /** A state file as `state pull` prints it (format version 4); only what a run touches is named. */
16
39
  export interface StateFile {
17
40
  version: number;
@@ -1 +1 @@
1
- {"version":3,"file":"exec.d.ts","sourceRoot":"","sources":["../../src/state/exec.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,GAAG;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,gDAAgD;IAChD,GAAG,EAAE,MAAM,CAAC;CACb;AAED,2JAA2J;AAC3J,MAAM,WAAW,QAAQ;IACvB,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;CACpC;AAED,uEAAuE;AACvE,MAAM,MAAM,UAAU,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,UAAU,EAAE,EAAE,CAAC,EAAE,QAAQ,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;AAE9H,mEAAmE;AACnE,eAAO,M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CACtB;AAED,wEAAwE;AACxE,eAAO,MAAM,SAAS,MAAO,MAAM,iBAAU,MAAgE,CAAC;AAE9G,yEAAyE;AACzE,wBAAsB,SAAS,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,UAAU,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAc9I"}
@@ -6,6 +6,7 @@
6
6
  * `BinaryExec`, `runBinary`, `StateFile`, `StateResource` and `pullState`.
7
7
  */
8
8
  import { spawn } from "node:child_process";
9
+ import { FORGE_TOKEN_VARS } from "@intentius/chant/ci-handover";
9
10
  /** The binary run with `-chdir=<dir>` and `TF_IN_AUTOMATION=1`. */
10
11
  export const runBinary = (binary, args, dir, env, io) => new Promise((done) => {
11
12
  const child = spawn(binary, [`-chdir=${dir}`, ...args], { env: { ...env, TF_IN_AUTOMATION: "1" }, stdio: ["ignore", "pipe", "pipe"] });
@@ -55,6 +56,43 @@ export const runBinary = (binary, args, dir, env, io) => new Promise((done) => {
55
56
  done({ code: code ?? 1, stdout, out });
56
57
  });
57
58
  });
59
+ /**
60
+ * `env` without the forge's tokens, for the engine (chant#4910): the
61
+ * providers, modules and external data sources the binary runs are the
62
+ * change's own code, and none of it needs the forge's API. Left out: chant's
63
+ * {@link FORGE_TOKEN_VARS}, the product's own token variables (`tokens`,
64
+ * such as terragucci's `TG_TOKEN` and `TG_MERGE_TOKEN`), and any other
65
+ * variable holding the same value as one of them (GitLab's `GITLAB_TOKEN`
66
+ * set from the product's, or a variable a product's `token_env` names). A
67
+ * variable whose name starts with `TF_` is passed as set, so a backend
68
+ * password or a `TF_VAR_` given to the binary on purpose still reaches it.
69
+ *
70
+ * Lifted from terragucci's `binaryEnv` (binary-env.ts).
71
+ */
72
+ export function engineEnv(env, tokens = []) {
73
+ const names = new Set([...FORGE_TOKEN_VARS, ...tokens]);
74
+ const secrets = new Set([...names].map((n) => env[n]).filter((v) => typeof v === "string" && v.length > 0));
75
+ const out = {};
76
+ for (const [k, v] of Object.entries(env)) {
77
+ if (names.has(k))
78
+ continue;
79
+ if (v !== undefined && secrets.has(v) && !k.startsWith("TF_"))
80
+ continue;
81
+ out[k] = v;
82
+ }
83
+ return out;
84
+ }
85
+ /**
86
+ * {@link runBinary} with the forge's tokens left out of the binary's
87
+ * environment ({@link engineEnv}), `tokens` naming the product's own
88
+ * (chant#4910). A product that ran the binary through its own wrapper over
89
+ * `runBinary` passes this one wherever a `BinaryExec` is taken. `runBinary`
90
+ * itself still passes the environment as given, since a project's provider
91
+ * may read a forge token on purpose (the GitHub provider reads `GITHUB_TOKEN`).
92
+ */
93
+ export function tokenlessBinaryExec(tokens = [], exec = runBinary) {
94
+ return (binary, args, dir, env, io) => exec(binary, args, dir, engineEnv(env, tokens), io);
95
+ }
58
96
  /** The last lines of the binary's output, on one line, for an error. */
59
97
  export const lastLines = (s, n = 4) => s.trim().split("\n").slice(-n).join(" ").slice(0, 400);
60
98
  /** A root's state as `state pull` gives it, or null when it has none. */
@@ -1 +1 @@
1
- {"version":3,"file":"state-ops.d.ts","sourceRoot":"","sources":["../src/state-ops.ts"],"names":[],"mappings":"AAuCA,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,wCAAwC,CAAC;AACzF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAEjE,OAAO,EAAsB,KAAK,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AACzH,OAAO,EAAE,OAAO,EAAE,MAAM,qCAAqC,CAAC;AAC9D,OAAO,EAAwC,KAAK,gBAAgB,EAAE,KAAK,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACrI,OAAO,EAAoE,KAAK,eAAe,EAAE,KAAK,gBAAgB,EAAE,KAAK,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAGvL,OAAO,EAA6D,KAAK,WAAW,EAAE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OAAO,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;CAC9B;AAuBD,eAAO,MAAM,8BAA8B,EAAE,UAAU,CAAC,oBAAoB,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAgBzG,CAAC;AAEF,eAAO,MAAM,4BAA4B,EAAE,UAAU,CAAC,kBAAkB,EAAE;IAAE,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,CAqB5F,CAAC;AAQF,eAAO,MAAM,uBAAuB,EAAE,UAAU,CAAC,aAAa,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAiBnG,CAAC;AAEF,qEAAqE;AACrE,eAAO,MAAM,4BAA4B;UAnE6C,MAAM;QAAM,MAAM;;WAkBrB,MAAM,EAAE;;UA6BnB,MAAM;gBAAc,MAAM;GAoB0C,CAAC"}
package/dist/state-ops.js CHANGED
@@ -49,6 +49,7 @@ import { lastLines, runBinary } from "./state/exec.js";
49
49
  import { gitlabStore, shownUrl } from "./state/gitlab.js";
50
50
  import { stateStore } from "./state/store.js";
51
51
  import { gitlabVersionSource, stateVersionSource } from "./state/versions.js";
52
+ import { actorFromEnv } from "@intentius/chant/actor";
52
53
  /** The ops the gated requests of this module wait at, one per kind, as terragucci named them. */
53
54
  export const STATE_OPS = {
54
55
  unlock: "tf-unlock",
@@ -273,7 +274,8 @@ export async function terraformStateUnlock(input) {
273
274
  return releaseStateLock({ ...input, subject: input.root, lock });
274
275
  });
275
276
  }
276
- const actorOf = (env) => env.GITHUB_ACTOR || env.GITLAB_USER_LOGIN || env.USER || env.USERNAME || "unknown";
277
+ /** Who asks when the caller names nobody: core's actor fallback (#4911). */
278
+ const actorOf = (env) => actorFromEnv(env);
277
279
  const dirOf = (cwd, input) => input.dir ?? join(cwd ?? process.cwd(), input.root);
278
280
  async function gatedRun(op, input, kind, fields, act, attachment) {
279
281
  const cwd = input.cwd ?? process.cwd();
@@ -2,7 +2,8 @@
2
2
  * Terragrunt units as roots (#3414). `./units`, `./wave` and `./mocks` are pure and
3
3
  * bundle without TypeScript; `./run` spawns `terragrunt`. `./affected` picks
4
4
  * the units a git range touches (#3415). `./capability` is `terragrunt-apply`,
5
- * the units as an op wave's step (#4842).
5
+ * the units as an op wave's step (#4842). `./place` is where a unit's binary runs
6
+ * as Terragrunt prepares it (#4910).
6
7
  */
7
8
  export * from "./units.js";
8
9
  export * from "./wave.js";
@@ -10,4 +11,5 @@ export * from "./mocks.js";
10
11
  export * from "./run.js";
11
12
  export * from "./affected.js";
12
13
  export * from "./capability.js";
14
+ export * from "./place.js";
13
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/terragrunt/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC;AACtB,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/terragrunt/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC;AACtB,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC"}
@@ -2,7 +2,8 @@
2
2
  * Terragrunt units as roots (#3414). `./units`, `./wave` and `./mocks` are pure and
3
3
  * bundle without TypeScript; `./run` spawns `terragrunt`. `./affected` picks
4
4
  * the units a git range touches (#3415). `./capability` is `terragrunt-apply`,
5
- * the units as an op wave's step (#4842).
5
+ * the units as an op wave's step (#4842). `./place` is where a unit's binary runs
6
+ * as Terragrunt prepares it (#4910).
6
7
  */
7
8
  export * from "./units.js";
8
9
  export * from "./wave.js";
@@ -10,3 +11,4 @@ export * from "./mocks.js";
10
11
  export * from "./run.js";
11
12
  export * from "./affected.js";
12
13
  export * from "./capability.js";
14
+ export * from "./place.js";
@@ -0,0 +1,27 @@
1
+ import { type TerragruntExec } from "./run.js";
2
+ /** Where a unit's binary runs: its directory, and the job's environment with what Terragrunt adds. */
3
+ export interface UnitPlace {
4
+ dir: string;
5
+ env: NodeJS.ProcessEnv;
6
+ }
7
+ /** A unit Terragrunt could not prepare. */
8
+ export declare class UnitPlaceError extends Error {
9
+ constructor(message: string);
10
+ }
11
+ export interface UnitPlaceInput {
12
+ /** The directory Terragrunt runs in; `unit` is relative to it. */
13
+ projectDir: string;
14
+ unit: string;
15
+ /** The binary Terragrunt calls through the wrapper. */
16
+ binary: string;
17
+ env: NodeJS.ProcessEnv;
18
+ /** A directory of the caller's, which the wrapper and its record go under. */
19
+ work: string;
20
+ /** The `terragrunt` executable. Default `terragrunt` on `PATH`. */
21
+ terragrunt?: string;
22
+ /** How Terragrunt runs. Default {@link defaultTerragruntExec}. */
23
+ exec?: TerragruntExec;
24
+ }
25
+ /** The unit's place, as Terragrunt prepares it. Throws {@link UnitPlaceError} when its init fails or never runs the binary. */
26
+ export declare function terragruntUnitPlace(input: UnitPlaceInput): Promise<UnitPlace>;
27
+ //# sourceMappingURL=place.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"place.d.ts","sourceRoot":"","sources":["../../src/terragrunt/place.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAyB,KAAK,cAAc,EAAE,MAAM,OAAO,CAAC;AAEnE,sGAAsG;AACtG,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;CACxB;AAED,2CAA2C;AAC3C,qBAAa,cAAe,SAAQ,KAAK;IACvC,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAED,MAAM,WAAW,cAAc;IAC7B,kEAAkE;IAClE,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,uDAAuD;IACvD,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;IACvB,8EAA8E;IAC9E,IAAI,EAAE,MAAM,CAAC;IACb,mEAAmE;IACnE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kEAAkE;IAClE,IAAI,CAAC,EAAE,cAAc,CAAC;CACvB;AAKD,+HAA+H;AAC/H,wBAAsB,mBAAmB,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,SAAS,CAAC,CAmBnF"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Where a Terragrunt unit's binary runs (chant#4910): its working directory
3
+ * and environment as Terragrunt prepares them, so a reader or writer of the
4
+ * unit's state (a state migration, an export, an ephemeral environment) runs
5
+ * the binary there as for a plain root.
6
+ *
7
+ * `terragrunt run -- init` in the unit, with `TG_TF_PATH` a wrapper that
8
+ * records the directory and the environment Terragrunt runs the binary in
9
+ * (its working directory, in Terragrunt's cache when the unit names a
10
+ * source, with backend.tf and provider.tf generated, and its inputs as
11
+ * `TF_VAR_` variables) and then runs the binary. The wrapper records with
12
+ * the running Node (`process.execPath`), so it needs nothing on `PATH`.
13
+ *
14
+ * Lifted from terragucci's `unitPlace` (migrate.ts), so terragucci deletes
15
+ * its copy.
16
+ */
17
+ import { chmodSync, existsSync, mkdtempSync, readFileSync, writeFileSync } from "node:fs";
18
+ import { basename, join } from "node:path";
19
+ import { defaultTerragruntExec } from "./run.js";
20
+ /** A unit Terragrunt could not prepare. */
21
+ export class UnitPlaceError extends Error {
22
+ constructor(message) {
23
+ super(message);
24
+ this.name = "UnitPlaceError";
25
+ }
26
+ }
27
+ /** The variables of the wrapper's own run that are not Terragrunt's additions. */
28
+ const SHELL_VARS = new Set(["TG_TF_PATH", "PWD", "OLDPWD", "SHLVL", "_"]);
29
+ /** The unit's place, as Terragrunt prepares it. Throws {@link UnitPlaceError} when its init fails or never runs the binary. */
30
+ export async function terragruntUnitPlace(input) {
31
+ const { unit, binary, env } = input;
32
+ const capture = mkdtempSync(join(input.work, "unit-"));
33
+ const file = join(capture, "place.json");
34
+ const wrapper = join(capture, basename(binary) || "tofu");
35
+ const q = (x) => `'${x.replace(/'/g, `'\\''`)}'`;
36
+ const record = `require("fs").writeFileSync(process.argv[1], JSON.stringify({ dir: process.cwd(), env: process.env }))`;
37
+ writeFileSync(wrapper, `#!/bin/sh\n${q(process.execPath)} -e ${q(record)} ${q(file)}\nexec ${q(binary)} "$@"\n`);
38
+ chmodSync(wrapper, 0o755);
39
+ const run = await (input.exec ?? defaultTerragruntExec)(input.terragrunt ?? "terragrunt", ["run", "--non-interactive", "--no-color", "--working-dir", unit, "--", "init", "-input=false", "-no-color"], {
40
+ cwd: input.projectDir,
41
+ env: { ...env, TG_TF_PATH: wrapper, TG_NON_INTERACTIVE: "true" },
42
+ });
43
+ if (run.code !== 0)
44
+ throw new UnitPlaceError(`terragrunt could not prepare ${unit} (init failed): ${lastLines(run.stderr || run.stdout)}`);
45
+ if (!existsSync(file))
46
+ throw new UnitPlaceError(`terragrunt prepared ${unit} without running ${binary}, so where it runs is not known`);
47
+ const got = JSON.parse(readFileSync(file, "utf-8"));
48
+ // The binary's own variables from Terragrunt: the unit's inputs, and any credentials an iam_role gave it.
49
+ const added = Object.fromEntries(Object.entries(got.env).filter(([k, v]) => env[k] !== v && !SHELL_VARS.has(k)));
50
+ return { dir: got.dir, env: { ...env, ...added } };
51
+ }
52
+ const lastLines = (s, n = 4) => s.trim().split("\n").slice(-n).join(" ").slice(0, 400);
@@ -6,6 +6,7 @@
6
6
  * acceptance test runs the real binary.
7
7
  */
8
8
  import type { ChangeSetPart, ChangeSetPlanner } from "@intentius/chant/change-set";
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;;;;;;GAMG;AAKH,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAEnF,OAAO,EAKL,K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GAAG,EAAE,MAAM,CAAC;CACb;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,kBAAkB,CAAC,KAAK,EAAE,sBAAsB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAwDnG;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,oBAAoB,EAAE,CAAC;IAChC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC;CACb;AAED;;;;;GAKG;AACH,wBAAsB,mBAAmB,CAAC,KAAK,EAAE,sBAAsB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CA6BrG"}
@@ -6,8 +6,8 @@
6
6
  * acceptance test runs the real binary.
7
7
  */
8
8
  import { execFile } from "node:child_process";
9
- import { existsSync, mkdirSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
10
- import { dirname, join, resolve } from "node:path";
9
+ import { chmodSync, existsSync, mkdirSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
10
+ import { basename, dirname, join, resolve } from "node:path";
11
11
  import { plannerForBinary } from "../change-set.js";
12
12
  import { parseTerragruntFind, terragruntFindArgs, terragruntVersionProblem, unitPathFilter, } from "./units.js";
13
13
  import { describeMockRefusal, failMockedParts, hasExpandedDependency, markProvisional, parseRenderedDependencies, parseTerragruntOutputs, PROVISIONAL_MARKER, terragruntMockReads, terragruntMockWarnings, terragruntOutputArgs, terragruntOutputUpstreams, terragruntRenderArgs, } from "./mocks.js";
@@ -92,6 +92,100 @@ export function terraformBinaryWarnings(dir, units, binary) {
92
92
  export function terragruntPlanner(binary) {
93
93
  return plannerForBinary(binary ?? "tofu");
94
94
  }
95
+ /** A word single-quoted for `sh`. */
96
+ const shq = (s) => `'${s.replace(/'/g, `'\\''`)}'`;
97
+ /**
98
+ * The `TG_TF_PATH` wrapper for one wave (chant#4954): a shell script that
99
+ * runs `binary` with the variables of the unit whose plan it runs.
100
+ * Terragrunt hands each unit's plan `-out=<out-dir>/<unit>/tfplan.tfplan`,
101
+ * which names the unit; every other call (init, show, output, version) runs
102
+ * the binary as it is. `outDirs` are the wave's plan directory as given and
103
+ * as its real path. Lifted from terragucci's `unitWrapper` (report/stage.ts).
104
+ */
105
+ export function terragruntUnitWrapper(binary, outDirs, units) {
106
+ const lines = [
107
+ "#!/bin/sh",
108
+ "# chant: each unit's plan runs with the variables its command hook answered. Written for one wave.",
109
+ 'out=""',
110
+ 'prev=""',
111
+ 'for a in "$@"; do',
112
+ ' case "$a" in -out=*|--out=*) out="${a#*=}" ;; esac',
113
+ ' if [ "$prev" = "-out" ] || [ "$prev" = "--out" ]; then out="$a"; fi',
114
+ ' prev="$a"',
115
+ "done",
116
+ 'case "$out" in',
117
+ ];
118
+ for (const [unit, vars] of units) {
119
+ const set = Object.entries(vars).filter(([k]) => /^[A-Za-z_][A-Za-z0-9_]*$/.test(k));
120
+ if (set.length === 0)
121
+ continue;
122
+ const patterns = [...new Set(outDirs.map((d) => join(d, unit, "tfplan.tfplan")))].map(shq).join(" | ");
123
+ lines.push(` ${patterns}) export ${set.map(([k, v]) => `${k}=${shq(v)}`).join(" ")} ;;`);
124
+ }
125
+ lines.push("esac", `exec ${shq(binary)} "$@"`);
126
+ return lines.join("\n") + "\n";
127
+ }
128
+ /**
129
+ * Ask `hook` for each unit's plan before the wave runs (chant#4954), and
130
+ * write the wrapper that hands each its variables when any has some.
131
+ * Answers the variables the run adds and what to call once the run report
132
+ * is read.
133
+ */
134
+ async function unitCommandRuns(hook, input, work, outDir, waveArgs) {
135
+ const units = [...new Set(input.units)].sort();
136
+ const args = waveArgs.slice(waveArgs.indexOf("--") + 1);
137
+ const runs = new Map();
138
+ for (const unit of units) {
139
+ const command = {
140
+ root: unit,
141
+ method: "plan",
142
+ binary: input.binary,
143
+ name: "plan",
144
+ args: [...args],
145
+ line: [input.binary, ...args].map((w) => (/^[\w@%+=:,./-]+$/.test(w) ? w : shq(w))).join(" "),
146
+ cwd: resolve(input.dir, unit),
147
+ env: {},
148
+ };
149
+ runs.set(unit, (await hook(command)) ?? {});
150
+ }
151
+ const vars = new Map([...runs].map(([unit, run]) => [unit, run.env ?? {}]));
152
+ let env = {};
153
+ if ([...vars.values()].some((v) => Object.keys(v).length > 0)) {
154
+ let real = outDir;
155
+ try {
156
+ real = join(realpathSync(work), "plans");
157
+ }
158
+ catch {
159
+ // The path as given is matched alone.
160
+ }
161
+ const bin = join(work, "unit-bin");
162
+ mkdirSync(bin, { recursive: true });
163
+ // The wrapper carries the binary's name, which Terragrunt prefixes its log lines with.
164
+ const wrapper = join(bin, basename(input.binary) || "tofu");
165
+ writeFileSync(wrapper, terragruntUnitWrapper(input.binary, [outDir, real], vars));
166
+ chmodSync(wrapper, 0o755);
167
+ env = { TG_TF_PATH: wrapper };
168
+ }
169
+ const done = async (report) => {
170
+ for (const [unit, run] of runs) {
171
+ if (!run.after)
172
+ continue;
173
+ const row = report.get(unit);
174
+ const start = row?.started ? Date.parse(row.started) : NaN;
175
+ const end = row?.ended ? Date.parse(row.ended) : NaN;
176
+ const timed = Number.isFinite(start) && Number.isFinite(end) && end >= start;
177
+ const why = row && row.result !== "succeeded" ? [row.result, row.reason, row.cause].filter(Boolean).join(": ") : "";
178
+ await run.after({
179
+ code: row ? (row.result === "succeeded" ? 0 : 1) : null,
180
+ seconds: timed ? (end - start) / 1000 : 0,
181
+ stdout: "",
182
+ stderr: row ? why : "not in Terragrunt's run report, so it did not run",
183
+ ...(timed ? { at: { start, end } } : {}),
184
+ });
185
+ }
186
+ };
187
+ return { env, done };
188
+ }
95
189
  /**
96
190
  * Thrown when a wave's plans would read `mock_outputs` (#3416). Nothing in
97
191
  * the wave was planned, so there is nothing to gate. `reads` names each unit,
@@ -242,8 +336,18 @@ export async function planTerragruntWave(input) {
242
336
  ...(input.destroy ? { destroy: true } : {}),
243
337
  ...(input.parallelism !== undefined ? { parallelism: input.parallelism } : {}),
244
338
  });
245
- const r = await exec(tg, args, { cwd: input.dir, env: terragruntEnv(input.binary) });
339
+ // chant#4954: each unit's plan goes through the product's hook, its variables through a TG_TF_PATH wrapper.
340
+ const units = input.onCommand && input.binary ? await unitCommandRuns(input.onCommand, { ...input, binary: input.binary }, work, outDir, args) : undefined;
341
+ let r;
342
+ try {
343
+ r = await exec(tg, args, { cwd: input.dir, env: { ...terragruntEnv(input.binary), ...(units?.env ?? {}) } });
344
+ }
345
+ catch (err) {
346
+ await units?.done(new Map());
347
+ throw err;
348
+ }
246
349
  const report = existsSync(reportFile) ? parseTerragruntReport(readFileSync(reportFile, "utf8")) : new Map();
350
+ await units?.done(report);
247
351
  const planFor = (unit) => {
248
352
  const f = join(jsonOutDir, unit, "tfplan.json");
249
353
  return existsSync(f) ? JSON.parse(readFileSync(f, "utf8")) : undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intentius/chant-lexicon-terraform",
3
- "version": "0.124.87",
3
+ "version": "0.124.89",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src/",
@@ -93,7 +93,7 @@
93
93
  "access": "public"
94
94
  },
95
95
  "peerDependencies": {
96
- "@intentius/chant": "^0.124.87",
96
+ "@intentius/chant": "^0.124.89",
97
97
  "zod": "^4.3.6"
98
98
  },
99
99
  "description": "terraform lexicon for chant, existing Terraform root modules as declarable entities",
package/src/action-ops.ts CHANGED
@@ -48,6 +48,7 @@ import { terraformChangeSetPart } from "./change-set";
48
48
  import { DEFAULT_LOCK_TIMEOUT, lockTimeoutArgs } from "./lock-timeout";
49
49
  import { lastLines, runBinary, type BinaryExec } from "./state/exec";
50
50
  import { gatedStateOp, StateOpError, StateOpWaitingError, type GatedRequestLedger } from "./state-ops";
51
+ import { actorFromEnv } from "@intentius/chant/actor";
51
52
 
52
53
  /** The op an action's request waits at. */
53
54
  export const ACTION_OP = "tf-action";
@@ -323,7 +324,8 @@ export interface ActionStepInput {
323
324
  lockTimeout?: string | false;
324
325
  }
325
326
 
326
- const actorOf = (env: NodeJS.ProcessEnv): string => env.GITHUB_ACTOR || env.GITLAB_USER_LOGIN || env.USER || env.USERNAME || "unknown";
327
+ /** Who asks when the caller names nobody: core's actor fallback (#4911). */
328
+ const actorOf = (env: NodeJS.ProcessEnv): string => actorFromEnv(env);
327
329
 
328
330
  function stepInvoke(input: ActionStepInput): InvokeActionInput {
329
331
  const cwd = input.cwd ?? process.cwd();