@intentius/chant-lexicon-terraform 0.124.102 → 0.124.104

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/index.d.ts CHANGED
@@ -27,3 +27,6 @@ export type { TerraformPinRolloutOpConfig, TerraformPinRolloutOpResources } from
27
27
  export { TERRAFORM_STATE_OWNERSHIP_KEYS } from "./state-ownership.js";
28
28
  export { predictTerraformBehaviour, terraformBehaviourRequest, terraformPredictOptionsFrom, TERRAFORM_REFERENCE_CATALOG, type TerraformBehaviourDeps, type TerraformBehaviourEntity, type TerraformBehaviourRequest, type TerraformBehaviourRequestOptions, type TerraformLiveRead, type TerraformPredictOptions, } from "./behaviour/index.js";
29
29
  export { terraformExitOf, terraformPlanMoved, type TerraformExitSource } from "./exit-codes.js";
30
+ export { classifyTerraformDisruption, terraformActionsDisruption, terraformDisruptionQueries, terraformQueryVerdict, } from "./disruption.js";
31
+ export { TERRAFORM_HEALTH_TYPES, terraformHealthTargets } from "./health-targets.js";
32
+ export { TERRAFORM_HEALTH_DISRUPTION_FLOOR, TERRAFORM_OWNERSHIP_ROWS_FLOOR, TERRAFORM_UNDECLARED_NODES_FLOOR, TERRAFORM_STATE_LOCATIONS_FLOOR } from "./chant-floors.js";
package/dist/index.js CHANGED
@@ -68,3 +68,7 @@ export { TERRAFORM_STATE_OWNERSHIP_KEYS } from "./state-ownership.js";
68
68
  export { predictTerraformBehaviour, terraformBehaviourRequest, terraformPredictOptionsFrom, TERRAFORM_REFERENCE_CATALOG, } from "./behaviour/index.js";
69
69
  // terraform, tofu and choudoufu exit statuses on chant's exit-code table (#4553).
70
70
  export { terraformExitOf, terraformPlanMoved } from "./exit-codes.js";
71
+ // Disruption from a plan's actions and health through the provider lexicons (#5338).
72
+ export { classifyTerraformDisruption, terraformActionsDisruption, terraformDisruptionQueries, terraformQueryVerdict, } from "./disruption.js";
73
+ export { TERRAFORM_HEALTH_TYPES, terraformHealthTargets } from "./health-targets.js";
74
+ export { TERRAFORM_HEALTH_DISRUPTION_FLOOR, TERRAFORM_OWNERSHIP_ROWS_FLOOR, TERRAFORM_UNDECLARED_NODES_FLOOR, TERRAFORM_STATE_LOCATIONS_FLOOR } from "./chant-floors.js";
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "algorithm": "sha256",
3
3
  "artifacts": {
4
- "manifest.json": "39a2b1c6acb49f2d3a932682b84629bfe416cd4ea1cbf102518cc089620a18b9",
4
+ "manifest.json": "3ba459e2176a939da05be0d81f21e82770981aeabfd328fa5b29dddc61314b87",
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": "7813cebfde4a31995e566cfd4c2d3cfc5c6838ac56a1889fc13c47b88d8c7096"
62
+ "composite": "6c90406fac17be37b6285ec1196a77d2e1583d5229f818a5d30b735c81c06eac"
63
63
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "terraform",
3
- "version": "0.124.102",
3
+ "version": "0.124.104",
4
4
  "chantVersion": ">=0.1.0",
5
5
  "namespace": "Terraform"
6
6
  }
@@ -301,6 +301,12 @@ export interface ChoudoufuLiveLsArgs extends TerraformRootArgs {
301
301
  estate?: string;
302
302
  /** `-consistent`: poll past the Resource Groups Tagging API's eventual-consistency window. */
303
303
  consistent?: boolean;
304
+ /**
305
+ * Pass the root as `DIR` (`.`), so the listing compares the declared
306
+ * instances and prints `gaps[]` (#5402). Without it, `gaps[]` is empty and
307
+ * `gaps_skipped` says no configuration was given.
308
+ */
309
+ compare?: boolean;
304
310
  }
305
311
  export type ChoudoufuLiveCheckArgs = TerraformRootArgs;
306
312
  export interface ChoudoufuAdoptArgs extends TerraformRootArgs {
@@ -663,6 +669,7 @@ export declare function choudoufuLiveLsCommand(opts: {
663
669
  binary: string;
664
670
  estate: string;
665
671
  consistent?: boolean;
672
+ compare?: boolean;
666
673
  }): string;
667
674
  /**
668
675
  * `live-check -json`. No `DIR` argument: the activity already runs in the
@@ -792,6 +799,16 @@ export declare function terraformApply(args: TerraformApplyArgs, signal?: AbortS
792
799
  * asked for the values to hand them on.
793
800
  */
794
801
  export declare function terraformOutputs(args: TerraformRootArgs, signal?: AbortSignal): Promise<Record<string, unknown>>;
802
+ /** `<binary> output -json` in a root, as `{ name: value }`, with the names it marks `sensitive` (#5345). */
803
+ export declare function terraformMarkedOutputs(args: TerraformRootArgs, signal?: AbortSignal): Promise<{
804
+ outputs: Record<string, unknown>;
805
+ sensitive: string[];
806
+ }>;
807
+ /** `output -json`'s document as values and the names it marks `sensitive`. */
808
+ export declare function markedOutputsOf(stdout: string): {
809
+ outputs: Record<string, unknown>;
810
+ sensitive: string[];
811
+ };
795
812
  /**
796
813
  * `live-plan-set -json` over one root, from the project root, so the
797
814
  * document names the root by its path from there, which is what
@@ -320,6 +320,8 @@ export function choudoufuLiveLsCommand(opts) {
320
320
  const parts = [opts.binary, "live-ls", `-estate=${quoteArg(opts.estate)}`, "-json"];
321
321
  if (opts.consistent)
322
322
  parts.push("-consistent");
323
+ if (opts.compare)
324
+ parts.push(".");
323
325
  return parts.join(" ");
324
326
  }
325
327
  /**
@@ -824,6 +826,20 @@ export async function terraformApply(args, signal) {
824
826
  export async function terraformOutputs(args, signal) {
825
827
  return outputsIn(await resolveRoot(args, signal), signal);
826
828
  }
829
+ /** `<binary> output -json` in a root, as `{ name: value }`, with the names it marks `sensitive` (#5345). */
830
+ export async function terraformMarkedOutputs(args, signal) {
831
+ const { binary, root, dir } = await resolveRoot(args, signal);
832
+ const { stdout } = await run(`${binary} output -json`, dir, terraformEnvironment(root), signal);
833
+ return markedOutputsOf(stdout);
834
+ }
835
+ /** `output -json`'s document as values and the names it marks `sensitive`. */
836
+ export function markedOutputsOf(stdout) {
837
+ const parsed = JSON.parse(stdout || "{}");
838
+ return {
839
+ outputs: Object.fromEntries(Object.entries(parsed).map(([name, entry]) => [name, entry?.value])),
840
+ sensitive: Object.entries(parsed).filter(([, entry]) => entry?.sensitive === true).map(([name]) => name).sort(),
841
+ };
842
+ }
827
843
  /** `<binary> output -json` in a resolved root, as `{ name: value }`. */
828
844
  async function outputsIn({ binary, root, dir }, signal) {
829
845
  const { stdout } = await run(`${binary} output -json`, dir, terraformEnvironment(root), signal);
@@ -1544,10 +1560,11 @@ export async function choudoufuLiveLs(args, signal) {
1544
1560
  const estate = resolveEstate(args, resolved, "choudoufuLiveLs");
1545
1561
  const env = terraformEnvironment(resolved.root);
1546
1562
  const consistent = args.consistent === true;
1547
- const cmd = choudoufuLiveLsCommand({ binary, estate, ...(consistent ? { consistent: true } : {}) });
1563
+ const compare = args.compare === true;
1564
+ const cmd = choudoufuLiveLsCommand({ binary, estate, ...(consistent ? { consistent: true } : {}), ...(compare ? { compare: true } : {}) });
1548
1565
  // Shared with every identical listing in the same read session, the way
1549
1566
  // {@link choudoufuLivePlanDocument} shares the document (chant #2498).
1550
- const key = liveReadKey("live-ls", { root: args.root, dir, binary, estate, consistent, env });
1567
+ const key = liveReadKey("live-ls", { root: args.root, dir, binary, estate, consistent, compare, env });
1551
1568
  const stdout = await memoLiveRead(key, async () => {
1552
1569
  const result = await run(cmd, dir, env, signal);
1553
1570
  report(result.stdout, result.stderr);
package/dist/plugin.d.ts CHANGED
@@ -1,10 +1,2 @@
1
1
  import type { LexiconPlugin } from "@intentius/chant/lexicon";
2
- /**
3
- * terraform lexicon plugin.
4
- *
5
- * There is no upstream schema to pin here: Terraform's resource surface lives
6
- * in provider registries, one schema per provider, and this lexicon reads the
7
- * HCL an estate already has rather than generating types for it. So `spec/`
8
- * and `codegen/` stay near-empty and there is no `upstreamPin`.
9
- */
10
2
  export declare const terraformPlugin: LexiconPlugin;
package/dist/plugin.js CHANGED
@@ -66,6 +66,8 @@ function looksLikeHcl(text) {
66
66
  * HCL an estate already has rather than generating types for it. So `spec/`
67
67
  * and `codegen/` stay near-empty and there is no `upstreamPin`.
68
68
  */
69
+ /** The state locations of the roots `buildRoots` read in this process, for `graphMeta` (#5456). */
70
+ let lastStateLocations;
69
71
  export const terraformPlugin = {
70
72
  behaviourKinds: terraformBehaviourKinds,
71
73
  name: "terraform",
@@ -134,6 +136,26 @@ export const terraformPlugin = {
134
136
  * drift` reaches it through `chant lifecycle drift` in a member's reader
135
137
  * project. See `./drift-read.ts`.
136
138
  */
139
+ /**
140
+ * What applying a planned update costs, from the plan's own actions
141
+ * (#5338): in place, a replacement created first, or a delete first. It
142
+ * answers for a root read at the plan depth, whose blocks carry
143
+ * `planActions`; any other read leaves the update `unknown`. See
144
+ * `./disruption.ts`.
145
+ */
146
+ async classifyDisruption(options) {
147
+ const { classifyTerraformDisruption } = await import("./disruption.js");
148
+ return classifyTerraformDisruption(options);
149
+ },
150
+ /**
151
+ * Health for a root's resources through the provider lexicons (#5338):
152
+ * each covered type mapped to its provider's health type, with the id from
153
+ * the root's state. See `./health-targets.ts`.
154
+ */
155
+ async healthTargets(options) {
156
+ const { terraformHealthTargets } = await import("./health-targets.js");
157
+ return terraformHealthTargets(options);
158
+ },
137
159
  async readDrift(options) {
138
160
  const { readTerraformDrift } = await import("./drift-read.js");
139
161
  return readTerraformDrift(options);
@@ -177,8 +199,12 @@ export const terraformPlugin = {
177
199
  const namespace = ctx.config.terraform;
178
200
  // A `signalOnly` root (#4484) feeds change detection only, so it builds no entities here.
179
201
  const roots = ownRoots(namespace?.roots);
202
+ lastStateLocations = undefined;
180
203
  if (Object.keys(roots).length === 0)
181
204
  return { entities: new Map(), warnings: [] };
205
+ // Where each root's state lives (#5456), published by graphMeta below.
206
+ const { terraformStateLocations } = await import("./state-locations.js");
207
+ lastStateLocations = terraformStateLocations(ctx.projectRoot, roots, { binary: namespace?.binary });
182
208
  return renderTerraformRoots({
183
209
  projectRoot: ctx.projectRoot,
184
210
  roots,
@@ -187,6 +213,10 @@ export const terraformPlugin = {
187
213
  moduleRoot: namespace?.moduleRoot,
188
214
  });
189
215
  },
216
+ /** Where each root's state lives, for `chant workspace state` (#5456). */
217
+ graphMeta() {
218
+ return lastStateLocations ? { stateLocations: lastStateLocations } : undefined;
219
+ },
190
220
  /** `chant terraform pin-rollout` (#3189). */
191
221
  commands() {
192
222
  return terraformCommands;
@@ -0,0 +1,40 @@
1
+ type Scalar = string | number | boolean | null;
2
+ export interface TerraformStateLocation {
3
+ environment: string | null;
4
+ unit: string;
5
+ substrate: "terraform";
6
+ backend: {
7
+ kind: string;
8
+ location: Record<string, Scalar>;
9
+ };
10
+ lock: {
11
+ mechanism: string;
12
+ location?: Record<string, Scalar>;
13
+ } | null;
14
+ reach: {
15
+ status: "unchecked";
16
+ reason: string;
17
+ };
18
+ }
19
+ /** The root fields a location is read from. */
20
+ export interface StateRoot {
21
+ dir: string;
22
+ workspace?: string;
23
+ estate?: string;
24
+ backendConfig?: Readonly<Record<string, string>>;
25
+ backendConfigFiles?: readonly string[];
26
+ }
27
+ /** One backend as a location and a lock. A backend chant has no reading for keeps its type and the keys it names. */
28
+ export declare function backendLocation(type: string, config: Record<string, unknown>, workspace: string | undefined): {
29
+ backend: TerraformStateLocation["backend"];
30
+ lock: TerraformStateLocation["lock"];
31
+ };
32
+ /**
33
+ * The state locations of the given roots, in name order: one for each root's
34
+ * backend, and one for the record store of each root with a live block.
35
+ */
36
+ export declare function terraformStateLocations(projectRoot: string, roots: Readonly<Record<string, StateRoot>>, options?: {
37
+ binary?: string;
38
+ env?: NodeJS.ProcessEnv;
39
+ }): TerraformStateLocation[];
40
+ export {};
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Where each Terraform root's state lives (#5456), as the entries `chant
3
+ * workspace state` reads from the member graph's `meta.stateLocations`.
4
+ *
5
+ * A root's backend is what its code declares with the `-backend-config`
6
+ * files, pairs and `TF_CLI_ARGS` flags applied over it ({@link declaredBackend}),
7
+ * the same reading the state and lock paths use. A root's environment is its
8
+ * `estate`, else its `workspace`, and an s3 key as the backend names it for a
9
+ * non-default workspace (`env:/<workspace>/<key>`). A root with a choudoufu
10
+ * live block also has its record store. Text reads only: nothing is run, no
11
+ * bucket is called, so `reach` is `unchecked`.
12
+ */
13
+ import { resolve } from "node:path";
14
+ import { declaredBackend } from "./state/backend.js";
15
+ import { writtenRecordStore } from "./live-roots.js";
16
+ const UNCHECKED = { status: "unchecked", reason: "the location is read from configuration; no call is made to it" };
17
+ const text = (v) => (typeof v === "string" && v !== "" ? v : null);
18
+ /** An s3 backend's key for a workspace: the backend's own rule, `<prefix>/<workspace>/<key>` with `env:` as the default prefix. */
19
+ function s3Key(config, workspace) {
20
+ const key = text(config.key);
21
+ if (!key || !workspace || workspace === "default")
22
+ return key;
23
+ return `${text(config.workspace_key_prefix) ?? "env:"}/${workspace}/${key}`;
24
+ }
25
+ function located(config, keys) {
26
+ return Object.fromEntries(keys.map((k) => [k, typeof config[k] === "number" || typeof config[k] === "boolean" ? config[k] : text(config[k])]));
27
+ }
28
+ /** One backend as a location and a lock. A backend chant has no reading for keeps its type and the keys it names. */
29
+ export function backendLocation(type, config, workspace) {
30
+ switch (type) {
31
+ case "s3": {
32
+ const key = s3Key(config, workspace);
33
+ const lockfile = config.use_lockfile === true;
34
+ const table = text(config.dynamodb_table);
35
+ return {
36
+ backend: { kind: "s3", location: { bucket: text(config.bucket), key, region: text(config.region) } },
37
+ lock: lockfile
38
+ ? { mechanism: "s3-lockfile", location: { key: key ? `${key}.tflock` : null } }
39
+ : table
40
+ ? { mechanism: "dynamodb", location: { table } }
41
+ : null,
42
+ };
43
+ }
44
+ case "gcs":
45
+ return {
46
+ backend: { kind: "gcs", location: { bucket: text(config.bucket), prefix: text(config.prefix) } },
47
+ lock: { mechanism: "gcs-object" },
48
+ };
49
+ case "azurerm":
50
+ return {
51
+ backend: { kind: "azurerm", location: located(config, ["storage_account_name", "container_name", "key", "resource_group_name"]) },
52
+ lock: { mechanism: "blob-lease" },
53
+ };
54
+ case "http":
55
+ return {
56
+ backend: { kind: "http", location: located(config, ["address"]) },
57
+ lock: text(config.lock_address) ? { mechanism: "http-lock", location: located(config, ["lock_address"]) } : null,
58
+ };
59
+ case "local":
60
+ return { backend: { kind: "local", location: { path: text(config.path) ?? "terraform.tfstate" } }, lock: { mechanism: "local-file" } };
61
+ case "cloud":
62
+ return { backend: { kind: "cloud", location: located(config, ["organization", "hostname"]) }, lock: { mechanism: "terraform-cloud" } };
63
+ default:
64
+ return { backend: { kind: type, location: located(config, Object.keys(config).sort()) }, lock: null };
65
+ }
66
+ }
67
+ /**
68
+ * The state locations of the given roots, in name order: one for each root's
69
+ * backend, and one for the record store of each root with a live block.
70
+ */
71
+ export function terraformStateLocations(projectRoot, roots, options = {}) {
72
+ const out = [];
73
+ for (const name of Object.keys(roots).sort()) {
74
+ const root = roots[name];
75
+ const dir = resolve(projectRoot, root.dir);
76
+ // A live root's estate is its environment (config.ts); a stock root's is its workspace.
77
+ const environment = root.estate ?? root.workspace ?? null;
78
+ const declared = declaredBackend(dir, {
79
+ binary: options.binary,
80
+ env: options.env ?? process.env,
81
+ ...(root.backendConfig ? { backendConfig: root.backendConfig } : {}),
82
+ ...(root.backendConfigFiles ? { backendConfigFiles: root.backendConfigFiles } : {}),
83
+ });
84
+ // No backend block is the local backend, which init records as no backend at all.
85
+ const { backend, lock } = backendLocation(declared?.type ?? "local", declared?.config ?? {}, root.workspace);
86
+ out.push({ environment, unit: name, substrate: "terraform", backend, lock, reach: UNCHECKED });
87
+ const store = writtenRecordStore(dir, root.estate ?? name, options.binary);
88
+ if (store) {
89
+ out.push({
90
+ environment,
91
+ unit: `${name} (records)`,
92
+ substrate: "terraform",
93
+ backend: store.kind === "s3"
94
+ ? { kind: "choudoufu-record-store:s3", location: { bucket: store.bucket, prefix: store.prefix, region: store.region ?? null } }
95
+ : store.kind === "local"
96
+ ? { kind: "choudoufu-record-store:local", location: { dir: store.dir, prefix: store.prefix } }
97
+ : { kind: `choudoufu-record-store:${store.name}`, location: {} },
98
+ lock: null,
99
+ reach: UNCHECKED,
100
+ });
101
+ }
102
+ }
103
+ return out;
104
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intentius/chant-lexicon-terraform",
3
- "version": "0.124.102",
3
+ "version": "0.124.104",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist/",
@@ -77,7 +77,7 @@
77
77
  "validate": "npx tsx src/validate-cli.ts",
78
78
  "docs": "npx tsx src/codegen/docs-cli.ts",
79
79
  "build": "../../scripts/tsc7.sh -p tsconfig.build.json --sourceMap false && tsc-alias -p tsconfig.build.json && node ../../scripts/copy-lexicon-assets.mjs",
80
- "prepack": "npm run generate && npm run bundle && npm run validate && npm run build",
80
+ "prepack": "npm run generate && npm run bundle && npm run validate && tsx ../../scripts/release-floors.ts --lexicon terraform --pack npm run build",
81
81
  "bundle": "tsx src/package-cli.ts",
82
82
  "module-catalog:refresh": "npx tsx src/module-catalog/refresh-cli.ts"
83
83
  },
@@ -92,7 +92,7 @@
92
92
  "access": "public"
93
93
  },
94
94
  "peerDependencies": {
95
- "@intentius/chant": "^0.124.102",
95
+ "@intentius/chant": "^0.124.114",
96
96
  "zod": "^4.3.6"
97
97
  },
98
98
  "description": "terraform lexicon for chant, existing Terraform root modules as declarable entities",