@intentius/chant-lexicon-terraform 0.124.79 → 0.124.81
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/components/capability-plugin.d.ts +74 -1
- package/dist/components/capability-plugin.d.ts.map +1 -1
- package/dist/components/capability-plugin.js +239 -138
- package/dist/components/compose-group.d.ts +2 -1
- package/dist/components/compose-group.d.ts.map +1 -1
- package/dist/components/compose-group.js +6 -6
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/init-turn.d.ts +21 -0
- package/dist/init-turn.d.ts.map +1 -0
- package/dist/init-turn.js +30 -0
- package/dist/integrity.json +2 -2
- package/dist/manifest.json +1 -1
- package/dist/op/activities/terraform.d.ts +22 -0
- package/dist/op/activities/terraform.d.ts.map +1 -1
- package/dist/op/activities/terraform.js +29 -5
- package/dist/state-reads.d.ts +20 -3
- package/dist/state-reads.d.ts.map +1 -1
- package/dist/state-reads.js +20 -4
- package/dist/terragrunt/capability.d.ts +5 -0
- package/dist/terragrunt/capability.d.ts.map +1 -1
- package/dist/terragrunt/capability.js +21 -7
- package/dist/terragrunt/run.d.ts +8 -0
- package/dist/terragrunt/run.d.ts.map +1 -1
- package/dist/terragrunt/run.js +12 -6
- package/dist/terragrunt/wave.d.ts +9 -0
- package/dist/terragrunt/wave.d.ts.map +1 -1
- package/dist/terragrunt/wave.js +22 -0
- package/package.json +2 -2
- package/src/components/capability-plugin.ts +279 -135
- package/src/components/compose-group.ts +8 -7
- package/src/components/terraform-apply-op-wave.test.ts +295 -0
- package/src/components/terraform-apply-parallel.test.ts +158 -0
- package/src/index.ts +5 -0
- package/src/init-turn.ts +36 -0
- package/src/op/activities/terraform.ts +45 -4
- package/src/state-reads.ts +23 -5
- package/src/terragrunt/capability.test.ts +94 -0
- package/src/terragrunt/capability.ts +22 -7
- package/src/terragrunt/run.ts +18 -4
- package/src/terragrunt/wave.ts +22 -0
|
@@ -119,6 +119,11 @@
|
|
|
119
119
|
* yet makes the member a hole naming it, so the root is never planned on a
|
|
120
120
|
* stand-in.
|
|
121
121
|
*
|
|
122
|
+
* - `workspace`: the workspace the root runs in (chant#4854). `init` runs in
|
|
123
|
+
* `default`, then `workspace select -or-create=true` selects it, creating
|
|
124
|
+
* it when the backend does not list it yet, and the plan, apply and
|
|
125
|
+
* output run in it. Such a root plans with `plan`, never as a one-root set.
|
|
126
|
+
*
|
|
122
127
|
* A wave's run hooks in the product's process (chant#4842) reach the step
|
|
123
128
|
* through its context. `processEnv` goes to every command for the root (a
|
|
124
129
|
* role's credentials, values from a secret store), and `afterInit` is
|
|
@@ -127,6 +132,14 @@
|
|
|
127
132
|
* plans the step's `dir` as its directory, so a product can name each root
|
|
128
133
|
* by its path without writing an entry for it.
|
|
129
134
|
*
|
|
135
|
+
* A wave that plans and applies several roots at once (chant#4864) gives
|
|
136
|
+
* each run its serial section (`DeployContext.serial`). Every `init` the
|
|
137
|
+
* step runs, a root's own and an upstream's for its `reads`, takes its turn
|
|
138
|
+
* there (`../init-turn.ts`): one at a time among the runs that share a
|
|
139
|
+
* provider cache, else one at a time per directory. A choudoufu one-root
|
|
140
|
+
* set's `live-plan-set` inits as it plans, so with a shared cache the whole
|
|
141
|
+
* command takes the turn.
|
|
142
|
+
*
|
|
130
143
|
* Every plan also writes its `show -json` beside the plan file and names it
|
|
131
144
|
* as `artifact.planJson`, the document a wave's cost hold prices
|
|
132
145
|
* (`../cost-hold.ts`).
|
|
@@ -176,6 +189,7 @@ import { fillStateReads, stateReadsProblems, waitingReadsReason, type TerraformS
|
|
|
176
189
|
import { terraformStateOpCapabilities } from "../state-ops";
|
|
177
190
|
import { terraformActionCapability } from "../action-ops";
|
|
178
191
|
import { terragruntApply } from "../terragrunt/capability";
|
|
192
|
+
import { inInitTurn, pluginCacheDir, type InitSection } from "../init-turn";
|
|
179
193
|
|
|
180
194
|
/** The `terraform-apply` step's input. */
|
|
181
195
|
export interface TerraformApplyStepInput {
|
|
@@ -183,7 +197,7 @@ export interface TerraformApplyStepInput {
|
|
|
183
197
|
root: string;
|
|
184
198
|
/** Input variables, after the root's var files. See `TerraformPlanArgs.vars`. */
|
|
185
199
|
vars?: Record<string, unknown>;
|
|
186
|
-
/** Where the `chant.config.*` search starts. Default: the current directory. */
|
|
200
|
+
/** Where the `chant.config.*` search starts. Default: the directory the caller runs the step in (`DeployContext.cwd`, an op wave's `cwd`, chant#4854), else the current directory. */
|
|
187
201
|
cwd?: string;
|
|
188
202
|
/** The root's files from here instead of its entry's `dir` (#4542): a promote under a release sets it to the recorded copy. */
|
|
189
203
|
dir?: string;
|
|
@@ -193,6 +207,49 @@ export interface TerraformApplyStepInput {
|
|
|
193
207
|
cone?: string;
|
|
194
208
|
/** Vars read from other roots' outputs (#4545), Atmos's `!terraform.state`. The step's `vars` win over them. */
|
|
195
209
|
reads?: TerraformStateRead[];
|
|
210
|
+
/**
|
|
211
|
+
* The workspace the root plans and applies in (chant#4854), such as an
|
|
212
|
+
* Atmos instance's. `init` runs in `default`, then `workspace select
|
|
213
|
+
* -or-create=true` selects it, creating it when the backend does not list
|
|
214
|
+
* it yet, and plan, apply and output run with `TF_WORKSPACE` set to it.
|
|
215
|
+
* Absent: the entry's `workspace`, or the run's environment, as before.
|
|
216
|
+
*/
|
|
217
|
+
workspace?: string;
|
|
218
|
+
/**
|
|
219
|
+
* The binary the root runs, a name on `PATH` or a path, in place of
|
|
220
|
+
* `terraform.binary` (terragucci issue 1303): a root that pins its own
|
|
221
|
+
* terraform or tofu release. A product's {@link TerraformRootResolver}
|
|
222
|
+
* sets it per root. Absent: `terraform.binary`, as before.
|
|
223
|
+
*/
|
|
224
|
+
binary?: string;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/** What a root runs in place of the step's (terragucci issue 1303). An unset field runs the step's. */
|
|
228
|
+
export interface TerraformRootTools {
|
|
229
|
+
/** The binary, a name on `PATH` or a path. See {@link TerraformApplyStepInput.binary}. */
|
|
230
|
+
binary?: string;
|
|
231
|
+
/**
|
|
232
|
+
* The environment a read of this root's state runs with over the job's,
|
|
233
|
+
* when another root's `reads` name it as their upstream (terragucci issue
|
|
234
|
+
* 1303): its role's credentials, never the reader's. The root's own plan
|
|
235
|
+
* and apply take theirs from the run hooks (`DeployContext.processEnv`).
|
|
236
|
+
*/
|
|
237
|
+
readEnv?: Record<string, string>;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* What a root runs (terragucci issue 1303), asked once per plan and per
|
|
242
|
+
* apply with the root and the step's input, as `terragrunt-apply`'s
|
|
243
|
+
* `resolveUnit` is asked per unit. A product passes its own, which installs
|
|
244
|
+
* a pinned release and checks its version, so a root runs what it plans
|
|
245
|
+
* with whatever `chant.config.ts` names.
|
|
246
|
+
*/
|
|
247
|
+
export type TerraformRootResolver = (root: string, input: TerraformApplyStepInput) => TerraformRootTools | Promise<TerraformRootTools>;
|
|
248
|
+
|
|
249
|
+
/** What {@link terraformApplyCapabilityWith} takes. */
|
|
250
|
+
export interface TerraformApplyDeps {
|
|
251
|
+
/** What each root runs. Default: the step's `binary`, else `terraform.binary`. */
|
|
252
|
+
resolveRoot?: TerraformRootResolver;
|
|
196
253
|
}
|
|
197
254
|
|
|
198
255
|
/** What `terraform-apply` returns. `outputs` is what a dependent's `stackOutput()` reads. */
|
|
@@ -230,14 +287,24 @@ function lockTimeoutOf(input: TerraformApplyStepInput): { lockTimeout?: string }
|
|
|
230
287
|
* read once, the values under the step's own `vars`. `waiting` when an
|
|
231
288
|
* upstream has no such output yet. Throws when a state cannot be read.
|
|
232
289
|
*/
|
|
233
|
-
async function withReads(input: TerraformApplyStepInput): Promise<{ input: TerraformApplyStepInput } | { waiting: string; upstreams: string[] }> {
|
|
290
|
+
async function withReads(input: TerraformApplyStepInput, resolveRoot?: TerraformRootResolver, serial?: InitSection): Promise<{ input: TerraformApplyStepInput } | { waiting: string; upstreams: string[] }> {
|
|
234
291
|
const reads = input.reads ?? [];
|
|
235
292
|
if (reads.length === 0) return { input };
|
|
236
293
|
const problems = stateReadsProblems(reads);
|
|
237
294
|
if (problems.length > 0) throw new Error(`terraform-apply: root "${input.root}": ${problems.join("; ")}`);
|
|
238
|
-
const filled = await fillStateReads(reads, async (root) => {
|
|
239
|
-
|
|
240
|
-
await
|
|
295
|
+
const filled = await fillStateReads(reads, async (root, read) => {
|
|
296
|
+
// terragucci issue 1303: the upstream's own directory, workspace, binary and environment, as terragucci's upstreamOutputs reads it.
|
|
297
|
+
const tools = resolveRoot ? await resolveRoot(root, { root, ...(input.cwd ? { cwd: input.cwd } : {}), ...(read.dir ? { dir: read.dir } : {}), ...(read.workspace ? { workspace: read.workspace } : {}) }) : undefined;
|
|
298
|
+
const at = {
|
|
299
|
+
root,
|
|
300
|
+
...(input.cwd ? { cwd: input.cwd } : {}),
|
|
301
|
+
...(read.dir ? { dir: read.dir } : {}),
|
|
302
|
+
...(read.workspace ? { workspace: read.workspace } : {}),
|
|
303
|
+
...(tools?.binary ? { binary: tools.binary } : {}),
|
|
304
|
+
...(tools?.readEnv ? { env: tools.readEnv } : {}),
|
|
305
|
+
};
|
|
306
|
+
// chant#4864: runs that plan at once may read the same upstream, so its init takes a turn.
|
|
307
|
+
await inInitTurn(serial, at.env, initDir(at), () => terraformInit(at));
|
|
241
308
|
return terraformOutputs(at);
|
|
242
309
|
});
|
|
243
310
|
if (filled.errors.length > 0) throw new Error(`terraform-apply: root "${input.root}": ${filled.errors.join("; ")}`);
|
|
@@ -258,17 +325,37 @@ function waitingOnReads(ctx: DeployContext, input: TerraformApplyStepInput, wait
|
|
|
258
325
|
/** A run hook's environment (chant#4842, `DeployContext.processEnv`), which every command for the root runs with. */
|
|
259
326
|
type RunEnv = Record<string, string> | undefined;
|
|
260
327
|
|
|
261
|
-
const rootArgs = (input: TerraformApplyStepInput, env?: RunEnv) => ({
|
|
328
|
+
const rootArgs = (input: TerraformApplyStepInput, env?: RunEnv) => ({
|
|
329
|
+
root: input.root,
|
|
330
|
+
...(input.cwd ? { cwd: input.cwd } : {}),
|
|
331
|
+
...(input.dir ? { dir: input.dir } : {}),
|
|
332
|
+
...(env ? { env } : {}),
|
|
333
|
+
...(input.workspace ? { workspace: input.workspace } : {}),
|
|
334
|
+
...(input.binary ? { binary: input.binary } : {}),
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
/** The directory an init runs in, as far as the step's input says, for its turn when no provider cache is shared (chant#4864). */
|
|
338
|
+
const initDir = (at: { root: string; cwd?: string; dir?: string }): string => join(at.cwd ?? process.cwd(), at.dir ?? at.root);
|
|
339
|
+
|
|
340
|
+
/** `terraform init` of `input`'s root in its turn (chant#4864). */
|
|
341
|
+
const initRoot = (input: TerraformApplyStepInput, env: RunEnv, serial: InitSection | undefined) =>
|
|
342
|
+
inInitTurn(serial, env, initDir(rootArgs(input, env)), () => terraformInit(rootArgs(input, env)));
|
|
262
343
|
|
|
263
344
|
function requireRoot(input: TerraformApplyStepInput): void {
|
|
264
345
|
if (typeof input.root !== "string" || input.root === "") {
|
|
265
346
|
throw new Error('terraform-apply: "root" is required and names an entry in terraform.roots');
|
|
266
347
|
}
|
|
348
|
+
if (input.workspace !== undefined && (typeof input.workspace !== "string" || input.workspace.trim() === "")) {
|
|
349
|
+
throw new Error(`terraform-apply: root "${input.root}": workspace must name a workspace`);
|
|
350
|
+
}
|
|
351
|
+
if (input.binary !== undefined && (typeof input.binary !== "string" || input.binary.trim() === "")) {
|
|
352
|
+
throw new Error(`terraform-apply: root "${input.root}": binary must name a binary or its path`);
|
|
353
|
+
}
|
|
267
354
|
}
|
|
268
355
|
|
|
269
|
-
async function planRoot(input: TerraformApplyStepInput, targets?: string[], at: { env?: RunEnv; afterInit?: () => Promise<void
|
|
356
|
+
async function planRoot(input: TerraformApplyStepInput, targets?: string[], at: { env?: RunEnv; afterInit?: () => Promise<void>; serial?: InitSection } = {}): Promise<PlannedRoot & { changeSet?: ChangeSetPart; json?: unknown }> {
|
|
270
357
|
requireRoot(input);
|
|
271
|
-
await
|
|
358
|
+
await initRoot(input, at.env, at.serial);
|
|
272
359
|
// chant#4842: the run hook's check, once init fetched the modules and providers and before the plan runs their code.
|
|
273
360
|
await at.afterInit?.();
|
|
274
361
|
// One `show -json` per plan (#4479): its document is the digest, the change
|
|
@@ -399,8 +486,41 @@ function isShapeArtifact(value: unknown): value is TerraformShapeArtifact {
|
|
|
399
486
|
return v?.kind === "terraform-apply-shape" && typeof v.digest === "string" && typeof v.shape === "object" && v.shape !== null;
|
|
400
487
|
}
|
|
401
488
|
|
|
489
|
+
/** Each step input core passed, as it was filled (chant#4854, terragucci issue 1303), for the methods core calls with the input alone. */
|
|
490
|
+
const filledInputs = new WeakMap<object, TerraformApplyStepInput>();
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* The step's input with `cwd` set to the caller's directory when it names
|
|
494
|
+
* none (chant#4854, `DeployContext.cwd`): an op wave run in process for
|
|
495
|
+
* another directory finds that directory's `chant.config.*`, not the
|
|
496
|
+
* process's. The input core passed is remembered, so `defaultLockGrain`,
|
|
497
|
+
* `lockGrainRefusal` and `traceFacts`, which get the input alone, read the
|
|
498
|
+
* same config.
|
|
499
|
+
*/
|
|
500
|
+
export function withContextCwd(ctx: { cwd?: string } | undefined, input: TerraformApplyStepInput): TerraformApplyStepInput {
|
|
501
|
+
if (!input || typeof input !== "object" || input.cwd !== undefined || ctx?.cwd === undefined) return input;
|
|
502
|
+
const filled = { ...input, cwd: ctx.cwd };
|
|
503
|
+
filledInputs.set(input, { ...filledInputs.get(input), ...filled });
|
|
504
|
+
return filled;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/** The step's input with `cwd` from the context and what `resolveRoot` answers for the root (terragucci issue 1303), remembered for the input core passed. */
|
|
508
|
+
async function filledInput(resolveRoot: TerraformRootResolver | undefined, ctx: { cwd?: string } | undefined, input: TerraformApplyStepInput): Promise<TerraformApplyStepInput> {
|
|
509
|
+
const at = withContextCwd(ctx, input);
|
|
510
|
+
if (!resolveRoot || !at || typeof at !== "object" || typeof at.root !== "string" || at.root === "") return at;
|
|
511
|
+
const tools = await resolveRoot(at.root, at);
|
|
512
|
+
if (tools?.binary !== undefined && (typeof tools.binary !== "string" || tools.binary.trim() === "")) {
|
|
513
|
+
throw new Error(`terraform-apply: root "${at.root}": the product's resolveRoot answered a binary that names nothing`);
|
|
514
|
+
}
|
|
515
|
+
if (!tools?.binary) return at;
|
|
516
|
+
const filled = { ...at, binary: tools.binary };
|
|
517
|
+
filledInputs.set(input, filled);
|
|
518
|
+
return filled;
|
|
519
|
+
}
|
|
520
|
+
|
|
402
521
|
/** The root's directory, as `terraform.roots` names it from the nearest `chant.config.*`, and the configured binary. */
|
|
403
|
-
async function rootDir(
|
|
522
|
+
async function rootDir(given: TerraformApplyStepInput): Promise<{ dir: string; binary?: string } | undefined> {
|
|
523
|
+
const input = filledInputs.get(given) ?? given;
|
|
404
524
|
const start = resolve(input.cwd ?? process.cwd());
|
|
405
525
|
const { config, configPath } = await loadChantConfigUpward(start);
|
|
406
526
|
const terraform = (config as { terraform?: TerraformConfig }).terraform;
|
|
@@ -408,7 +528,8 @@ async function rootDir(input: TerraformApplyStepInput): Promise<{ dir: string; b
|
|
|
408
528
|
const declared = terraform?.roots?.[input.root]?.dir ?? input.dir;
|
|
409
529
|
if (declared === undefined) return undefined;
|
|
410
530
|
const dir = input.dir ?? declared;
|
|
411
|
-
|
|
531
|
+
const binary = input.binary ?? terraform?.binary;
|
|
532
|
+
return { dir: resolve(configPath ? dirname(configPath) : start, dir), ...(binary ? { binary } : {}) };
|
|
412
533
|
}
|
|
413
534
|
|
|
414
535
|
const firstLines = (err: unknown): string => {
|
|
@@ -433,7 +554,7 @@ async function previewRoot(ctx: DeployContext, input: TerraformApplyStepInput, u
|
|
|
433
554
|
if (typeof stand === "string") return waitingRoot(ctx, input, unresolved, stand);
|
|
434
555
|
let planned: Awaited<ReturnType<typeof terraformPlan>>;
|
|
435
556
|
try {
|
|
436
|
-
await
|
|
557
|
+
await initRoot(input, ctx.processEnv, ctx.serial);
|
|
437
558
|
await ctx.afterInit?.();
|
|
438
559
|
planned = await terraformPlan({
|
|
439
560
|
...rootArgs(input, ctx.processEnv),
|
|
@@ -541,8 +662,8 @@ async function runChoudoufuWave(
|
|
|
541
662
|
}
|
|
542
663
|
|
|
543
664
|
/** The input a `run` that plans for itself plans with (#4545): its reads filled, or an error naming the upstream to apply first. */
|
|
544
|
-
async function readsForRun(input: TerraformApplyStepInput): Promise<TerraformApplyStepInput> {
|
|
545
|
-
const read = await withReads(input);
|
|
665
|
+
async function readsForRun(input: TerraformApplyStepInput, resolveRoot?: TerraformRootResolver, serial?: InitSection): Promise<TerraformApplyStepInput> {
|
|
666
|
+
const read = await withReads(input, resolveRoot, serial);
|
|
546
667
|
if ("waiting" in read) throw new Error(`terraform-apply: root "${input.root}": ${read.waiting}`);
|
|
547
668
|
return read.input;
|
|
548
669
|
}
|
|
@@ -555,132 +676,155 @@ async function plannerOf(input: TerraformApplyStepInput, plan?: CapabilityPlan):
|
|
|
555
676
|
return planner === "terraform" || planner === "tofu" || planner === "choudoufu" ? planner : "terraform";
|
|
556
677
|
}
|
|
557
678
|
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
//
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
const
|
|
588
|
-
const
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
679
|
+
/**
|
|
680
|
+
* `terraform-apply` with `deps` in place of the defaults (terragucci issue
|
|
681
|
+
* 1303). `resolveRoot` answers what each root runs, so a product whose roots
|
|
682
|
+
* pin their own releases passes its resolver, as it passes `resolveUnit` to
|
|
683
|
+
* `terragruntApplyCapability`. A composed group (`together`) runs the
|
|
684
|
+
* project's binary, as before.
|
|
685
|
+
*/
|
|
686
|
+
export function terraformApplyCapabilityWith(deps: TerraformApplyDeps = {}): Capability<TerraformApplyStepInput, TerraformApplyStepOutput> {
|
|
687
|
+
return {
|
|
688
|
+
kind: "terraform-apply",
|
|
689
|
+
// A root's apply has no undo short of applying the previous configuration,
|
|
690
|
+
// which is a change of its own. COMP003 asks the component to say so.
|
|
691
|
+
rollbackPolicy: "needs-opt-out",
|
|
692
|
+
// #4300: `--target` passes through as `-target`, and the saved plan holds those addresses alone.
|
|
693
|
+
targets: "accept",
|
|
694
|
+
// #4627: `plan` refreshes the root's state before it plans unless told `-refresh=false`, which chant never passes,
|
|
695
|
+
// so `--refresh` asks for what every plan does and the digest still binds it. `-target` plans a resource with what it
|
|
696
|
+
// depends on and never what depends on it, so `--target-dependents` has nothing to map onto.
|
|
697
|
+
planFlags: {
|
|
698
|
+
refresh: "accept",
|
|
699
|
+
targetDependents: { refuse: "terraform and tofu plan a -target with what it depends on, never what depends on it, so there is no flag to widen it to its dependents; name each dependent with --target" },
|
|
700
|
+
},
|
|
701
|
+
async plan(ctx: DeployContext, step: TerraformApplyStepInput): Promise<CapabilityPlan> {
|
|
702
|
+
const given = await filledInput(deps.resolveRoot, ctx, step);
|
|
703
|
+
requireRoot(given);
|
|
704
|
+
// #4545: a root reading an upstream's output that is not there yet is a hole naming the upstream.
|
|
705
|
+
const read = await withReads(given, deps.resolveRoot, ctx.serial);
|
|
706
|
+
if ("waiting" in read) return waitingOnReads(ctx, given, read);
|
|
707
|
+
const { input } = read;
|
|
708
|
+
const unresolved = [...(ctx.unresolvedInputs ?? [])].sort();
|
|
709
|
+
const targets = ctx.targets && ctx.targets.length > 0 ? ctx.targets : undefined;
|
|
710
|
+
if (unresolved.length > 0) return previewRoot(ctx, input, unresolved, targets);
|
|
711
|
+
// A targeted root plans with `plan -target`, and a cone plan with `plan -cone` (#4545), never as a choudoufu one-root set.
|
|
712
|
+
const env = ctx.processEnv;
|
|
713
|
+
const wave = targets || input.cone ? { wave: false } : await choudoufuWaveRoot({ ...rootArgs(input, env), ...(input.vars ? { vars: input.vars } : {}) });
|
|
714
|
+
if (wave.wave) {
|
|
715
|
+
// chant#4842: live-plan-set inits and plans in one command, so the run hook's check comes before it.
|
|
716
|
+
await ctx.afterInit?.();
|
|
717
|
+
// chant#4864: live-plan-set inits too, so with a shared provider cache the whole command takes the init's turn.
|
|
718
|
+
const set = await inInitTurn(pluginCacheDir(env) ? ctx.serial : undefined, env, undefined, () => choudoufuPlanSet(rootArgs(input, env)));
|
|
719
|
+
const artifact: ChoudoufuWavePlannedRoot = {
|
|
720
|
+
planDigest: set.planDigest,
|
|
721
|
+
choudoufu: { planSetFile: set.planSetFile, setDigest: set.setDigest },
|
|
722
|
+
lockRows: terraformLockRows(input.root, set.changeSet.member.scope, set.json),
|
|
723
|
+
};
|
|
724
|
+
return { member: input.root, planDigest: set.planDigest, artifact, changeSet: set.changeSet, outputs: terraformPlannedOutputs(set.json), shape: terraformPlanShape(set.json, input.root) };
|
|
725
|
+
}
|
|
726
|
+
const { changeSet, json, ...planned } = await planRoot(input, targets, { env, ...(ctx.afterInit ? { afterInit: ctx.afterInit } : {}), ...(ctx.serial ? { serial: ctx.serial } : {}) });
|
|
727
|
+
// #4552: a choudoufu root's rows, keyed from the plan document while it is at hand.
|
|
728
|
+
const lockRows = changeSet?.member.planner === "choudoufu" ? terraformLockRows(input.root, changeSet.member.scope, json) : undefined;
|
|
729
|
+
return {
|
|
730
|
+
member: input.root,
|
|
731
|
+
planDigest: planned.planDigest,
|
|
732
|
+
artifact: { ...planned, ...(lockRows ? { lockRows } : {}) },
|
|
733
|
+
...(changeSet ? { changeSet } : {}),
|
|
734
|
+
// plywood#55: each changed resource's own digest, which a merged wave compares with the pull request's per resource.
|
|
735
|
+
resourceDigests: terraformResourceDigests(json),
|
|
736
|
+
outputs: terraformPlannedOutputs(json),
|
|
737
|
+
shape: terraformPlanShape(json, input.root),
|
|
738
|
+
...(targets ? { targets } : {}),
|
|
592
739
|
};
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
:
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
const
|
|
740
|
+
},
|
|
741
|
+
// The root's outputs as its state holds them now (#3183): what a dependent
|
|
742
|
+
// planned before this root applies reads through `stackOutput()`.
|
|
743
|
+
async outputs(ctx: DeployContext, step: TerraformApplyStepInput): Promise<Record<string, unknown>> {
|
|
744
|
+
const input = await filledInput(deps.resolveRoot, ctx, step);
|
|
745
|
+
requireRoot(input);
|
|
746
|
+
await initRoot(input, ctx.processEnv, ctx.serial);
|
|
747
|
+
return terraformOutputs(rootArgs(input, ctx.processEnv));
|
|
748
|
+
},
|
|
749
|
+
// #4447 (ws-107): a group core forms of components that read each other plans and applies as one composed run
|
|
750
|
+
// when `terraform.compose.enabled` is set (./compose-group.ts). Delegates, so the methods are read when called.
|
|
751
|
+
groupReads: (ctx, members) => terraformComposeGroup.groupReads(ctx, members),
|
|
752
|
+
// #4542: a member pointed at a release's recorded copy plans alone, since a composition reads the declared roots.
|
|
753
|
+
groupFallback: async (ctx, members) =>
|
|
754
|
+
members.some((m) => typeof m.step.dir === "string")
|
|
755
|
+
? { kind: "release-copy", reason: "a member deploys a release's recorded copy of its root, which a composition does not read" }
|
|
756
|
+
: terraformComposeGroup.groupFallback(ctx, members),
|
|
757
|
+
// #4542: the root's files, which a release cut records and a promote under it plans.
|
|
758
|
+
releaseInputs: (input, ctx) => terraformReleaseInputs(input, ctx),
|
|
759
|
+
// #4552: resource under choudoufu, the root under Terraform, tofu and Terragrunt, which refuse resource by name.
|
|
760
|
+
async defaultLockGrain(input, plan) {
|
|
761
|
+
return terraformDefaultLockGrain(await plannerOf(input, plan));
|
|
762
|
+
},
|
|
763
|
+
async lockGrainRefusal(input, grain, plan) {
|
|
764
|
+
if (grain !== "resource") return undefined;
|
|
765
|
+
const binary = (await rootDir(input).catch(() => undefined))?.binary;
|
|
766
|
+
return terraformLockGrainRefusal(grain, await plannerOf(input, plan), binary);
|
|
767
|
+
},
|
|
768
|
+
// The ruling for ci-products (2026-10-28): a Terraform, tofu or Terragrunt root waits for its root row on the ledger in place of
|
|
769
|
+
// the backend's lock. A choudoufu root stays on the resource grain and never asks for this row.
|
|
770
|
+
targetLockRow(input) {
|
|
771
|
+
return typeof input?.root === "string" && input.root !== "" ? { key: rootRowKey(input.root), target: input.root, address: input.root } : undefined;
|
|
772
|
+
},
|
|
773
|
+
lockRows(input, plan) {
|
|
774
|
+
const kept = (plan.artifact as { lockRows?: LockRow[] } | undefined)?.lockRows;
|
|
775
|
+
if (Array.isArray(kept)) return kept;
|
|
776
|
+
return plan.changeSet ? terraformLockRowsFromPart(input.root, plan.changeSet) : [];
|
|
777
|
+
},
|
|
778
|
+
// #4555: the root and the binary, for the step's span and run record.
|
|
779
|
+
traceFacts: async (input, outcome) => terraformTraceFacts(input, outcome, (await rootDir(input).catch(() => undefined))?.binary),
|
|
780
|
+
planGroup: (ctx, members) => {
|
|
781
|
+
// chant#4854: each member's lock grain reads the config at the wave's directory too.
|
|
782
|
+
for (const m of members) if (m.input) withContextCwd(m.ctx ?? ctx, m.input);
|
|
783
|
+
return terraformComposeGroup.planGroup(ctx, members);
|
|
784
|
+
},
|
|
785
|
+
runGroup: (ctx, run, members) => {
|
|
786
|
+
for (const m of members) if (m.input) withContextCwd(m.ctx ?? ctx, m.input);
|
|
787
|
+
return terraformComposeGroup.runGroup(ctx, run, members);
|
|
788
|
+
},
|
|
789
|
+
async run(ctx: DeployContext, step: TerraformApplyStepInput): Promise<TerraformApplyStepOutput> {
|
|
790
|
+
const input = await filledInput(deps.resolveRoot, ctx, step);
|
|
791
|
+
const fromWave = ctx.plans?.[input.root];
|
|
792
|
+
if (isChoudoufuWavePlan(fromWave)) return runChoudoufuWave(ctx, input, fromWave);
|
|
793
|
+
if (isShapeArtifact(fromWave)) {
|
|
794
|
+
// A root previewed with stand-ins (#4463): plan it now with the real
|
|
795
|
+
// values, and apply that plan only when it is within the preview's shape.
|
|
796
|
+
const fresh = await planRoot(await readsForRun(input, deps.resolveRoot, ctx.serial), ctx.targets, { env: ctx.processEnv, ...(ctx.serial ? { serial: ctx.serial } : {}) });
|
|
797
|
+
const differences = planShapeDifferences(fromWave.shape, terraformPlanShape(fresh.json, input.root));
|
|
798
|
+
if (differences.length > 0) throw new PlanShapeMovedError(input.root, differences);
|
|
799
|
+
const applied = await terraformApply({ ...rootArgs(input, ctx.processEnv), planFile: fresh.planFile, ...lockTimeoutOf(input) });
|
|
800
|
+
if (!applied.applied) {
|
|
801
|
+
throw new Error(`terraform-apply: root "${input.root}" refused the plan it was given (${applied.refused ?? "refused"}). ${applied.refusal ?? ""}`);
|
|
802
|
+
}
|
|
803
|
+
const outputs = await terraformOutputs(rootArgs(input, ctx.processEnv));
|
|
804
|
+
return { root: input.root, planDigest: fresh.planDigest, fromWavePlan: false, outputs };
|
|
805
|
+
}
|
|
806
|
+
const planned: PlannedRoot = isPlannedRoot(fromWave)
|
|
807
|
+
? fromWave
|
|
808
|
+
: await planRoot(await readsForRun(input, deps.resolveRoot, ctx.serial), ctx.targets, { env: ctx.processEnv, ...(ctx.serial ? { serial: ctx.serial } : {}) }).then(({ planFile, planDigest }) => ({ planFile, planDigest }));
|
|
809
|
+
const applied = await terraformApply({ ...rootArgs(input, ctx.processEnv), planFile: planned.planFile, ...lockTimeoutOf(input) });
|
|
660
810
|
if (!applied.applied) {
|
|
661
|
-
|
|
811
|
+
const message =
|
|
812
|
+
`terraform-apply: root "${input.root}" refused the plan it was given (${applied.refused ?? "refused"}). ` +
|
|
813
|
+
(applied.refusal ?? "");
|
|
814
|
+
// A plan the wave approved that choudoufu refuses as no longer matching
|
|
815
|
+
// moved since the approval (#4553: one made against another estate is a
|
|
816
|
+
// failure). One this run made itself is planned afresh by the next run.
|
|
817
|
+
if (applied.refused === "approval-mismatch" && isPlannedRoot(fromWave)) throw new TerraformPlanMovedError(input.root, message);
|
|
818
|
+
throw new Error(message);
|
|
662
819
|
}
|
|
663
820
|
const outputs = await terraformOutputs(rootArgs(input, ctx.processEnv));
|
|
664
|
-
return { root: input.root, planDigest:
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
const message =
|
|
672
|
-
`terraform-apply: root "${input.root}" refused the plan it was given (${applied.refused ?? "refused"}). ` +
|
|
673
|
-
(applied.refusal ?? "");
|
|
674
|
-
// A plan the wave approved that choudoufu refuses as no longer matching
|
|
675
|
-
// moved since the approval (#4553: one made against another estate is a
|
|
676
|
-
// failure). One this run made itself is planned afresh by the next run.
|
|
677
|
-
if (applied.refused === "approval-mismatch" && isPlannedRoot(fromWave)) throw new TerraformPlanMovedError(input.root, message);
|
|
678
|
-
throw new Error(message);
|
|
679
|
-
}
|
|
680
|
-
const outputs = await terraformOutputs(rootArgs(input, ctx.processEnv));
|
|
681
|
-
return { root: input.root, planDigest: planned.planDigest, fromWavePlan: isPlannedRoot(fromWave), outputs };
|
|
682
|
-
},
|
|
683
|
-
};
|
|
821
|
+
return { root: input.root, planDigest: planned.planDigest, fromWavePlan: isPlannedRoot(fromWave), outputs };
|
|
822
|
+
},
|
|
823
|
+
};
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
/** `terraform-apply` with each root on the step's `binary`, else `terraform.binary`. */
|
|
827
|
+
export const terraformApplyCapability: Capability<TerraformApplyStepInput, TerraformApplyStepOutput> = terraformApplyCapabilityWith();
|
|
684
828
|
|
|
685
829
|
export const TERRAFORM_VERB_FAMILIES = {
|
|
686
830
|
apply: ["terraform-apply"],
|
|
@@ -103,7 +103,8 @@ interface ComposedArtifact {
|
|
|
103
103
|
/** What the group methods use, each replaceable in a test. */
|
|
104
104
|
export interface ComposeGroupDeps {
|
|
105
105
|
/** The project's config. Default: `loadChantConfigUpward` from the current directory. */
|
|
106
|
-
project
|
|
106
|
+
/** The project at the group's directory (`GroupContext.cwd`, chant#4854), else at `process.cwd()`. */
|
|
107
|
+
project?: (cwd?: string) => Promise<ComposeProject>;
|
|
107
108
|
/** The run for a composition. Default: `EstateRun` when `estate` is set, else `ComposedRun`. */
|
|
108
109
|
runner?: (o: GroupRunnerOptions) => ComposedRunner;
|
|
109
110
|
/**
|
|
@@ -128,8 +129,8 @@ export interface ComposeGroupMethods {
|
|
|
128
129
|
runGroup(ctx: GroupContext, run: GroupRun, members: readonly GroupMember<StepInput>[]): Promise<CapabilityGroupOutcome>;
|
|
129
130
|
}
|
|
130
131
|
|
|
131
|
-
async function loadProject(): Promise<ComposeProject> {
|
|
132
|
-
const start = resolve(process.cwd());
|
|
132
|
+
async function loadProject(cwd?: string): Promise<ComposeProject> {
|
|
133
|
+
const start = resolve(cwd ?? process.cwd());
|
|
133
134
|
const { config, configPath } = await loadChantConfigUpward(start);
|
|
134
135
|
const projectRoot = configPath ? dirname(configPath) : start;
|
|
135
136
|
const terraform = (config as { terraform?: TerraformConfig }).terraform;
|
|
@@ -369,7 +370,7 @@ export function composeGroup(deps: ComposeGroupDeps = {}): ComposeGroupMethods {
|
|
|
369
370
|
|
|
370
371
|
/** The composition the group plans as, or throws when it does not compose. */
|
|
371
372
|
async function composed(ctx: GroupContext, members: readonly GroupMember<StepInput>[]): Promise<{ p: ComposeProject; c: Composition }> {
|
|
372
|
-
const p = await project();
|
|
373
|
+
const p = await project(ctx.cwd);
|
|
373
374
|
const off = composeOff(p.terraform);
|
|
374
375
|
if (off) throw new Error(off.reason);
|
|
375
376
|
const c = await compositionOf(ctx, p, members);
|
|
@@ -403,14 +404,14 @@ export function composeGroup(deps: ComposeGroupDeps = {}): ComposeGroupMethods {
|
|
|
403
404
|
}
|
|
404
405
|
|
|
405
406
|
return {
|
|
406
|
-
async groupReads(
|
|
407
|
-
const p = await project();
|
|
407
|
+
async groupReads(ctx, members) {
|
|
408
|
+
const p = await project(ctx.cwd);
|
|
408
409
|
if (composeOff(p.terraform)) return [];
|
|
409
410
|
return hclGroupReads(p, members);
|
|
410
411
|
},
|
|
411
412
|
|
|
412
413
|
async groupFallback(ctx, members) {
|
|
413
|
-
const p = await project();
|
|
414
|
+
const p = await project(ctx.cwd);
|
|
414
415
|
const off = composeOff(p.terraform);
|
|
415
416
|
if (off) return { kind: off.kind, reason: off.reason };
|
|
416
417
|
const c = await compositionOf(ctx, p, members);
|