@intentius/chant-lexicon-terraform 0.124.96 → 0.124.98

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 (104) hide show
  1. package/dist/behaviour/reference-catalog.d.ts +42 -6
  2. package/dist/behaviour/reference-catalog.d.ts.map +1 -1
  3. package/dist/behaviour/reference-catalog.js +169 -8
  4. package/dist/describe-resources.js +1 -1
  5. package/dist/hcl/evaluate.d.ts +151 -0
  6. package/dist/hcl/evaluate.d.ts.map +1 -0
  7. package/dist/hcl/evaluate.js +940 -0
  8. package/dist/hcl/instances.d.ts +11 -1
  9. package/dist/hcl/instances.d.ts.map +1 -1
  10. package/dist/hcl/instances.js +89 -3
  11. package/dist/hcl/parse.d.ts +23 -1
  12. package/dist/hcl/parse.d.ts.map +1 -1
  13. package/dist/hcl/parse.js +9 -3
  14. package/dist/hcl/redact.d.ts +5 -1
  15. package/dist/hcl/redact.d.ts.map +1 -1
  16. package/dist/hcl/redact.js +7 -3
  17. package/dist/hcl/references.d.ts +12 -1
  18. package/dist/hcl/references.d.ts.map +1 -1
  19. package/dist/hcl/references.js +33 -16
  20. package/dist/integrity.json +6 -6
  21. package/dist/lint/post-synth/tf001.d.ts +4 -1
  22. package/dist/lint/post-synth/tf001.d.ts.map +1 -1
  23. package/dist/lint/post-synth/tf001.js +20 -8
  24. package/dist/lint/post-synth/tf002.d.ts +11 -5
  25. package/dist/lint/post-synth/tf002.d.ts.map +1 -1
  26. package/dist/lint/post-synth/tf002.js +42 -8
  27. package/dist/lint/post-synth/tf006.d.ts +7 -3
  28. package/dist/lint/post-synth/tf006.d.ts.map +1 -1
  29. package/dist/lint/post-synth/tf006.js +9 -3
  30. package/dist/lint/post-synth/tf022.d.ts +6 -0
  31. package/dist/lint/post-synth/tf022.d.ts.map +1 -1
  32. package/dist/lint/post-synth/tf022.js +18 -1
  33. package/dist/lint/secret-shape.d.ts +8 -0
  34. package/dist/lint/secret-shape.d.ts.map +1 -1
  35. package/dist/lint/secret-shape.js +76 -0
  36. package/dist/manifest.json +1 -1
  37. package/dist/plugin.d.ts.map +1 -1
  38. package/dist/plugin.js +7 -2
  39. package/dist/rules/tf001.ts +21 -7
  40. package/dist/rules/tf002.ts +44 -7
  41. package/dist/rules/tf006.ts +8 -3
  42. package/dist/rules/tf022.ts +18 -1
  43. package/package.json +2 -2
  44. package/src/__fixtures__/resolved-arguments/build-trusted/extras.tf +28 -0
  45. package/src/__fixtures__/resolved-arguments/build-trusted/main.tf +22 -0
  46. package/src/__fixtures__/resolved-arguments/build-trusted/serviceaccounts.tf +26 -0
  47. package/src/__fixtures__/resolved-arguments/modules/gke-cluster/main.tf +15 -0
  48. package/src/__fixtures__/resolved-arguments/modules/gke-cluster/variables.tf +12 -0
  49. package/src/__fixtures__/resolved-arguments/modules/gke-project/main.tf +9 -0
  50. package/src/__fixtures__/resolved-arguments/modules/gke-project/outputs.tf +9 -0
  51. package/src/__fixtures__/resolved-arguments/modules/gke-project/variables.tf +7 -0
  52. package/src/__fixtures__/resolved-arguments/modules/workload-identity-service-account/main.tf +16 -0
  53. package/src/__fixtures__/resolved-arguments/modules/workload-identity-service-account/outputs.tf +4 -0
  54. package/src/__fixtures__/resolved-arguments/modules/workload-identity-service-account/variables.tf +21 -0
  55. package/src/behaviour/reference-catalog.plugin.test.ts +101 -2
  56. package/src/behaviour/reference-catalog.ts +162 -9
  57. package/src/describe-resources.ts +1 -1
  58. package/src/hcl/edges.test.ts +1 -1
  59. package/src/hcl/evaluate.test.ts +215 -0
  60. package/src/hcl/evaluate.ts +899 -0
  61. package/src/hcl/instances.ts +89 -3
  62. package/src/hcl/parse.test.ts +18 -0
  63. package/src/hcl/parse.ts +28 -3
  64. package/src/hcl/redact.ts +7 -3
  65. package/src/hcl/references.test.ts +68 -0
  66. package/src/hcl/references.ts +31 -15
  67. package/src/lint/post-synth/fixtures/TF001/negative-second-block.tf +17 -0
  68. package/src/lint/post-synth/fixtures/TF002/module-cycle/cdn/back/main.tf +3 -0
  69. package/src/lint/post-synth/fixtures/TF002/module-cycle/cdn/main.tf +3 -0
  70. package/src/lint/post-synth/fixtures/TF002/module-cycle/main.tf +14 -0
  71. package/src/lint/post-synth/fixtures/TF002/module-nested/cdn/edge/main.tf +8 -0
  72. package/src/lint/post-synth/fixtures/TF002/module-nested/cdn/main.tf +3 -0
  73. package/src/lint/post-synth/fixtures/TF002/module-nested/main.tf +14 -0
  74. package/src/lint/post-synth/fixtures/TF002/module-other-provider/cdn/main.tf +8 -0
  75. package/src/lint/post-synth/fixtures/TF002/module-other-provider/main.tf +14 -0
  76. package/src/lint/post-synth/fixtures/TF002/module-pinned/cdn/main.tf +12 -0
  77. package/src/lint/post-synth/fixtures/TF002/module-pinned/main.tf +14 -0
  78. package/src/lint/post-synth/fixtures/TF002/module-unpinned/cdn/main.tf +7 -0
  79. package/src/lint/post-synth/fixtures/TF002/module-unpinned/main.tf +14 -0
  80. package/src/lint/post-synth/fixtures/TF006/negative-null-default.tf +12 -0
  81. package/src/lint/post-synth/fixtures/TF006/positive-empty-default.tf +0 -6
  82. package/src/lint/post-synth/fixtures/TF007/negative-names.tf +25 -0
  83. package/src/lint/post-synth/fixtures/TF022/negative-secret-reference.tf +32 -0
  84. package/src/lint/post-synth/fixtures/TF022/positive-secret-data.tf +8 -0
  85. package/src/lint/post-synth/fixtures/TF024/live-backend-second-block/a-versions.tf +3 -0
  86. package/src/lint/post-synth/fixtures/TF024/live-backend-second-block/b-backend.tf +10 -0
  87. package/src/lint/post-synth/fixtures/TF024/live-cloud-second-block/a-versions.tf +3 -0
  88. package/src/lint/post-synth/fixtures/TF024/live-cloud-second-block/b-cloud.tf +9 -0
  89. package/src/lint/post-synth/fixtures/TF024/sidecar-backend-second-block/a-versions.tf +3 -0
  90. package/src/lint/post-synth/fixtures/TF024/sidecar-backend-second-block/b-backend.tf +6 -0
  91. package/src/lint/post-synth/fixtures/TF024/sidecar-backend-second-block/estate.chdf.hcl +1 -0
  92. package/src/lint/post-synth/module-rules.test.ts +1 -1
  93. package/src/lint/post-synth/post-synth.test.ts +39 -0
  94. package/src/lint/post-synth/single-block.test.ts +23 -2
  95. package/src/lint/post-synth/tf001.ts +21 -7
  96. package/src/lint/post-synth/tf002.test.ts +45 -1
  97. package/src/lint/post-synth/tf002.ts +44 -7
  98. package/src/lint/post-synth/tf006.ts +8 -3
  99. package/src/lint/post-synth/tf022.ts +18 -1
  100. package/src/lint/post-synth/tf024.test.ts +21 -0
  101. package/src/lint/secret-shape.test.ts +30 -0
  102. package/src/lint/secret-shape.ts +75 -0
  103. package/src/plugin.ts +6 -2
  104. package/src/redact.test.ts +8 -0
@@ -34,6 +34,16 @@
34
34
  * rolled up by ruling. A block under an expanded call whose own expansion
35
35
  * or whose call's expansion cannot be counted gets no instances at all,
36
36
  * since a partial list would name ids the plan never prints.
37
+ *
38
+ * Since #5117 an expansion none of those forms counts is read once more with
39
+ * `./evaluate.ts`, which follows locals that read locals, interpolation,
40
+ * `lookup()` and module outputs: a `for_each` over a local map whose values
41
+ * interpolate another local gets its keys, since a map's keys are known when
42
+ * some of its values are not. The same evaluator then gives each resource
43
+ * block its `evaluated` arguments, per instance when it has instance nodes,
44
+ * for the reference catalog. Since #5094 that reading includes `==` and
45
+ * `!=`, and a block whose expansion comes to zero instances gets
46
+ * `{ instances: {} }`, so the catalog reads nothing on it.
37
47
  */
38
48
  import { type Declarable } from "@intentius/chant/declarable";
39
49
  import type { InstanceRollup } from "@intentius/chant/instance-nodes";
@@ -62,7 +72,7 @@ export interface ResolveInstancesOptions {
62
72
  * A block's expansion in a scope: its instance keys as Terraform prints them,
63
73
  * `null` when the block is not expanded, or why the keys are not known.
64
74
  */
65
- export declare function expansionIn(body: BlockBody, scope: Scope): {
75
+ export declare function expansionIn(body: BlockBody, scope: Scope, evaluateFully?: (raw: unknown) => unknown): {
66
76
  keys: string[];
67
77
  } | {
68
78
  rollup: InstanceRollup;
@@ -1 +1 @@
1
- {"version":3,"file":"instances.d.ts","sourceRoot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AE,IAAI,EAAE,SAAS,EAAE,MAAM,GAAE,SAAqB,GAAG,MAAM,EAAE,GAAG,IAAI,GAAG,SAAS,CAG3H;AAoDD;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,EACjC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,uBAAuB,GAC5B,OAAO,CAAC,IAAI,CAAC,CAwKf"}
@@ -34,11 +34,22 @@
34
34
  * rolled up by ruling. A block under an expanded call whose own expansion
35
35
  * or whose call's expansion cannot be counted gets no instances at all,
36
36
  * since a partial list would name ids the plan never prints.
37
+ *
38
+ * Since #5117 an expansion none of those forms counts is read once more with
39
+ * `./evaluate.ts`, which follows locals that read locals, interpolation,
40
+ * `lookup()` and module outputs: a `for_each` over a local map whose values
41
+ * interpolate another local gets its keys, since a map's keys are known when
42
+ * some of its values are not. The same evaluator then gives each resource
43
+ * block its `evaluated` arguments, per instance when it has instance nodes,
44
+ * for the reference catalog. Since #5094 that reading includes `==` and
45
+ * `!=`, and a block whose expansion comes to zero instances gets
46
+ * `{ instances: {} }`, so the catalog reads nothing on it.
37
47
  */
38
48
  import { readdirSync, readFileSync, statSync } from "node:fs";
39
49
  import { join, resolve } from "node:path";
40
50
  import { isResourceDeclarable } from "@intentius/chant/declarable";
41
51
  import { loadHcl2json } from "@intentius/chant/terraform/hcl2json";
52
+ import { RootEvaluator, evaluateArguments, instanceKeyValue, isSetValue, isUnknown } from "./evaluate.js";
42
53
  import { DATA_TYPE, LOCALS_TYPE, MODULE_TYPE, RESOURCE_TYPE, VARIABLE_TYPE, callersOfKey, literalInstanceKeys, scopeOfKey, } from "./parse.js";
43
54
  /** The most instance nodes one block gets; past it the block draws alone. */
44
55
  const MAX_INSTANCES = 256;
@@ -133,7 +144,7 @@ function rollupCodeOf(value) {
133
144
  * A block's expansion in a scope: its instance keys as Terraform prints them,
134
145
  * `null` when the block is not expanded, or why the keys are not known.
135
146
  */
136
- export function expansionIn(body, scope) {
147
+ export function expansionIn(body, scope, evaluateFully) {
137
148
  if (!("count" in body) && !("for_each" in body))
138
149
  return null;
139
150
  const argument = "count" in body ? "count" : "for_each";
@@ -159,12 +170,32 @@ export function expansionIn(body, scope) {
159
170
  keys = Object.keys(v.value).sort().map((k) => `[${JSON.stringify(k)}]`);
160
171
  }
161
172
  }
173
+ if (keys === undefined && evaluateFully)
174
+ keys = keysOfValue(argument, evaluateFully(expr));
162
175
  if (keys === undefined)
163
176
  return rolled(rollupCodeOf(expr));
164
177
  if (keys.length > MAX_INSTANCES)
165
178
  return rolled("instances-over-limit");
166
179
  return { keys };
167
180
  }
181
+ /**
182
+ * The instance keys of an evaluated `count` or `for_each` (#5117): a whole
183
+ * number, a map (whose keys are known even when some of its values are not),
184
+ * or a set of strings `toset()` made. Undefined for anything else.
185
+ */
186
+ function keysOfValue(argument, v) {
187
+ if (isUnknown(v))
188
+ return undefined;
189
+ if (argument === "count")
190
+ return typeof v === "number" && Number.isInteger(v) && v >= 0 ? Array.from({ length: v }, (_, i) => `[${i}]`) : undefined;
191
+ if (isSetValue(v)) {
192
+ const list = v;
193
+ return list.every((s) => typeof s === "string") ? [...new Set(list)].sort().map((k) => `[${JSON.stringify(k)}]`) : undefined;
194
+ }
195
+ if (typeof v === "object" && v !== null && !Array.isArray(v))
196
+ return Object.keys(v).sort().map((k) => `[${JSON.stringify(k)}]`);
197
+ return undefined;
198
+ }
168
199
  /**
169
200
  * The instance keys a block's `count` or `for_each` gives in `vars`, as
170
201
  * Terraform prints them. `null` when the block is not expanded, undefined
@@ -255,6 +286,12 @@ export async function resolveInstanceNodes(entities, root, opts) {
255
286
  into.set(name, value);
256
287
  }
257
288
  const tfvars = await rootTfvars(opts);
289
+ const evaluator = new RootEvaluator(entities, root, tfvars);
290
+ /** The full evaluator over a block-level read of a scope (#5117), where the narrow forms above give no keys. */
291
+ const evaluateIn = (scope) => (raw) => {
292
+ const place = evaluator.placeOfScope(scope);
293
+ return place ? evaluator.value(raw, { place }) : undefined;
294
+ };
258
295
  const scopes = new Map();
259
296
  const localScopes = new Map();
260
297
  /**
@@ -318,7 +355,7 @@ export async function resolveInstanceNodes(entities, root, opts) {
318
355
  const call = entities.get(callKey);
319
356
  if (!call || call.entityType !== MODULE_TYPE)
320
357
  return undefined;
321
- return expansionIn(bodyOf(call), scopeOf(scopeOfKey(callKey)));
358
+ return expansionIn(bodyOf(call), scopeOf(scopeOfKey(callKey)), evaluateIn(scopeOfKey(callKey)));
322
359
  };
323
360
  const keysOf = (e) => e === undefined ? undefined : e === null ? null : "keys" in e ? e.keys : undefined;
324
361
  for (const [key, entity] of own) {
@@ -327,7 +364,7 @@ export async function resolveInstanceNodes(entities, root, opts) {
327
364
  const callers = callersOfKey(key);
328
365
  const calls = callers.map((_, i) => callExpansion(`${root}/${callers.slice(0, i + 1).join("/")}`));
329
366
  const chain = calls.map(keysOf);
330
- const own = expansionIn(bodyOf(entity), scopeOf(scopeOfKey(key)));
367
+ const own = expansionIn(bodyOf(entity), scopeOf(scopeOfKey(key)), evaluateIn(scopeOfKey(key)));
331
368
  const ownKeys = keysOf(own);
332
369
  const ownRollup = own !== null && "rollup" in own ? own.rollup : undefined;
333
370
  const expandedChain = chain.some((k) => k !== null);
@@ -387,4 +424,53 @@ export async function resolveInstanceNodes(entities, root, opts) {
387
424
  }
388
425
  entities.set(key, { ...rest, instances });
389
426
  }
427
+ // Each resource block's expressions, per instance when it has instance
428
+ // nodes (#5117), for the reference catalog.
429
+ for (const [key] of own) {
430
+ const entity = entities.get(key);
431
+ if (!entity || entity.entityType !== RESOURCE_TYPE)
432
+ continue;
433
+ const evaluated = evaluateBlock(evaluator, entity, key);
434
+ if (evaluated)
435
+ entities.set(key, { ...entity, props: { ...entity.props, evaluated } });
436
+ }
437
+ }
438
+ const hasAny = (e) => e.arguments !== undefined || e.stopped !== undefined;
439
+ /**
440
+ * A resource block's evaluated arguments (#5117): one entry per instance node
441
+ * the graph will list, keyed by the instance address, or the block's own when
442
+ * it has none. Undefined when nothing in it holds an expression and it has no
443
+ * instance nodes.
444
+ */
445
+ function evaluateBlock(evaluator, entity, key) {
446
+ const body = bodyOf(entity);
447
+ const scope = scopeOfKey(key);
448
+ const address = entity.props.address;
449
+ const callers = callersOfKey(key);
450
+ const listed = entity.instances;
451
+ const keys = entity.instanceKeys;
452
+ // A count or for_each the files settle at zero (`count = var.on == "true" ? 1 : 0` with it off, #5094)
453
+ // plans no instance, so nothing is read for the catalog to match.
454
+ if ((listed && listed.length === 0) || (!listed && keys && keys.length === 0 && ("count" in body || "for_each" in body)))
455
+ return { instances: {} };
456
+ if ((listed && listed.length > 0) || (keys && keys.length > 0)) {
457
+ const entries = listed && listed.length > 0 ? [...listed] : keys.map((k) => ({ key: k }));
458
+ const instances = {};
459
+ for (const inst of entries) {
460
+ const place = inst.scope !== undefined ? evaluator.placeOfInstanceScope(inst.scope) : evaluator.placeOfScope(scope);
461
+ if (!place)
462
+ continue;
463
+ const k = inst.key !== undefined ? instanceKeyValue(inst.key) : undefined;
464
+ const iteration = k !== undefined ? evaluator.iterationOf(body, { place }, k) : evaluator.blockIteration(body, place);
465
+ const path = inst.scope ?? callers.join(".");
466
+ instances[`${path ? `${path}.` : ""}${address}${inst.key ?? ""}`] = evaluateArguments(body, (raw) => evaluator.value(raw, { place, ...(iteration ? { iteration } : {}) }));
467
+ }
468
+ return { instances };
469
+ }
470
+ const place = evaluator.placeOfScope(scope);
471
+ if (!place)
472
+ return undefined;
473
+ const iteration = evaluator.blockIteration(body, place);
474
+ const out = evaluateArguments(body, (raw) => evaluator.value(raw, { place, ...(iteration ? { iteration } : {}) }));
475
+ return hasAny(out) ? out : undefined;
390
476
  }
@@ -44,6 +44,15 @@ export type BlockBody = Record<string, unknown>;
44
44
  export type TerraformExpansion = "count" | "for_each";
45
45
  /** Whether a root runs under choudoufu with a declared estate (#2103). */
46
46
  export type TerraformRootMode = "live" | "state";
47
+ /** What `./evaluate.ts` made of a block's expressions (chant #5117). */
48
+ export interface TerraformEvaluated {
49
+ readonly arguments?: Record<string, unknown>;
50
+ readonly stopped?: Record<string, string>;
51
+ readonly instances?: Record<string, {
52
+ readonly arguments?: Record<string, unknown>;
53
+ readonly stopped?: Record<string, string>;
54
+ }>;
55
+ }
47
56
  /** The entity every block becomes. `props` is what post-synth checks read. */
48
57
  export interface TerraformEntity extends Declarable {
49
58
  readonly lexicon: "terraform";
@@ -134,6 +143,18 @@ export interface TerraformEntity extends Declarable {
134
143
  * expansion.
135
144
  */
136
145
  readonly expansion?: TerraformExpansion;
146
+ /**
147
+ * A `resource` block's arguments that hold an expression, evaluated from
148
+ * the files a plan reads (chant #5117, `./evaluate.ts`): `arguments` has
149
+ * the ones that resolved, shaped like `body`, and `stopped` names, per
150
+ * argument that did not, the first reference that stopped it. A block
151
+ * with instance nodes has one such pair per instance instead, under
152
+ * `instances`, keyed by the instance's address as Terraform prints it
153
+ * (`module.sa["a"].google_service_account.this`). The reference catalog
154
+ * reads it through `terraformDeclaredNode`. Set by `./instances.ts`;
155
+ * absent when no argument holds an expression.
156
+ */
157
+ readonly evaluated?: TerraformEvaluated;
137
158
  };
138
159
  /**
139
160
  * The deployable unit this entity belongs to: the root name, which is what
@@ -321,7 +342,8 @@ export declare const LOCK_FILENAME = ".terraform.lock.hcl";
321
342
  /**
322
343
  * Parse a set of files into entities keyed `<root>/<address>`. Two blocks that
323
344
  * genuinely share an address (two `locals` blocks, or the same address in two
324
- * files of one root) are numbered `~2`, `~3` rather than overwriting.
345
+ * files of one root) are numbered `~2`, `~3` rather than overwriting. An aliased
346
+ * `provider` block is keyed `provider.<name>~<alias>` instead of by number.
325
347
  *
326
348
  * Recognises both ways an estate is declared: a `live { }` block nested in a
327
349
  * `terraform { }` block of any file here, and, when `sidecar` is given, the
@@ -1 +1 @@
1
- {"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/hcl/parse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAIH,OAAO,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CACzC,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,QAAQ,CAAC,EAAE,QAAQ,EACnB,WAAW,CAAC,EAAE,wBAAwB,EACtC,OAAO,GAAE,SAAS,MAAM,EAAO,GAC9B,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAclC;AAED;;;;;;;;GAQG;AACH,wBAAsB,yBAAyB,CAC7C,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,QAAQ,CAAC,EAAE,QAAQ,EACnB,WAAW,CAAC,EAAE,wBAAwB,GACrC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAElC;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,aAAa,EAAE,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,aAAa,EAAE,CAGhG;AAED,2EAA2E;AAC3E,eAAO,MAAM,eAAe,eAAe,CAAC;AAE5C;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAInD;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAG9C;AAED,kGAAkG;AAClG,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAGlD"}
package/dist/hcl/parse.js CHANGED
@@ -259,7 +259,8 @@ export const LOCK_FILENAME = ".terraform.lock.hcl";
259
259
  /**
260
260
  * Parse a set of files into entities keyed `<root>/<address>`. Two blocks that
261
261
  * genuinely share an address (two `locals` blocks, or the same address in two
262
- * files of one root) are numbered `~2`, `~3` rather than overwriting.
262
+ * files of one root) are numbered `~2`, `~3` rather than overwriting. An aliased
263
+ * `provider` block is keyed `provider.<name>~<alias>` instead of by number.
263
264
  *
264
265
  * Recognises both ways an estate is declared: a `live { }` block nested in a
265
266
  * `terraform { }` block of any file here, and, when `sidecar` is given, the
@@ -298,9 +299,14 @@ export async function blocksToEntities(files, root, hcl2json, modeOptions, sidec
298
299
  ...(modeOptions?.configEstate !== undefined ? { configEstate: modeOptions.configEstate } : {}),
299
300
  ...(callers.length > 0 ? { callers } : {}),
300
301
  }, source, line, suppressions);
301
- let key = `${prefix}/${address}`;
302
+ // An aliased provider shares its address with the other blocks of that
303
+ // provider, so it is keyed by its alias, not by its place among them: a
304
+ // block added elsewhere in the root no longer renumbers it (#5106).
305
+ const alias = entityType === PROVIDER_TYPE && typeof plain.alias === "string" && plain.alias.trim() !== "" ? plain.alias.trim() : undefined;
306
+ const base = alias !== undefined ? `${address}~${alias}` : address;
307
+ let key = `${prefix}/${base}`;
302
308
  for (let n = 2; entities.has(key); n++)
303
- key = `${prefix}/${address}~${n}`;
309
+ key = `${prefix}/${base}~${n}`;
304
310
  entities.set(key, entity);
305
311
  };
306
312
  /** `terraform` and `locals` carry no labels: the tree holds a bare body array. */
@@ -10,7 +10,11 @@
10
10
  * redacted form.
11
11
  *
12
12
  * `body` keeps its `default` key: TF006 asks whether a sensitive variable
13
- * declares a default, and that fact survives. Only the value goes.
13
+ * declares a default, and that fact survives. Only the value goes. A
14
+ * `default = null` is the exception (#5081): it holds no value, so there is
15
+ * nothing to leave out, and it is the way to say "optional, nothing committed".
16
+ * Replacing it would make it look like a committed default to the rules that
17
+ * read the body.
14
18
  *
15
19
  * The source scanner skips strings (with `${}`), heredocs and comments, finds
16
20
  * each top-level `variable` block, and inside it the `sensitive` and `default`
@@ -1 +1 @@
1
- {"version":3,"file":"redact.d.ts","sourceRoot":"","sources":["../../src/hcl/redact.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,eAAO,MAAM,qBAAqB,gBAAgB,CAAC;AAsHnD,wGAAwG;AACxG,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAkC5D;AAED,gJAAgJ;AAChJ,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,CAGjF"}
1
+ {"version":3,"file":"redact.d.ts","sourceRoot":"","sources":["../../src/hcl/redact.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,eAAO,MAAM,qBAAqB,gBAAgB,CAAC;AAsHnD,wGAAwG;AACxG,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAkC5D;AAED,gJAAgJ;AAChJ,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,CAGjF"}
@@ -10,7 +10,11 @@
10
10
  * redacted form.
11
11
  *
12
12
  * `body` keeps its `default` key: TF006 asks whether a sensitive variable
13
- * declares a default, and that fact survives. Only the value goes.
13
+ * declares a default, and that fact survives. Only the value goes. A
14
+ * `default = null` is the exception (#5081): it holds no value, so there is
15
+ * nothing to leave out, and it is the way to say "optional, nothing committed".
16
+ * Replacing it would make it look like a committed default to the rules that
17
+ * read the body.
14
18
  *
15
19
  * The source scanner skips strings (with `${}`), heredocs and comments, finds
16
20
  * each top-level `variable` block, and inside it the `sensitive` and `default`
@@ -199,7 +203,7 @@ export function redactSensitiveSource(source) {
199
203
  const sensitive = attrs.some((a) => a.name === "sensitive" && source.slice(a.from, a.to) === "true");
200
204
  if (sensitive)
201
205
  for (const a of attrs)
202
- if (a.name === "default")
206
+ if (a.name === "default" && source.slice(a.from, a.to) !== "null")
203
207
  spans.push([a.from, a.to]);
204
208
  }
205
209
  variable = false;
@@ -222,7 +226,7 @@ export function redactSensitiveSource(source) {
222
226
  }
223
227
  /** A variable body with its `default` replaced, when the variable is a literal `sensitive = true` with a default. Otherwise the body itself. */
224
228
  export function redactSensitiveBody(body) {
225
- if (body.sensitive !== true || !("default" in body))
229
+ if (body.sensitive !== true || !("default" in body) || body.default === null)
226
230
  return body;
227
231
  return { ...body, default: SENSITIVE_PLACEHOLDER };
228
232
  }
@@ -48,7 +48,18 @@ export declare function collectReferences(text: string): string[];
48
48
  * address that happens to look the same.
49
49
  */
50
50
  export declare function providerReference(value: unknown): string | undefined;
51
- /** Every reference in one block body, provider meta-arguments included. */
51
+ /**
52
+ * Every reference in one block body, provider meta-arguments included.
53
+ *
54
+ * The walk reaches every string in the body at any depth. hcl2json wraps each
55
+ * nested block in an array, so a provider's `rule { match { expr { ... } } }`
56
+ * is already six levels down before its attribute, and real providers nest
57
+ * further; a depth cap would have to be guessed and would still miss someone's
58
+ * block. Instead the walk is iterative, so a deeply nested body cannot
59
+ * overflow the call stack, and it marks each container it has opened, so a
60
+ * body that shares a sub-object or points back at an ancestor is read once and
61
+ * cannot loop. Cost is linear in the number of values in the body.
62
+ */
52
63
  export declare function referencesInBody(body: BlockBody): string[];
53
64
  /**
54
65
  * Every reference in one module scope: token to the entity keys whose body
@@ -1 +1 @@
1
- {"version":3,"file":"references.d.ts","sourceRoot":"","sources":["../../src/hcl/references.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAAwB,KAAK,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACpF,OAAO,EAAc,KAAK,SAAS,EAAwB,MAAM,SAAS,CAAC;AAc3E;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAOxD;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAMpE;AAED,2EAA2E;AAC3E,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,EAAE,CA6B1D;AAED;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;AAEvD,4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AAE,eAAe,CAAC,CAAC;CAC/C;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG,cAAc,CAqBrF;AAED,gEAAgE;AAChE,wBAAgB,YAAY,CAAC,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAE7F;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,cAAc,EACrB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAMT"}
@@ -76,12 +76,24 @@ export function providerReference(value) {
76
76
  const m = PROVIDER_REF_RE.exec((inner ? inner[1] : trimmed).trim());
77
77
  return m ? `provider.${m[1]}.${m[2]}` : undefined;
78
78
  }
79
- /** Every reference in one block body, provider meta-arguments included. */
79
+ /**
80
+ * Every reference in one block body, provider meta-arguments included.
81
+ *
82
+ * The walk reaches every string in the body at any depth. hcl2json wraps each
83
+ * nested block in an array, so a provider's `rule { match { expr { ... } } }`
84
+ * is already six levels down before its attribute, and real providers nest
85
+ * further; a depth cap would have to be guessed and would still miss someone's
86
+ * block. Instead the walk is iterative, so a deeply nested body cannot
87
+ * overflow the call stack, and it marks each container it has opened, so a
88
+ * body that shares a sub-object or points back at an ancestor is read once and
89
+ * cannot loop. Cost is linear in the number of values in the body.
90
+ */
80
91
  export function referencesInBody(body) {
81
92
  const found = new Set();
82
- const visit = (value, key, depth) => {
83
- if (depth > 6)
84
- return;
93
+ const opened = new Set();
94
+ const stack = [[body, ""]];
95
+ while (stack.length > 0) {
96
+ const [value, key] = stack.pop();
85
97
  if (typeof value === "string") {
86
98
  for (const ref of collectReferences(value))
87
99
  found.add(ref);
@@ -90,23 +102,28 @@ export function referencesInBody(body) {
90
102
  if (provider)
91
103
  found.add(provider);
92
104
  }
93
- return;
105
+ continue;
94
106
  }
107
+ if (typeof value !== "object" || value === null)
108
+ continue;
109
+ // A key is passed down unchanged through arrays, so the same container
110
+ // reached under two different keys could in principle matter. A body is a
111
+ // tree, so it is not, and a repeat visit only repeats what was found.
112
+ if (opened.has(value))
113
+ continue;
114
+ opened.add(value);
95
115
  if (Array.isArray(value)) {
96
116
  for (const item of value)
97
- visit(item, key, depth + 1);
98
- return;
117
+ stack.push([item, key]);
118
+ continue;
99
119
  }
100
- if (typeof value === "object" && value !== null) {
101
- for (const [k, v] of Object.entries(value)) {
102
- // `providers = { aws = aws.west }` maps a child module's provider name
103
- // to the caller's block, so every VALUE under `providers` is a
104
- // provider reference, whatever its key.
105
- visit(v, key === "providers" ? "provider" : k, depth + 1);
106
- }
120
+ for (const [k, v] of Object.entries(value)) {
121
+ // `providers = { aws = aws.west }` maps a child module's provider name
122
+ // to the caller's block, so every VALUE under `providers` is a
123
+ // provider reference, whatever its key.
124
+ stack.push([v, key === "providers" ? "provider" : k]);
107
125
  }
108
- };
109
- visit(body, "", 0);
126
+ }
110
127
  return [...found];
111
128
  }
112
129
  /**
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "algorithm": "sha256",
3
3
  "artifacts": {
4
- "manifest.json": "5510ea4437a27307658c908c5f6e3625fc78f6f7adef8aabda9bb51de0232b3f",
4
+ "manifest.json": "7a2d38b1181b1bef2c8e2fde7e4f98ed2e80559916810b246cc0f6dc12c477b7",
5
5
  "meta.json": "ca3d163bab055381827226140568f3bef7eaac187cebd76878e0b63e9e442356",
6
6
  "types/index.d.ts": "022927e6a7b351cc4cf52d5f973f60ccd140e5810e17b32fb8868965aa1db161",
7
7
  "rules/plan-before-apply.ts": "7c10245b2c3335253b48ee7d8b075d89f43116bde20313a5d1031b343fef1282",
@@ -11,12 +11,12 @@
11
11
  "rules/record-store.ts": "644ef9785ea9500e8945a181160aff1c4133ad895451413b40d293abc9620066",
12
12
  "rules/scope.ts": "a6d327d821f219c98a9d4ae6e6eed6325f3d3edf6286f3622b41be591d190dc8",
13
13
  "rules/terragrunt.ts": "1973dbee0933db9593347aa662c71b86f02302c19a28f5ecba23a694ca96641b",
14
- "rules/tf001.ts": "d0c20e9e70403ec79515114cc00dff8c599c372b343ff96beb951bb7b0dbf9ba",
15
- "rules/tf002.ts": "6759fe5135c85ed9016adbddd90e77743cdf243b261a98deb38e907da83c6d25",
14
+ "rules/tf001.ts": "c8b89257851014f1979f711b3c62719097d712c52a238b1b32d0a5b67bb3fd5e",
15
+ "rules/tf002.ts": "f9db8b4252de6f7434de889465b0183b87261f701a78f8f86d2adb465641211d",
16
16
  "rules/tf003.ts": "7b705a08f03769f353910e524bb3f1b4cc844bcb620e240a9063288d0fd60802",
17
17
  "rules/tf004.ts": "59ef2108aa561cc6a40cd970fc54604be60872b51a035ed3bc3c53346a31d358",
18
18
  "rules/tf005.ts": "17fbaf5ac205c8a768415eacd2cbfb7749e9a251c8f2d0c05dce7462db7fa821",
19
- "rules/tf006.ts": "2d6a80d048cb337d189e735224437ac851b51d73d9ff55f5d1ffedf736c16fb0",
19
+ "rules/tf006.ts": "90f5a4464073711bb8cb523de671732c16b832b81939fa96bd670549cfa697af",
20
20
  "rules/tf007.ts": "9a1eeb1dbaf230b841cc32f2753219e57a6e7a2296d9ed6c1fb1e8e38a9a594d",
21
21
  "rules/tf008.ts": "b09eefcdf6c37207d9d7270d1753a7812a0a07d2e88767f8c7a7885e42c0a730",
22
22
  "rules/tf009.ts": "8631838f4756e5fdc163ccc283e59002accdcbe4384d11ee20a2be9514f7b2a9",
@@ -32,7 +32,7 @@
32
32
  "rules/tf019.ts": "ae1841a358e5b7a3f42c484f0b5cf1c1f5aa845a50516969a46d65b13e282951",
33
33
  "rules/tf020.ts": "2210815c355e37459c34de0fe622f0b87b78010ee7c444135cf5abf7e048adf7",
34
34
  "rules/tf021.ts": "ad3cd813a289437d33da866927697077e7a5b20f3c05341325193d286b57bbd5",
35
- "rules/tf022.ts": "5466797cd88fd5489f6c5abd1e796d7c5d3d0e977d0e9e043d253f6ecf369cdc",
35
+ "rules/tf022.ts": "48aeb321f230f8963772af8890d1ccdcdee81a43215d9e981b105bedf97d5747",
36
36
  "rules/tf024.ts": "e82bb9d29fb1645823899fb03fcb0381ca2df11039f02609acee861013278724",
37
37
  "rules/tf025.ts": "0c31be3885e940e2b3e9ac8e023067d8d6e2b42c04f628890405c9fc6db7d1ce",
38
38
  "rules/tf026.ts": "8cf1e61bc9563aa2d3c149f243ffa02ad4f183eebb672f861cd6c4e6fba1d310",
@@ -59,5 +59,5 @@
59
59
  "rules/tf047.ts": "bfa86f85c4c5efff297280fc2f15104d6319fa96dfc444a31829fb7353224092",
60
60
  "skills/chant-terraform.md": "53dd11c7b289652f92fdaf2c03766abda46d8964e31fe709e8b142ced4f19c50"
61
61
  },
62
- "composite": "e38dfa512d9887c84983fd85fb530864ac65a32d6a2867152d6a514895c5645a"
62
+ "composite": "77b919da2b9cdd68a381d5c355b8caac27a4a484861ac7aef7d2f33309a4c5e2"
63
63
  }
@@ -21,7 +21,10 @@
21
21
  * `# chant-ignore-block: TF001` on the line above its `terraform` block
22
22
  * (chant #2111), which is what the three shipped examples do.
23
23
  *
24
- * One diagnostic per root, fired from the root's `terraform` block. A root
24
+ * One diagnostic per root, fired from the root's first `terraform` block. The
25
+ * verdict reads every `terraform` block of the root, because Terraform merges
26
+ * them and a backend often sits in `backend.tf` or `provider.tf` beside a
27
+ * `versions.tf` block of its own (#5079). A root
25
28
  * with no `terraform` block at all is not flagged: it declares no version
26
29
  * constraints either, and the missing block is a different finding.
27
30
  *
@@ -1 +1 @@
1
- {"version":3,"file":"tf001.d.ts","sourceRoot":"","sources":["../../../src/lint/post-synth/tf001.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH,OAAO,KAAK,EACV,cAAc,EAGf,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EAAkB,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAIjE;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAK9D;AAED,uEAAuE;AACvE,eAAO,MAAM,aAAa,UAAU,CAAC;AAErC;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,EAAE,CAMtD;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAGzD;AAED,eAAO,MAAM,KAAK,EAAE,cAmDnB,CAAC"}
1
+ {"version":3,"file":"tf001.d.ts","sourceRoot":"","sources":["../../../src/lint/post-synth/tf001.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,OAAO,KAAK,EACV,cAAc,EAGf,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EAAkB,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAIjE;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAK9D;AAED,uEAAuE;AACvE,eAAO,MAAM,aAAa,UAAU,CAAC;AAErC;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,EAAE,CAMtD;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAGzD;AAED,eAAO,MAAM,KAAK,EAAE,cA8DnB,CAAC"}
@@ -21,7 +21,10 @@
21
21
  * `# chant-ignore-block: TF001` on the line above its `terraform` block
22
22
  * (chant #2111), which is what the three shipped examples do.
23
23
  *
24
- * One diagnostic per root, fired from the root's `terraform` block. A root
24
+ * One diagnostic per root, fired from the root's first `terraform` block. The
25
+ * verdict reads every `terraform` block of the root, because Terraform merges
26
+ * them and a backend often sits in `backend.tf` or `provider.tf` beside a
27
+ * `versions.tf` block of its own (#5079). A root
25
28
  * with no `terraform` block at all is not flagged: it declares no version
26
29
  * constraints either, and the missing block is a different finding.
27
30
  *
@@ -91,8 +94,14 @@ export const tf001 = {
91
94
  description: "Root module declares no remote backend",
92
95
  check(ctx) {
93
96
  const diagnostics = [];
94
- /** Root name to the entity key of the first `terraform` block seen for it. */
95
- const flagged = new Set();
97
+ /**
98
+ * Per root: the entity key of the first `terraform` block seen, whether any
99
+ * block of the root configures remote state, and whether any block names
100
+ * `backend "local"`. Terraform merges the `terraform` blocks of a module,
101
+ * so the verdict belongs to the root, not to whichever block is read first
102
+ * (#5079).
103
+ */
104
+ const roots = new Map();
96
105
  for (const [name, entity] of ctx.entities) {
97
106
  if (entity.entityType !== TERRAFORM_TYPE)
98
107
  continue;
@@ -102,17 +111,20 @@ export const tf001 = {
102
111
  if (props.mode === "live")
103
112
  continue;
104
113
  const root = typeof props.root === "string" ? props.root : "";
105
- if (flagged.has(root))
106
- continue;
107
114
  const body = (typeof props.body === "object" && props.body !== null ? props.body : {});
108
- if (hasRemoteBackend(body))
115
+ const seen = roots.get(root) ?? { entity: name, remote: false, local: false };
116
+ seen.remote || (seen.remote = hasRemoteBackend(body));
117
+ seen.local || (seen.local = backendTypes(body).includes(LOCAL_BACKEND));
118
+ roots.set(root, seen);
119
+ }
120
+ for (const [root, { entity: name, remote, local }] of roots) {
121
+ if (remote)
109
122
  continue;
110
123
  // What the root actually declares, so the message names it rather than
111
124
  // saying "no remote backend" over a block the reader can see.
112
- const found = backendTypes(body).includes(LOCAL_BACKEND)
125
+ const found = local
113
126
  ? 'the backend it declares is `backend "local"`'
114
127
  : "there is no backend block at all";
115
- flagged.add(root);
116
128
  diagnostics.push({
117
129
  checkId: "TF001",
118
130
  severity: "warning",
@@ -21,11 +21,17 @@
21
21
  * A root with no `terraform` block at all is out of scope, same as TF001:
22
22
  * the missing block is that rule's finding, not this one's.
23
23
  *
24
- * Scope: root modules only (#2112). A child module's own `required_providers`
25
- * are the child's business, and its resources are constrained by the root's
26
- * block at plan time, so folding a descended module's blocks into this pass
27
- * would both credit the root with requirements it never declared and judge it
28
- * on providers it never named.
24
+ * Scope: the providers a root implies come from the root's own blocks (#2112);
25
+ * a child module's resources and provider blocks are not judged here. The
26
+ * constraints, though, come from the whole local module tree (#5108).
27
+ * Terraform combines the `required_providers` of every module in a
28
+ * configuration, so a root that gives only `source` is constrained when a
29
+ * local module it calls pins the `version`, and the reverse. A field the root
30
+ * entry lacks is taken from a descended module's entry for the same provider
31
+ * name; the root's own value always wins. A root entry in the legacy bare
32
+ * string form stays a finding. Registry and git modules are never fetched, so
33
+ * only the local modules `descend.ts` already read can contribute, and its
34
+ * cycle guard is what bounds the tree.
29
35
  */
30
36
  import type { PostSynthCheck, PostSynthContext } from "@intentius/chant/lint/post-synth";
31
37
  /** One implied provider name to the entity key that first implied it in file order. */
@@ -1 +1 @@
1
- {"version":3,"file":"tf002.d.ts","sourceRoot":"","sources":["../../../src/lint/post-synth/tf002.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,KAAK,EACV,cAAc,EACd,gBAAgB,EAEjB,MAAM,kCAAkC,CAAC;AAkB1C,uFAAuF;AACvF,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,gBAAgB,CAAC,UAAU,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CA6B1G;AAyBD,eAAO,MAAM,KAAK,EAAE,cA2CnB,CAAC"}
1
+ {"version":3,"file":"tf002.d.ts","sourceRoot":"","sources":["../../../src/lint/post-synth/tf002.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,KAAK,EACV,cAAc,EACd,gBAAgB,EAEjB,MAAM,kCAAkC,CAAC;AAkB1C,uFAAuF;AACvF,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,gBAAgB,CAAC,UAAU,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CA6B1G;AA4CD,eAAO,MAAM,KAAK,EAAE,cAuDnB,CAAC"}