@intentius/chant-lexicon-terraform 0.124.85 → 0.124.87

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 (65) hide show
  1. package/dist/ci-setup.d.ts +11 -2
  2. package/dist/ci-setup.d.ts.map +1 -1
  3. package/dist/ci-setup.js +11 -6
  4. package/dist/components/capability-plugin.d.ts +12 -0
  5. package/dist/components/capability-plugin.d.ts.map +1 -1
  6. package/dist/components/capability-plugin.js +22 -4
  7. package/dist/compose.d.ts.map +1 -1
  8. package/dist/compose.js +1 -1
  9. package/dist/estate-migration.d.ts +101 -0
  10. package/dist/estate-migration.d.ts.map +1 -0
  11. package/dist/estate-migration.js +471 -0
  12. package/dist/integrity.json +2 -2
  13. package/dist/manifest.json +1 -1
  14. package/dist/op/activities/terraform.d.ts +65 -0
  15. package/dist/op/activities/terraform.d.ts.map +1 -1
  16. package/dist/op/activities/terraform.js +94 -1
  17. package/dist/state/backend.d.ts +46 -9
  18. package/dist/state/backend.d.ts.map +1 -1
  19. package/dist/state/backend.js +84 -31
  20. package/dist/state/gitlab.d.ts +1 -1
  21. package/dist/state/gitlab.d.ts.map +1 -1
  22. package/dist/state/gitlab.js +27 -14
  23. package/dist/state/index.d.ts +1 -0
  24. package/dist/state/index.d.ts.map +1 -1
  25. package/dist/state/index.js +1 -0
  26. package/dist/state/s3.d.ts +9 -3
  27. package/dist/state/s3.d.ts.map +1 -1
  28. package/dist/state/s3.js +4 -3
  29. package/dist/state/source.d.ts +92 -0
  30. package/dist/state/source.d.ts.map +1 -0
  31. package/dist/state/source.js +254 -0
  32. package/dist/state/store.d.ts +41 -4
  33. package/dist/state/store.d.ts.map +1 -1
  34. package/dist/state/store.js +125 -10
  35. package/dist/state/versions.d.ts +77 -10
  36. package/dist/state/versions.d.ts.map +1 -1
  37. package/dist/state/versions.js +118 -64
  38. package/dist/state-migration.d.ts +43 -1
  39. package/dist/state-migration.d.ts.map +1 -1
  40. package/dist/state-migration.js +251 -20
  41. package/dist/state-ops.d.ts +2 -3
  42. package/dist/state-ops.d.ts.map +1 -1
  43. package/dist/state-ops.js +4 -7
  44. package/package.json +2 -2
  45. package/src/ci-setup.test.ts +20 -0
  46. package/src/ci-setup.ts +11 -6
  47. package/src/components/capability-plugin.ts +36 -3
  48. package/src/components/terraform-apply-command-hook.test.ts +157 -0
  49. package/src/compose.ts +1 -0
  50. package/src/estate-migration.test.ts +186 -0
  51. package/src/estate-migration.ts +563 -0
  52. package/src/op/activities/terraform.ts +153 -3
  53. package/src/state/backend-verdict.test.ts +4 -3
  54. package/src/state/backend.test.ts +3 -1
  55. package/src/state/backend.ts +108 -33
  56. package/src/state/gitlab.ts +25 -12
  57. package/src/state/index.ts +1 -0
  58. package/src/state/s3.ts +5 -4
  59. package/src/state/source.ts +289 -0
  60. package/src/state/store.ts +145 -11
  61. package/src/state/versions.test.ts +365 -0
  62. package/src/state/versions.ts +148 -68
  63. package/src/state-migration-backends.test.ts +277 -0
  64. package/src/state-migration.ts +265 -23
  65. package/src/state-ops.ts +6 -8
@@ -38,6 +38,7 @@
38
38
  * module load (`ensureChoudoufuVersion`) and refuses a binary older than
39
39
  * {@link MIN_CHOUDOUFU_VERSION}.
40
40
  */
41
+ import { AsyncLocalStorage } from "node:async_hooks";
41
42
  import { exec } from "node:child_process";
42
43
  import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
43
44
  import { tmpdir } from "node:os";
@@ -538,13 +539,105 @@ async function resolveRoot(args, signal) {
538
539
  projectRoot,
539
540
  };
540
541
  }
542
+ /**
543
+ * The command scope of the step call that runs the engine (chant#4865). An
544
+ * async-local store, so each root a wave runs at once (chant#4864) sees its
545
+ * own, and the activities need no hook argument threaded through.
546
+ */
547
+ const commandScope = new AsyncLocalStorage();
548
+ /**
549
+ * Run `fn` with every engine command it runs going through `hook`, as
550
+ * commands for `scope.root` (chant#4865). Inside another scope, a field this
551
+ * one leaves out (`upstream`) is not kept from the outer.
552
+ */
553
+ export function withTerraformCommandHook(hook, scope, fn) {
554
+ if (!hook)
555
+ return fn();
556
+ return commandScope.run({ hook, ...scope }, fn);
557
+ }
558
+ /** 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. */
559
+ export function asUpstreamCommands(upstream, fn) {
560
+ const scope = commandScope.getStore();
561
+ return scope ? commandScope.run({ ...scope, upstream }, fn) : fn();
562
+ }
563
+ /** The words of a command line the builders here wrote: plain words, and `quoteArg`'s single-quoted ones. */
564
+ export function commandWords(line) {
565
+ const words = [];
566
+ let word;
567
+ for (let i = 0; i < line.length; i++) {
568
+ const c = line[i];
569
+ if (c === " ") {
570
+ if (word !== undefined)
571
+ words.push(word);
572
+ word = undefined;
573
+ }
574
+ else if (c === "'") {
575
+ const end = line.indexOf("'", i + 1);
576
+ const stop = end < 0 ? line.length : end;
577
+ word = (word ?? "") + line.slice(i + 1, stop);
578
+ i = stop;
579
+ }
580
+ else if (c === "\\" && i + 1 < line.length) {
581
+ word = (word ?? "") + line[++i];
582
+ }
583
+ else {
584
+ word = (word ?? "") + c;
585
+ }
586
+ }
587
+ if (word !== undefined)
588
+ words.push(word);
589
+ return words;
590
+ }
541
591
  /** Run `cmd` in `dir`, forwarding the signal so an abort kills the child. */
542
- async function run(cmd, dir, env, signal, unset = []) {
592
+ function runPlain(cmd, dir, env, signal, unset = []) {
543
593
  const merged = { ...process.env, ...env };
544
594
  for (const name of unset)
545
595
  delete merged[name];
546
596
  return execAsync(cmd, { cwd: dir, env: merged, signal, maxBuffer: MAX_BUFFER });
547
597
  }
598
+ /**
599
+ * Run `cmd` in `dir` ({@link runPlain}), through the command hook of the
600
+ * step call it runs in (chant#4865): the hook's variables over `env`, still
601
+ * less `unset`, and its `after` with the exit code, time and output.
602
+ */
603
+ async function run(cmd, dir, env, signal, unset = []) {
604
+ const scope = commandScope.getStore();
605
+ if (!scope)
606
+ return runPlain(cmd, dir, env, signal, unset);
607
+ const words = commandWords(cmd);
608
+ const args = words.slice(1);
609
+ const command = {
610
+ root: scope.root,
611
+ ...(scope.upstream !== undefined ? { upstream: scope.upstream } : {}),
612
+ method: scope.method,
613
+ binary: words[0] ?? "",
614
+ name: args.find((a) => !a.startsWith("-")) ?? "",
615
+ args,
616
+ line: cmd,
617
+ cwd: dir,
618
+ env: { ...env },
619
+ };
620
+ const given = (await scope.hook(command)) ?? {};
621
+ const start = performance.now();
622
+ const took = () => (performance.now() - start) / 1000;
623
+ let out;
624
+ try {
625
+ out = await runPlain(cmd, dir, given.env ? { ...env, ...given.env } : env, signal, unset);
626
+ }
627
+ catch (err) {
628
+ const failure = err;
629
+ const seconds = took();
630
+ await given.after?.({
631
+ code: typeof failure.code === "number" ? failure.code : null,
632
+ seconds,
633
+ stdout: failure.stdout ?? "",
634
+ stderr: failure.stderr ?? (err instanceof Error ? err.message : String(err)),
635
+ });
636
+ throw err;
637
+ }
638
+ await given.after?.({ code: 0, seconds: took(), stdout: out.stdout, stderr: out.stderr });
639
+ return out;
640
+ }
548
641
  /**
549
642
  * Echo a subprocess's own output to the console for a human watching a
550
643
  * `chant run` step. Both streams land on real stderr (`console.error`),
@@ -1,5 +1,7 @@
1
+ import type { StoreHints } from "@intentius/chant/object-store";
1
2
  import { type AzureOidc } from "./azure-blob.js";
2
3
  import { type GcsTarget } from "./gcs.js";
4
+ import { type GitLabState } from "./gitlab.js";
3
5
  import { type S3Target } from "./s3.js";
4
6
  /** The backend `init` recorded: its type and configuration. */
5
7
  export interface InitialisedBackend {
@@ -41,8 +43,14 @@ export interface AzureState {
41
43
  key: string;
42
44
  /** The backend snapshots the blob before each write (`snapshot = true`). */
43
45
  snapshot: boolean;
44
- /** The account's blob endpoint. */
45
- endpoint: string;
46
+ /** The account's blob endpoint, when the cloud is one chant knows; else `metadataHost` names it. */
47
+ endpoint?: string;
48
+ /**
49
+ * The host of the cloud's metadata (`metadata_host`), whose storage suffix
50
+ * names the endpoint, for a cloud other than public, china or
51
+ * usgovernment. The store reads it when it first calls the account (#4793).
52
+ */
53
+ metadataHost?: string;
46
54
  auth: AzureAuth;
47
55
  }
48
56
  /** A local state file, its path relative to the root (or absolute). */
@@ -57,19 +65,36 @@ export interface StateRefusal {
57
65
  refused: StateRefusalKind;
58
66
  reason: string;
59
67
  }
60
- /** Where a root's state lives, or why chant does not lock it. */
61
- export type StateObject = S3State | GcsState | AzureState | LocalState | StateRefusal;
68
+ /** Where a root's state lives, or why chant does not lock it. An http backend's is a GitLab-managed state (./gitlab.ts). */
69
+ export type StateObject = S3State | GcsState | AzureState | LocalState | GitLabState | StateRefusal;
62
70
  /** A state in a bucket or a container. */
63
71
  export type StoredState = S3State | GcsState | AzureState;
64
72
  /** A state chant locks and writes. */
65
- export type LockableState = StoredState | LocalState;
73
+ export type LockableState = StoredState | LocalState | GitLabState;
66
74
  export declare const isRefused: (o: StateObject) => o is StateRefusal;
67
75
  /** Whether the state is in a bucket or a container: s3, gcs or azurerm. */
68
76
  export declare const isStored: (o: StateObject) => o is StoredState;
69
- /** The backend types whose state chant locks and writes itself, s3 only with `use_lockfile = true` (#4437). The one list (chant#4478). */
77
+ /** Whether the state is a GitLab-managed one, an http backend's (#4793). */
78
+ export declare const isGitLabState: (o: StateObject) => o is GitLabState;
79
+ /**
80
+ * The backend types whose state chant locks and writes itself (#4437), s3
81
+ * only with `use_lockfile = true` and http only at a GitLab project's state
82
+ * API (#4793). The one list (chant#4478).
83
+ */
70
84
  export declare const LOCKABLE_BACKENDS: readonly string[];
71
85
  /** What a refusal says chant locks, spelled from {@link LOCKABLE_BACKENDS}. */
72
86
  export declare const LOCKS: string;
87
+ /**
88
+ * A product's words for the messages a state's credentials refusal gives: what
89
+ * the bucket and role are called, the STS session name, and the keys that
90
+ * give the job an identity (#4793). Default chant's.
91
+ */
92
+ export interface StateStoreWords {
93
+ setting?: string;
94
+ roleSetting?: string;
95
+ sessionName?: string;
96
+ hints?: StoreHints;
97
+ }
73
98
  /** The root's data dir: `TF_DATA_DIR` (relative to the root, as the binary run with `-chdir` reads it), else `.terraform`. */
74
99
  export declare function dataDir(dir: string, env?: NodeJS.ProcessEnv): string;
75
100
  /** The backend `init` recorded for the root, or undefined when it has not been initialised with one. */
@@ -143,9 +168,10 @@ export declare function readBackend(dir: string, input?: ReadBackendInput): Back
143
168
  * Whether chant can lock the root's state, from one {@link BackendReading}:
144
169
  * undefined when it can, else the refusal and why. The one verdict the
145
170
  * composition's `backend` fallback (#4438) and the state refusals (#4437)
146
- * both give (chant#4478).
171
+ * both give (chant#4478). An http backend's address is the configuration's,
172
+ * else `env`'s TF_HTTP_ADDRESS, as the binary reads it.
147
173
  */
148
- export declare function lockRefusal(reading: BackendReading): StateRefusal | undefined;
174
+ export declare function lockRefusal(reading: BackendReading, env?: NodeJS.ProcessEnv): StateRefusal | undefined;
149
175
  /**
150
176
  * Where the root's state is, or why chant does not lock it, from
151
177
  * {@link readBackend}: what `init` recorded (`backend` stands in for it),
@@ -153,6 +179,17 @@ export declare function lockRefusal(reading: BackendReading): StateRefusal | und
153
179
  * nor records a backend for reads as a local one.
154
180
  */
155
181
  export declare function stateObject(dir: string, env?: NodeJS.ProcessEnv, backend?: InitialisedBackend | undefined, binary?: string, flags?: Pick<DeclaredBackendInput, "backendConfig" | "backendConfigFiles">): StateObject;
156
- /** `s3://<bucket>/<key>`, `gs://<bucket>/<key>`, `az://<account>/<container>/<key>`, or the local file's path; undefined for a refusal. */
182
+ /**
183
+ * Where the root's state is for a read of its versions (#4793), from what
184
+ * `init` recorded (`backend` stands in for it): a read holds no lock, so the
185
+ * lock verdict's refusals that are about holding one do not apply. An s3
186
+ * backend without `use_lockfile` is read all the same (`lockfile: false`),
187
+ * and a root's code is not compared with the record, since the record is
188
+ * where the binary wrote. A `cloud` backend and any type chant reads no
189
+ * versions of is refused (`backend`). No backend recorded reads as a local
190
+ * one. `words` names the product's settings in a credentials refusal.
191
+ */
192
+ export declare function readableStateObject(dir: string, env?: NodeJS.ProcessEnv, backend?: InitialisedBackend | undefined, words?: StateStoreWords): StateObject;
193
+ /** `s3://<bucket>/<key>`, `gs://<bucket>/<key>`, `az://<account>/<container>/<key>`, a GitLab state's address without its credentials, or the local file's path; undefined for a refusal. */
157
194
  export declare function stateLocation(o: StateObject): string | undefined;
158
195
  //# sourceMappingURL=backend.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"backend.d.ts","sourceRoot":"","sources":["../../src/state/backend.ts"],"names":[],"mappings":"AA2BA,OAAO,EAAmB,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAgB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,EAAa,KAAK,QAAQ,EAAE,MAAM,MAAM,CAAC;AAKhD,+DAA+D;AAC/D,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAED,+BAA+B;AAC/B,MAAM,WAAW,OAAO;IACtB,OAAO,EAAE,IAAI,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qFAAqF;IACrF,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,QAAQ,CAAC;CAClB;AAED,wGAAwG;AACxG,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,KAAK,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,SAAS,CAAC;CACnB;AAED,4GAA4G;AAC5G,MAAM,MAAM,SAAS,GAAG;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,CAAC;AAEvF,2EA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AAa,CAAC,CAAC,EAAE,WAAW,GAAG,MAAM,GAAG,SAAS,CAOhE"}
@@ -6,9 +6,15 @@
6
6
  * `-backend-config` file or the job's flags supplied it. Nothing here reads
7
7
  * a state's contents.
8
8
  *
9
- * chant locks and writes four backends: s3 with `use_lockfile`, gcs, azurerm
10
- * and local. Every other backend, and a root with a `cloud` block, comes back
11
- * as a {@link StateRefusal} naming why, and is never locked.
9
+ * chant locks and writes five backends: s3 with `use_lockfile`, gcs, azurerm,
10
+ * local, and an http backend whose address is a GitLab project's state API
11
+ * (./gitlab.ts, #4793). Every other backend, and a root with a `cloud` block,
12
+ * comes back as a {@link StateRefusal} naming why, and is never locked.
13
+ *
14
+ * A read of the state's versions holds no lock, so it is not held to the lock
15
+ * verdict: {@link readableStateObject} reads an s3 backend without
16
+ * `use_lockfile` all the same, and goes by what `init` recorded alone
17
+ * (./versions.ts, #4793).
12
18
  *
13
19
  * This is also the one place that answers which backend a root has and
14
20
  * whether chant can lock it (chant#4478). Before `init` the answer comes
@@ -27,18 +33,25 @@ import { existsSync, readFileSync } from "node:fs";
27
33
  import { isAbsolute, join } from "node:path";
28
34
  import { AZURE_AUTHORITY } from "./azure-blob.js";
29
35
  import { GCS_ENDPOINT } from "./gcs.js";
36
+ import { gitlabState, isGitLabAddress, shownUrl } from "./gitlab.js";
30
37
  import { s3FromEnv } from "./s3.js";
31
38
  import { isJsonConfigFile, listConfigFilesSafe } from "../hcl/files.js";
32
39
  import { blockBody, jsonBlocks, rootTexts } from "../compose/hcl.js";
33
40
  import { backendConfigFileKeys, literalAttributes } from "../backend-config.js";
34
41
  export const isRefused = (o) => "refused" in o;
35
42
  /** Whether the state is in a bucket or a container: s3, gcs or azurerm. */
36
- export const isStored = (o) => !isRefused(o) && o.backend !== "local";
37
- /** The backend types whose state chant locks and writes itself, s3 only with `use_lockfile = true` (#4437). The one list (chant#4478). */
38
- export const LOCKABLE_BACKENDS = ["s3", "gcs", "azurerm", "local"];
43
+ export const isStored = (o) => !isRefused(o) && o.backend !== "local" && o.backend !== "http";
44
+ /** Whether the state is a GitLab-managed one, an http backend's (#4793). */
45
+ export const isGitLabState = (o) => !isRefused(o) && o.backend === "http";
46
+ /**
47
+ * The backend types whose state chant locks and writes itself (#4437), s3
48
+ * only with `use_lockfile = true` and http only at a GitLab project's state
49
+ * API (#4793). The one list (chant#4478).
50
+ */
51
+ export const LOCKABLE_BACKENDS = ["s3", "gcs", "azurerm", "local", "http"];
39
52
  /** What a refusal says chant locks, spelled from {@link LOCKABLE_BACKENDS}. */
40
53
  export const LOCKS = (() => {
41
- const names = LOCKABLE_BACKENDS.map((b) => (b === "s3" ? "s3 (with use_lockfile = true)" : b));
54
+ const names = LOCKABLE_BACKENDS.map((b) => (b === "s3" ? "s3 (with use_lockfile = true)" : b === "http" ? "GitLab-managed http" : b));
42
55
  return `chant locks and writes ${names.slice(0, -1).join(", ")} and ${names.at(-1)} states`;
43
56
  })();
44
57
  const str = (v) => (typeof v === "string" && v !== "" ? v : undefined);
@@ -249,9 +262,10 @@ export function readBackend(dir, input = {}) {
249
262
  * Whether chant can lock the root's state, from one {@link BackendReading}:
250
263
  * undefined when it can, else the refusal and why. The one verdict the
251
264
  * composition's `backend` fallback (#4438) and the state refusals (#4437)
252
- * both give (chant#4478).
265
+ * both give (chant#4478). An http backend's address is the configuration's,
266
+ * else `env`'s TF_HTTP_ADDRESS, as the binary reads it.
253
267
  */
254
- export function lockRefusal(reading) {
268
+ export function lockRefusal(reading, env = {}) {
255
269
  const b = reading.backend;
256
270
  if (reading.disagreement)
257
271
  return { backend: b.type, refused: "disagree", reason: `${reading.disagreement}, so chant cannot tell which state to lock; run init again with the configuration the root means; ${LOCKS}` };
@@ -259,6 +273,9 @@ export function lockRefusal(reading) {
259
273
  return { backend: b.type, refused: "cloud", reason: `${CLOUD_REASON}; ${LOCKS}` };
260
274
  if (!LOCKABLE_BACKENDS.includes(b.type))
261
275
  return { backend: b.type, refused: "backend", reason: `the root's backend is ${b.type}; ${LOCKS}` };
276
+ if (b.type === "http" && !isGitLabAddress(str(b.config.address) ?? str(env.TF_HTTP_ADDRESS))) {
277
+ return { backend: "http", refused: "backend", reason: `the root's http backend ${httpAddressNamed(b, env)}; ${LOCKS}` };
278
+ }
262
279
  if (b.type === "s3" && b.config.use_lockfile !== true && b.config.use_lockfile !== "true") {
263
280
  return { backend: "s3", refused: "no-lockfile", reason: `the s3 backend takes no lock file (use_lockfile = true is unset), so chant cannot hold its lock; ${LOCKS}` };
264
281
  }
@@ -278,20 +295,49 @@ export function stateObject(dir, env = process.env, backend = initialisedBackend
278
295
  ...(flags.backendConfig ? { backendConfig: flags.backendConfig } : {}),
279
296
  ...(flags.backendConfigFiles ? { backendConfigFiles: flags.backendConfigFiles } : {}),
280
297
  });
281
- const refusal = lockRefusal(reading);
298
+ const refusal = lockRefusal(reading, env);
282
299
  if (refusal)
283
300
  return refusal;
284
- const chosen = reading.backend;
285
- const ws = workspaceOf(dir, env);
301
+ return backendObject(reading.backend, workspaceOf(dir, env), env);
302
+ }
303
+ /** How an http backend's address reads in a refusal: which address, or that it names none. */
304
+ function httpAddressNamed(b, env) {
305
+ const address = str(b.config.address) ?? str(env.TF_HTTP_ADDRESS);
306
+ return address ? `address ${shownUrl(address)} is not a GitLab project's state API (.../projects/<id>/terraform/state/<name>)` : "names no address";
307
+ }
308
+ /**
309
+ * Where the root's state is for a read of its versions (#4793), from what
310
+ * `init` recorded (`backend` stands in for it): a read holds no lock, so the
311
+ * lock verdict's refusals that are about holding one do not apply. An s3
312
+ * backend without `use_lockfile` is read all the same (`lockfile: false`),
313
+ * and a root's code is not compared with the record, since the record is
314
+ * where the binary wrote. A `cloud` backend and any type chant reads no
315
+ * versions of is refused (`backend`). No backend recorded reads as a local
316
+ * one. `words` names the product's settings in a credentials refusal.
317
+ */
318
+ export function readableStateObject(dir, env = process.env, backend = initialisedBackend(dir, env), words = {}) {
319
+ const b = backend ?? { type: "local", config: {} };
320
+ if (b.type === "http" && !gitlabState(b.config, env))
321
+ return { backend: "http", refused: "backend", reason: `the root's http backend ${httpAddressNamed(b, env)}; ${READS}` };
322
+ if (!LOCKABLE_BACKENDS.includes(b.type))
323
+ return { backend: b.type, refused: "backend", reason: `the root's backend is ${b.type}; ${READS}` };
324
+ return backendObject(b, workspaceOf(dir, env), env, words);
325
+ }
326
+ /** What a read refusal says chant reads. */
327
+ const READS = "chant reads the state of s3, gcs, azurerm, local and GitLab-managed http backends";
328
+ /** The state a backend of a type chant reads names, in workspace `ws`, or why it names none. */
329
+ function backendObject(chosen, ws, env, words = {}) {
286
330
  if (chosen.type === "local") {
287
331
  const c = chosen.config;
288
332
  const path = ws === "default" ? (str(c.path) ?? "terraform.tfstate") : join(str(c.workspace_dir) ?? "terraform.tfstate.d", ws, "terraform.tfstate");
289
333
  return { backend: "local", path };
290
334
  }
335
+ if (chosen.type === "http")
336
+ return gitlabState(chosen.config, env) ?? { backend: "http", refused: "backend", reason: `the root's http backend ${httpAddressNamed(chosen, env)}; ${LOCKS}` };
291
337
  if (chosen.type === "gcs")
292
- return gcsObject(chosen.config, ws, env);
338
+ return gcsObject(chosen.config, ws, env, words);
293
339
  if (chosen.type === "azurerm")
294
- return azureObject(chosen.config, ws, env);
340
+ return azureObject(chosen.config, ws, env, words);
295
341
  const c = chosen.config;
296
342
  const bucket = str(c.bucket);
297
343
  const key = str(c.key);
@@ -305,7 +351,7 @@ export function stateObject(dir, env = process.env, backend = initialisedBackend
305
351
  const jobEnv = { ...env, AWS_REGION: region, ...(access && secret ? { AWS_ACCESS_KEY_ID: access, AWS_SECRET_ACCESS_KEY: secret, AWS_SESSION_TOKEN: str(c.token) ?? "" } : {}) };
306
352
  let target;
307
353
  try {
308
- target = s3FromEnv({ bucket, ...(endpoint ? { endpoint } : {}) }, jobEnv);
354
+ target = s3FromEnv({ bucket, ...(endpoint ? { endpoint } : {}) }, jobEnv, words);
309
355
  }
310
356
  catch (e) {
311
357
  return { backend: "s3", refused: "credentials", reason: `the job has no credentials to read s3://${bucket}: ${e.message}` };
@@ -316,7 +362,7 @@ export function stateObject(dir, env = process.env, backend = initialisedBackend
316
362
  key: s3StateKey(key, ws, str(c.workspace_key_prefix)),
317
363
  region,
318
364
  ...(endpoint ? { endpoint: endpoint.replace(/\/+$/, "") } : {}),
319
- lockfile: true,
365
+ lockfile: c.use_lockfile === true || c.use_lockfile === "true",
320
366
  target,
321
367
  };
322
368
  }
@@ -329,7 +375,7 @@ const gcsEndpoint = (e) => e.replace(/\/+$/, "").replace(/\/storage\/v1$/, "");
329
375
  * JSON), GOOGLE_BACKEND_CREDENTIALS, GOOGLE_CREDENTIALS, and
330
376
  * GOOGLE_APPLICATION_CREDENTIALS.
331
377
  */
332
- function gcsObject(c, ws, env) {
378
+ function gcsObject(c, ws, env, words) {
333
379
  const bucket = str(c.bucket);
334
380
  if (!bucket)
335
381
  return { backend: "gcs", refused: "config", reason: "the gcs backend's bucket is not in the configuration init recorded" };
@@ -347,8 +393,10 @@ function gcsObject(c, ws, env) {
347
393
  target = creds.trim().startsWith("{") ? { ...where, credentialsJson: creds } : { ...where, credentialsFile: creds };
348
394
  else if (env.GOOGLE_APPLICATION_CREDENTIALS)
349
395
  target = { ...where, credentialsFile: env.GOOGLE_APPLICATION_CREDENTIALS };
350
- else
351
- return { backend: "gcs", refused: "credentials", reason: `the job has no credentials to read gs://${bucket}: set GOOGLE_APPLICATION_CREDENTIALS, GOOGLE_CREDENTIALS or GOOGLE_OAUTH_ACCESS_TOKEN` };
396
+ else {
397
+ const how = words.hints?.gcp ? `give the job ${words.hints.gcp} (it sets GOOGLE_APPLICATION_CREDENTIALS), or set GOOGLE_CREDENTIALS or GOOGLE_OAUTH_ACCESS_TOKEN` : "set GOOGLE_APPLICATION_CREDENTIALS, GOOGLE_CREDENTIALS or GOOGLE_OAUTH_ACCESS_TOKEN";
398
+ return { backend: "gcs", refused: "credentials", reason: `the job has no credentials to read gs://${bucket}: ${how}` };
399
+ }
352
400
  return { backend: "gcs", bucket, key: `${prefix}${ws}.tfstate`, lock: `${prefix}${ws}.tflock`, target };
353
401
  }
354
402
  /** Each Azure cloud's storage suffix and Entra ID, by the azurerm backend's `environment`. */
@@ -361,12 +409,12 @@ const CLOUD_ENDPOINTS = {
361
409
  * An azurerm backend's state: the blob `key` in `container_name` of
362
410
  * `storage_account_name`, `<key>env:<workspace>` in another workspace, with
363
411
  * the credentials the backend would use: `access_key` (ARM_ACCESS_KEY),
364
- * `sas_token` (ARM_SAS_TOKEN), else the job's OIDC identity. An
365
- * `environment` other than public, china or usgovernment is refused: its
366
- * storage suffix would need the metadata lookup terragucci makes and chant
367
- * does not.
412
+ * `sas_token` (ARM_SAS_TOKEN), else the job's OIDC identity. A backend that
413
+ * names `metadata_host` (ARM_METADATA_HOSTNAME) gets its endpoint from that
414
+ * cloud's metadata, which the store reads (#4793); an `environment` other
415
+ * than public, china or usgovernment without one is refused.
368
416
  */
369
- function azureObject(c, ws, env) {
417
+ function azureObject(c, ws, env, words) {
370
418
  const account = str(c.storage_account_name);
371
419
  const container = str(c.container_name);
372
420
  const base = str(c.key);
@@ -374,8 +422,9 @@ function azureObject(c, ws, env) {
374
422
  return { backend: "azurerm", refused: "config", reason: "the azurerm backend's storage_account_name, container_name or key is not in the configuration init recorded" };
375
423
  const key = ws === "default" ? base : `${base}env:${ws}`;
376
424
  const cloud = CLOUD_ENDPOINTS[str(c.environment) ?? env.ARM_ENVIRONMENT ?? "public"];
377
- if (!cloud)
378
- return { backend: "azurerm", refused: "config", reason: `the azurerm backend's environment ${str(c.environment) ?? env.ARM_ENVIRONMENT} is not public, china or usgovernment` };
425
+ const metadataHost = str(c.metadata_host) ?? env.ARM_METADATA_HOSTNAME ?? env.ARM_METADATA_HOST;
426
+ if (!cloud && !metadataHost)
427
+ return { backend: "azurerm", refused: "config", reason: `the azurerm backend's environment ${str(c.environment) ?? env.ARM_ENVIRONMENT} is not public, china or usgovernment, and it names no metadata_host` };
379
428
  const accessKey = str(c.access_key) ?? env.ARM_ACCESS_KEY;
380
429
  const sas = str(c.sas_token) ?? env.ARM_SAS_TOKEN;
381
430
  const tenantId = str(c.tenant_id) ?? env.ARM_TENANT_ID;
@@ -387,17 +436,21 @@ function azureObject(c, ws, env) {
387
436
  else if (sas)
388
437
  auth = { sas };
389
438
  else if (tenantId && clientId && tokenFile)
390
- auth = { oidc: { tenantId, clientId, tokenFile, authority: (env.AZURE_AUTHORITY_HOST || cloud.authority).replace(/\/+$/, "") } };
391
- else
392
- return { backend: "azurerm", refused: "credentials", reason: `the job has no credentials to read the container ${container} of ${account}: set ARM_ACCESS_KEY, ARM_SAS_TOKEN, or ARM_TENANT_ID, ARM_CLIENT_ID and ARM_OIDC_TOKEN_FILE_PATH` };
393
- return { backend: "azurerm", account, container, key, snapshot: c.snapshot === true || env.ARM_SNAPSHOT === "true", endpoint: `https://${account}.blob.${cloud.storage}`, auth };
439
+ auth = { oidc: { tenantId, clientId, tokenFile, authority: (env.AZURE_AUTHORITY_HOST || cloud?.authority || AZURE_AUTHORITY).replace(/\/+$/, "") } };
440
+ else {
441
+ const how = words.hints?.azure ? `give the job ${words.hints.azure} (it sets ARM_TENANT_ID, ARM_CLIENT_ID and ARM_OIDC_TOKEN_FILE_PATH), or set ARM_ACCESS_KEY` : "set ARM_ACCESS_KEY, ARM_SAS_TOKEN, or ARM_TENANT_ID, ARM_CLIENT_ID and ARM_OIDC_TOKEN_FILE_PATH";
442
+ return { backend: "azurerm", refused: "credentials", reason: `the job has no credentials to read the container ${container} of ${account}: ${how}` };
443
+ }
444
+ return { backend: "azurerm", account, container, key, snapshot: c.snapshot === true || env.ARM_SNAPSHOT === "true", ...(metadataHost ? { metadataHost } : { endpoint: `https://${account}.blob.${cloud.storage}` }), auth };
394
445
  }
395
- /** `s3://<bucket>/<key>`, `gs://<bucket>/<key>`, `az://<account>/<container>/<key>`, or the local file's path; undefined for a refusal. */
446
+ /** `s3://<bucket>/<key>`, `gs://<bucket>/<key>`, `az://<account>/<container>/<key>`, a GitLab state's address without its credentials, or the local file's path; undefined for a refusal. */
396
447
  export function stateLocation(o) {
397
448
  if (isRefused(o))
398
449
  return undefined;
399
450
  if (o.backend === "local")
400
451
  return o.path;
452
+ if (o.backend === "http")
453
+ return shownUrl(o.address);
401
454
  if (o.backend === "gcs")
402
455
  return `gs://${o.bucket}/${o.key}`;
403
456
  if (o.backend === "azurerm")
@@ -47,7 +47,7 @@ export interface GitLabStateStore extends StateStore {
47
47
  serial: number;
48
48
  lineage?: string;
49
49
  } | undefined>;
50
- /** Whether GitLab keeps the version with this serial: a HEAD, so no state is read. */
50
+ /** Whether GitLab keeps the version with this serial: a HEAD, so no state is read. An id that is not a serial is none. */
51
51
  hasVersion(serial: string | number): Promise<boolean>;
52
52
  /** One version of the state, or undefined when GitLab keeps no version with that serial. */
53
53
  readVersion(serial: string | number): Promise<string | undefined>;
@@ -1 +1 @@
1
- {"version":3,"file":"gitlab.d.ts","sourceRoot":"","sources":["../../src/state/gitlab.ts"],"names":[],"mappings":"AAgCA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAE5D,OAAO,KAAK,EAAc,UAAU,EAAE,MAAM,SAAS,CAAC;AAEtD;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC;AAErC,gEAAgE;AAChE,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,iDAAiD;IACjD,OAAO,EAAE,MAAM,CAAC;IAChB,sDAAsD;IACtD,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,gFAAgF;IAChF,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAOD,yEAAyE;AACzE,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAOpE;AAED,0EAA0E;AAC1E,wBAAgB,QA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WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAI1E;AAqBD,kKAAkK;AAClK,MAAM,WAAW,gBAAiB,SAAQ,UAAU;IAClD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB;;;;OAIG;IACH,MAAM,IAAI,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC,CAAC;IACpE,0HAA0H;IAC1H,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACtD,4FAA4F;IAC5F,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IAClE;;;;;;OAMG;IACH,SAAS,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IACzC;;;OAGG;IACH,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACxC;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,WAAW,EAAE,OAAO,GAAE,WAA0B,EAAE,GAAG,SAAU,GAAG,gBAAgB,CAoIhH"}
@@ -193,26 +193,39 @@ export function gitlabStore(s, fetchFn = defaultFetch, who = "chant") {
193
193
  if (!r.ok)
194
194
  throw answered("a write of", url, r.status, text);
195
195
  };
196
+ /** The serial and lineage of the state GitLab holds now, read from the state, or undefined when it holds none. */
197
+ const serialNow = async () => {
198
+ const text = await read(s.address);
199
+ if (text === undefined)
200
+ return undefined;
201
+ let doc;
202
+ try {
203
+ doc = JSON.parse(text);
204
+ }
205
+ catch {
206
+ throw new StoreError(`GitLab answered ${location} with no state`);
207
+ }
208
+ if (typeof doc.serial !== "number")
209
+ throw new StoreError(`the state at ${location} has no serial`);
210
+ return { serial: doc.serial, ...(typeof doc.lineage === "string" ? { lineage: doc.lineage } : {}) };
211
+ };
196
212
  return {
197
213
  backend: "http",
198
214
  location,
199
215
  lockLocation: shownUrl(s.lockAddress ?? s.address),
200
- serial: async () => {
201
- const text = await read(s.address);
202
- if (text === undefined)
203
- return undefined;
204
- let doc;
205
- try {
206
- doc = JSON.parse(text);
207
- }
208
- catch {
209
- throw new StoreError(`GitLab answered ${location} with no state`);
210
- }
211
- if (typeof doc.serial !== "number")
212
- throw new StoreError(`the state at ${location} has no serial`);
213
- return { serial: doc.serial, ...(typeof doc.lineage === "string" ? { lineage: doc.lineage } : {}) };
216
+ serial: serialNow,
217
+ // The version id of a GitLab-managed state is its serial (#4793).
218
+ version: async () => {
219
+ const now = await serialNow();
220
+ return now ? { exists: true, versionId: String(now.serial) } : { exists: false };
221
+ },
222
+ isAt: async (id) => {
223
+ const now = await serialNow();
224
+ return now !== undefined && String(now.serial) === id;
214
225
  },
215
226
  hasVersion: async (serial) => {
227
+ if (!/^\d+$/.test(String(serial)))
228
+ return false;
216
229
  const url = gitlabVersionUrl(s, serial);
217
230
  const r = await fetchFn(url, { method: "HEAD", headers: headers(s) });
218
231
  if (r.status === 404)
@@ -14,4 +14,5 @@ export { S3Client, s3FromEnv, type S3Target } from "./s3.js";
14
14
  export { GcsClient, type GcsTarget } from "./gcs.js";
15
15
  export { AzureBlobClient, type AzureTarget } from "./azure-blob.js";
16
16
  export * from "./versions.js";
17
+ export * from "./source.js";
17
18
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/state/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AACjE,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/state/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AACjE,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC"}
@@ -14,3 +14,4 @@ export { S3Client, s3FromEnv } from "./s3.js";
14
14
  export { GcsClient } from "./gcs.js";
15
15
  export { AzureBlobClient } from "./azure-blob.js";
16
16
  export * from "./versions.js";
17
+ export * from "./source.js";
@@ -5,17 +5,23 @@
5
5
  * no static keys, a role is assumed with the job's OIDC token through STS
6
6
  * AssumeRoleWithWebIdentity.
7
7
  */
8
- import { type S3Target } from "@intentius/chant/object-store";
8
+ import { type S3Target, type StoreHints } from "@intentius/chant/object-store";
9
9
  export { assumeRoleWithWebIdentity, S3Client, sign, type S3Credentials, type S3Location, type S3Target, type S3WebIdentity } from "@intentius/chant/object-store";
10
10
  /**
11
11
  * The target for `bucket` from the AWS environment variables. Credentials,
12
12
  * first match wins: static keys in `AWS_ACCESS_KEY_ID` and
13
13
  * `AWS_SECRET_ACCESS_KEY`; `AWS_ROLE_ARN` assumed with the token in
14
14
  * `AWS_WEB_IDENTITY_TOKEN_FILE`, in a session named `chant-state` unless
15
- * AWS_ROLE_SESSION_NAME names one.
15
+ * AWS_ROLE_SESSION_NAME names one. `words` puts a product's names in the
16
+ * session and the messages (#4793).
16
17
  */
17
18
  export declare function s3FromEnv(where: {
18
19
  bucket: string;
19
20
  endpoint?: string;
20
- }, env?: NodeJS.ProcessEnv): S3Target;
21
+ }, env?: NodeJS.ProcessEnv, words?: {
22
+ setting?: string;
23
+ roleSetting?: string;
24
+ sessionName?: string;
25
+ hints?: StoreHints;
26
+ }): S3Target;
21
27
  //# sourceMappingURL=s3.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"s3.d.ts","sourceRoot":"","sources":["../../src/state/s3.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAA8B,KAAK,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAE1F,OAAO,EAAE,yBAAyB,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,aAAa,EAAE,KAAK,UAAU,EAAE,KAAK,QAAQ,EAAE,KAAK,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAElK;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,EAAE,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,QAAQ,CAEtH"}
1
+ {"version":3,"file":"s3.d.ts","sourceRoot":"","sources":["../../src/state/s3.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAA8B,KAAK,QAAQ,EAAE,KAAK,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAE3G,OAAO,EAAE,yBAAyB,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,aAAa,EAAE,KAAK,UAAU,EAAE,KAAK,QAAQ,EAAE,KAAK,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAElK;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,EAAE,GAAG,GAAE,MAAM,CAAC,UAAwB,EAAE,KAAK,GAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,UAAU,CAAA;CAAO,GAAG,QAAQ,CAExN"}
package/dist/state/s3.js CHANGED
@@ -12,8 +12,9 @@ export { assumeRoleWithWebIdentity, S3Client, sign } from "@intentius/chant/obje
12
12
  * first match wins: static keys in `AWS_ACCESS_KEY_ID` and
13
13
  * `AWS_SECRET_ACCESS_KEY`; `AWS_ROLE_ARN` assumed with the token in
14
14
  * `AWS_WEB_IDENTITY_TOKEN_FILE`, in a session named `chant-state` unless
15
- * AWS_ROLE_SESSION_NAME names one.
15
+ * AWS_ROLE_SESSION_NAME names one. `words` puts a product's names in the
16
+ * session and the messages (#4793).
16
17
  */
17
- export function s3FromEnv(where, env = process.env) {
18
- return coreS3FromEnv({ ...where, sessionName: "chant-state", setting: "the state bucket" }, env);
18
+ export function s3FromEnv(where, env = process.env, words = {}) {
19
+ return coreS3FromEnv({ sessionName: "chant-state", setting: "the state bucket", ...words, ...where }, env);
19
20
  }