@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`).
|
|
@@ -142,7 +155,7 @@ export interface TerraformApplyStepInput {
|
|
|
142
155
|
root: string;
|
|
143
156
|
/** Input variables, after the root's var files. See `TerraformPlanArgs.vars`. */
|
|
144
157
|
vars?: Record<string, unknown>;
|
|
145
|
-
/** Where the `chant.config.*` search starts. Default: the current directory. */
|
|
158
|
+
/** 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. */
|
|
146
159
|
cwd?: string;
|
|
147
160
|
/** The root's files from here instead of its entry's `dir` (#4542): a promote under a release sets it to the recorded copy. */
|
|
148
161
|
dir?: string;
|
|
@@ -152,6 +165,46 @@ export interface TerraformApplyStepInput {
|
|
|
152
165
|
cone?: string;
|
|
153
166
|
/** Vars read from other roots' outputs (#4545), Atmos's `!terraform.state`. The step's `vars` win over them. */
|
|
154
167
|
reads?: TerraformStateRead[];
|
|
168
|
+
/**
|
|
169
|
+
* The workspace the root plans and applies in (chant#4854), such as an
|
|
170
|
+
* Atmos instance's. `init` runs in `default`, then `workspace select
|
|
171
|
+
* -or-create=true` selects it, creating it when the backend does not list
|
|
172
|
+
* it yet, and plan, apply and output run with `TF_WORKSPACE` set to it.
|
|
173
|
+
* Absent: the entry's `workspace`, or the run's environment, as before.
|
|
174
|
+
*/
|
|
175
|
+
workspace?: string;
|
|
176
|
+
/**
|
|
177
|
+
* The binary the root runs, a name on `PATH` or a path, in place of
|
|
178
|
+
* `terraform.binary` (terragucci issue 1303): a root that pins its own
|
|
179
|
+
* terraform or tofu release. A product's {@link TerraformRootResolver}
|
|
180
|
+
* sets it per root. Absent: `terraform.binary`, as before.
|
|
181
|
+
*/
|
|
182
|
+
binary?: string;
|
|
183
|
+
}
|
|
184
|
+
/** What a root runs in place of the step's (terragucci issue 1303). An unset field runs the step's. */
|
|
185
|
+
export interface TerraformRootTools {
|
|
186
|
+
/** The binary, a name on `PATH` or a path. See {@link TerraformApplyStepInput.binary}. */
|
|
187
|
+
binary?: string;
|
|
188
|
+
/**
|
|
189
|
+
* The environment a read of this root's state runs with over the job's,
|
|
190
|
+
* when another root's `reads` name it as their upstream (terragucci issue
|
|
191
|
+
* 1303): its role's credentials, never the reader's. The root's own plan
|
|
192
|
+
* and apply take theirs from the run hooks (`DeployContext.processEnv`).
|
|
193
|
+
*/
|
|
194
|
+
readEnv?: Record<string, string>;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* What a root runs (terragucci issue 1303), asked once per plan and per
|
|
198
|
+
* apply with the root and the step's input, as `terragrunt-apply`'s
|
|
199
|
+
* `resolveUnit` is asked per unit. A product passes its own, which installs
|
|
200
|
+
* a pinned release and checks its version, so a root runs what it plans
|
|
201
|
+
* with whatever `chant.config.ts` names.
|
|
202
|
+
*/
|
|
203
|
+
export type TerraformRootResolver = (root: string, input: TerraformApplyStepInput) => TerraformRootTools | Promise<TerraformRootTools>;
|
|
204
|
+
/** What {@link terraformApplyCapabilityWith} takes. */
|
|
205
|
+
export interface TerraformApplyDeps {
|
|
206
|
+
/** What each root runs. Default: the step's `binary`, else `terraform.binary`. */
|
|
207
|
+
resolveRoot?: TerraformRootResolver;
|
|
155
208
|
}
|
|
156
209
|
/** What `terraform-apply` returns. `outputs` is what a dependent's `stackOutput()` reads. */
|
|
157
210
|
export interface TerraformApplyStepOutput {
|
|
@@ -193,6 +246,17 @@ export declare const PREVIEW_PLAN_FILE = ".chant-preview.tfplan";
|
|
|
193
246
|
export interface TerraformShapeArtifact extends PlanShapeArtifact {
|
|
194
247
|
kind: "terraform-apply-shape";
|
|
195
248
|
}
|
|
249
|
+
/**
|
|
250
|
+
* The step's input with `cwd` set to the caller's directory when it names
|
|
251
|
+
* none (chant#4854, `DeployContext.cwd`): an op wave run in process for
|
|
252
|
+
* another directory finds that directory's `chant.config.*`, not the
|
|
253
|
+
* process's. The input core passed is remembered, so `defaultLockGrain`,
|
|
254
|
+
* `lockGrainRefusal` and `traceFacts`, which get the input alone, read the
|
|
255
|
+
* same config.
|
|
256
|
+
*/
|
|
257
|
+
export declare function withContextCwd(ctx: {
|
|
258
|
+
cwd?: string;
|
|
259
|
+
} | undefined, input: TerraformApplyStepInput): TerraformApplyStepInput;
|
|
196
260
|
/**
|
|
197
261
|
* choudoufu refused the plan `run` was handed by its wave (its exit 3)
|
|
198
262
|
* because the live system moved since the plan. Nothing was applied.
|
|
@@ -206,6 +270,15 @@ export declare class TerraformPlanMovedError extends Error {
|
|
|
206
270
|
readonly planMoved = true;
|
|
207
271
|
constructor(root: string, message: string);
|
|
208
272
|
}
|
|
273
|
+
/**
|
|
274
|
+
* `terraform-apply` with `deps` in place of the defaults (terragucci issue
|
|
275
|
+
* 1303). `resolveRoot` answers what each root runs, so a product whose roots
|
|
276
|
+
* pin their own releases passes its resolver, as it passes `resolveUnit` to
|
|
277
|
+
* `terragruntApplyCapability`. A composed group (`together`) runs the
|
|
278
|
+
* project's binary, as before.
|
|
279
|
+
*/
|
|
280
|
+
export declare function terraformApplyCapabilityWith(deps?: TerraformApplyDeps): Capability<TerraformApplyStepInput, TerraformApplyStepOutput>;
|
|
281
|
+
/** `terraform-apply` with each root on the step's `binary`, else `terraform.binary`. */
|
|
209
282
|
export declare const terraformApplyCapability: Capability<TerraformApplyStepInput, TerraformApplyStepOutput>;
|
|
210
283
|
export declare const TERRAFORM_VERB_FAMILIES: {
|
|
211
284
|
readonly apply: readonly ["terraform-apply"];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capability-plugin.d.ts","sourceRoot":"","sources":["../../src/components/capability-plugin.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"capability-plugin.d.ts","sourceRoot":"","sources":["../../src/components/capability-plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiJG;AAIH,OAAO,KAAK,EAAE,UAAU,EAAiC,cAAc,EAAE,MAAM,wCAAwC,CAAC;AAExH,OAAO,EAIL,KAAK,iBAAiB,EACvB,MAAM,2CAA2C,CAAC;AAInD,OAAO,EAAqB,KAAK,gBAAgB,EAAE,MAAM,+CAA+C,CAAC;AACzG,OAAO,KAAK,EAAmB,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,kDAAkD,CAAC;AA0BlI,OAAO,EAA0D,KA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B,EAAE,gBAoBvC,CAAC"}
|
|
@@ -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`).
|
|
@@ -156,6 +169,7 @@ import { fillStateReads, stateReadsProblems, waitingReadsReason } from "../state
|
|
|
156
169
|
import { terraformStateOpCapabilities } from "../state-ops.js";
|
|
157
170
|
import { terraformActionCapability } from "../action-ops.js";
|
|
158
171
|
import { terragruntApply } from "../terragrunt/capability.js";
|
|
172
|
+
import { inInitTurn, pluginCacheDir } from "../init-turn.js";
|
|
159
173
|
/** The lock timeout a step's plan and apply pass (#4545). */
|
|
160
174
|
function lockTimeoutOf(input) {
|
|
161
175
|
if (input.lockTimeout === false)
|
|
@@ -170,16 +184,26 @@ function lockTimeoutOf(input) {
|
|
|
170
184
|
* read once, the values under the step's own `vars`. `waiting` when an
|
|
171
185
|
* upstream has no such output yet. Throws when a state cannot be read.
|
|
172
186
|
*/
|
|
173
|
-
async function withReads(input) {
|
|
187
|
+
async function withReads(input, resolveRoot, serial) {
|
|
174
188
|
const reads = input.reads ?? [];
|
|
175
189
|
if (reads.length === 0)
|
|
176
190
|
return { input };
|
|
177
191
|
const problems = stateReadsProblems(reads);
|
|
178
192
|
if (problems.length > 0)
|
|
179
193
|
throw new Error(`terraform-apply: root "${input.root}": ${problems.join("; ")}`);
|
|
180
|
-
const filled = await fillStateReads(reads, async (root) => {
|
|
181
|
-
|
|
182
|
-
await
|
|
194
|
+
const filled = await fillStateReads(reads, async (root, read) => {
|
|
195
|
+
// terragucci issue 1303: the upstream's own directory, workspace, binary and environment, as terragucci's upstreamOutputs reads it.
|
|
196
|
+
const tools = resolveRoot ? await resolveRoot(root, { root, ...(input.cwd ? { cwd: input.cwd } : {}), ...(read.dir ? { dir: read.dir } : {}), ...(read.workspace ? { workspace: read.workspace } : {}) }) : undefined;
|
|
197
|
+
const at = {
|
|
198
|
+
root,
|
|
199
|
+
...(input.cwd ? { cwd: input.cwd } : {}),
|
|
200
|
+
...(read.dir ? { dir: read.dir } : {}),
|
|
201
|
+
...(read.workspace ? { workspace: read.workspace } : {}),
|
|
202
|
+
...(tools?.binary ? { binary: tools.binary } : {}),
|
|
203
|
+
...(tools?.readEnv ? { env: tools.readEnv } : {}),
|
|
204
|
+
};
|
|
205
|
+
// chant#4864: runs that plan at once may read the same upstream, so its init takes a turn.
|
|
206
|
+
await inInitTurn(serial, at.env, initDir(at), () => terraformInit(at));
|
|
183
207
|
return terraformOutputs(at);
|
|
184
208
|
});
|
|
185
209
|
if (filled.errors.length > 0)
|
|
@@ -197,15 +221,32 @@ function waitingOnReads(ctx, input, waiting) {
|
|
|
197
221
|
};
|
|
198
222
|
return { member: input.root, planDigest, changeSet };
|
|
199
223
|
}
|
|
200
|
-
const rootArgs = (input, env) => ({
|
|
224
|
+
const rootArgs = (input, env) => ({
|
|
225
|
+
root: input.root,
|
|
226
|
+
...(input.cwd ? { cwd: input.cwd } : {}),
|
|
227
|
+
...(input.dir ? { dir: input.dir } : {}),
|
|
228
|
+
...(env ? { env } : {}),
|
|
229
|
+
...(input.workspace ? { workspace: input.workspace } : {}),
|
|
230
|
+
...(input.binary ? { binary: input.binary } : {}),
|
|
231
|
+
});
|
|
232
|
+
/** 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). */
|
|
233
|
+
const initDir = (at) => join(at.cwd ?? process.cwd(), at.dir ?? at.root);
|
|
234
|
+
/** `terraform init` of `input`'s root in its turn (chant#4864). */
|
|
235
|
+
const initRoot = (input, env, serial) => inInitTurn(serial, env, initDir(rootArgs(input, env)), () => terraformInit(rootArgs(input, env)));
|
|
201
236
|
function requireRoot(input) {
|
|
202
237
|
if (typeof input.root !== "string" || input.root === "") {
|
|
203
238
|
throw new Error('terraform-apply: "root" is required and names an entry in terraform.roots');
|
|
204
239
|
}
|
|
240
|
+
if (input.workspace !== undefined && (typeof input.workspace !== "string" || input.workspace.trim() === "")) {
|
|
241
|
+
throw new Error(`terraform-apply: root "${input.root}": workspace must name a workspace`);
|
|
242
|
+
}
|
|
243
|
+
if (input.binary !== undefined && (typeof input.binary !== "string" || input.binary.trim() === "")) {
|
|
244
|
+
throw new Error(`terraform-apply: root "${input.root}": binary must name a binary or its path`);
|
|
245
|
+
}
|
|
205
246
|
}
|
|
206
247
|
async function planRoot(input, targets, at = {}) {
|
|
207
248
|
requireRoot(input);
|
|
208
|
-
await
|
|
249
|
+
await initRoot(input, at.env, at.serial);
|
|
209
250
|
// chant#4842: the run hook's check, once init fetched the modules and providers and before the plan runs their code.
|
|
210
251
|
await at.afterInit?.();
|
|
211
252
|
// One `show -json` per plan (#4479): its document is the digest, the change
|
|
@@ -327,8 +368,41 @@ function isShapeArtifact(value) {
|
|
|
327
368
|
const v = value;
|
|
328
369
|
return v?.kind === "terraform-apply-shape" && typeof v.digest === "string" && typeof v.shape === "object" && v.shape !== null;
|
|
329
370
|
}
|
|
371
|
+
/** Each step input core passed, as it was filled (chant#4854, terragucci issue 1303), for the methods core calls with the input alone. */
|
|
372
|
+
const filledInputs = new WeakMap();
|
|
373
|
+
/**
|
|
374
|
+
* The step's input with `cwd` set to the caller's directory when it names
|
|
375
|
+
* none (chant#4854, `DeployContext.cwd`): an op wave run in process for
|
|
376
|
+
* another directory finds that directory's `chant.config.*`, not the
|
|
377
|
+
* process's. The input core passed is remembered, so `defaultLockGrain`,
|
|
378
|
+
* `lockGrainRefusal` and `traceFacts`, which get the input alone, read the
|
|
379
|
+
* same config.
|
|
380
|
+
*/
|
|
381
|
+
export function withContextCwd(ctx, input) {
|
|
382
|
+
if (!input || typeof input !== "object" || input.cwd !== undefined || ctx?.cwd === undefined)
|
|
383
|
+
return input;
|
|
384
|
+
const filled = { ...input, cwd: ctx.cwd };
|
|
385
|
+
filledInputs.set(input, { ...filledInputs.get(input), ...filled });
|
|
386
|
+
return filled;
|
|
387
|
+
}
|
|
388
|
+
/** 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. */
|
|
389
|
+
async function filledInput(resolveRoot, ctx, input) {
|
|
390
|
+
const at = withContextCwd(ctx, input);
|
|
391
|
+
if (!resolveRoot || !at || typeof at !== "object" || typeof at.root !== "string" || at.root === "")
|
|
392
|
+
return at;
|
|
393
|
+
const tools = await resolveRoot(at.root, at);
|
|
394
|
+
if (tools?.binary !== undefined && (typeof tools.binary !== "string" || tools.binary.trim() === "")) {
|
|
395
|
+
throw new Error(`terraform-apply: root "${at.root}": the product's resolveRoot answered a binary that names nothing`);
|
|
396
|
+
}
|
|
397
|
+
if (!tools?.binary)
|
|
398
|
+
return at;
|
|
399
|
+
const filled = { ...at, binary: tools.binary };
|
|
400
|
+
filledInputs.set(input, filled);
|
|
401
|
+
return filled;
|
|
402
|
+
}
|
|
330
403
|
/** The root's directory, as `terraform.roots` names it from the nearest `chant.config.*`, and the configured binary. */
|
|
331
|
-
async function rootDir(
|
|
404
|
+
async function rootDir(given) {
|
|
405
|
+
const input = filledInputs.get(given) ?? given;
|
|
332
406
|
const start = resolve(input.cwd ?? process.cwd());
|
|
333
407
|
const { config, configPath } = await loadChantConfigUpward(start);
|
|
334
408
|
const terraform = config.terraform;
|
|
@@ -337,7 +411,8 @@ async function rootDir(input) {
|
|
|
337
411
|
if (declared === undefined)
|
|
338
412
|
return undefined;
|
|
339
413
|
const dir = input.dir ?? declared;
|
|
340
|
-
|
|
414
|
+
const binary = input.binary ?? terraform?.binary;
|
|
415
|
+
return { dir: resolve(configPath ? dirname(configPath) : start, dir), ...(binary ? { binary } : {}) };
|
|
341
416
|
}
|
|
342
417
|
const firstLines = (err) => {
|
|
343
418
|
const text = (err instanceof Error ? err.message : String(err)).trim();
|
|
@@ -362,7 +437,7 @@ async function previewRoot(ctx, input, unresolved, targets) {
|
|
|
362
437
|
return waitingRoot(ctx, input, unresolved, stand);
|
|
363
438
|
let planned;
|
|
364
439
|
try {
|
|
365
|
-
await
|
|
440
|
+
await initRoot(input, ctx.processEnv, ctx.serial);
|
|
366
441
|
await ctx.afterInit?.();
|
|
367
442
|
planned = await terraformPlan({
|
|
368
443
|
...rootArgs(input, ctx.processEnv),
|
|
@@ -457,8 +532,8 @@ async function runChoudoufuWave(ctx, input, planned) {
|
|
|
457
532
|
return { root: input.root, planDigest: planned.planDigest, fromWavePlan: true, outputs };
|
|
458
533
|
}
|
|
459
534
|
/** The input a `run` that plans for itself plans with (#4545): its reads filled, or an error naming the upstream to apply first. */
|
|
460
|
-
async function readsForRun(input) {
|
|
461
|
-
const read = await withReads(input);
|
|
535
|
+
async function readsForRun(input, resolveRoot, serial) {
|
|
536
|
+
const read = await withReads(input, resolveRoot, serial);
|
|
462
537
|
if ("waiting" in read)
|
|
463
538
|
throw new Error(`terraform-apply: root "${input.root}": ${read.waiting}`);
|
|
464
539
|
return read.input;
|
|
@@ -471,137 +546,163 @@ async function plannerOf(input, plan) {
|
|
|
471
546
|
const planner = plan?.changeSet?.member.planner;
|
|
472
547
|
return planner === "terraform" || planner === "tofu" || planner === "choudoufu" ? planner : "terraform";
|
|
473
548
|
}
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
//
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
const
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
549
|
+
/**
|
|
550
|
+
* `terraform-apply` with `deps` in place of the defaults (terragucci issue
|
|
551
|
+
* 1303). `resolveRoot` answers what each root runs, so a product whose roots
|
|
552
|
+
* pin their own releases passes its resolver, as it passes `resolveUnit` to
|
|
553
|
+
* `terragruntApplyCapability`. A composed group (`together`) runs the
|
|
554
|
+
* project's binary, as before.
|
|
555
|
+
*/
|
|
556
|
+
export function terraformApplyCapabilityWith(deps = {}) {
|
|
557
|
+
return {
|
|
558
|
+
kind: "terraform-apply",
|
|
559
|
+
// A root's apply has no undo short of applying the previous configuration,
|
|
560
|
+
// which is a change of its own. COMP003 asks the component to say so.
|
|
561
|
+
rollbackPolicy: "needs-opt-out",
|
|
562
|
+
// #4300: `--target` passes through as `-target`, and the saved plan holds those addresses alone.
|
|
563
|
+
targets: "accept",
|
|
564
|
+
// #4627: `plan` refreshes the root's state before it plans unless told `-refresh=false`, which chant never passes,
|
|
565
|
+
// so `--refresh` asks for what every plan does and the digest still binds it. `-target` plans a resource with what it
|
|
566
|
+
// depends on and never what depends on it, so `--target-dependents` has nothing to map onto.
|
|
567
|
+
planFlags: {
|
|
568
|
+
refresh: "accept",
|
|
569
|
+
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" },
|
|
570
|
+
},
|
|
571
|
+
async plan(ctx, step) {
|
|
572
|
+
const given = await filledInput(deps.resolveRoot, ctx, step);
|
|
573
|
+
requireRoot(given);
|
|
574
|
+
// #4545: a root reading an upstream's output that is not there yet is a hole naming the upstream.
|
|
575
|
+
const read = await withReads(given, deps.resolveRoot, ctx.serial);
|
|
576
|
+
if ("waiting" in read)
|
|
577
|
+
return waitingOnReads(ctx, given, read);
|
|
578
|
+
const { input } = read;
|
|
579
|
+
const unresolved = [...(ctx.unresolvedInputs ?? [])].sort();
|
|
580
|
+
const targets = ctx.targets && ctx.targets.length > 0 ? ctx.targets : undefined;
|
|
581
|
+
if (unresolved.length > 0)
|
|
582
|
+
return previewRoot(ctx, input, unresolved, targets);
|
|
583
|
+
// A targeted root plans with `plan -target`, and a cone plan with `plan -cone` (#4545), never as a choudoufu one-root set.
|
|
584
|
+
const env = ctx.processEnv;
|
|
585
|
+
const wave = targets || input.cone ? { wave: false } : await choudoufuWaveRoot({ ...rootArgs(input, env), ...(input.vars ? { vars: input.vars } : {}) });
|
|
586
|
+
if (wave.wave) {
|
|
587
|
+
// chant#4842: live-plan-set inits and plans in one command, so the run hook's check comes before it.
|
|
588
|
+
await ctx.afterInit?.();
|
|
589
|
+
// chant#4864: live-plan-set inits too, so with a shared provider cache the whole command takes the init's turn.
|
|
590
|
+
const set = await inInitTurn(pluginCacheDir(env) ? ctx.serial : undefined, env, undefined, () => choudoufuPlanSet(rootArgs(input, env)));
|
|
591
|
+
const artifact = {
|
|
592
|
+
planDigest: set.planDigest,
|
|
593
|
+
choudoufu: { planSetFile: set.planSetFile, setDigest: set.setDigest },
|
|
594
|
+
lockRows: terraformLockRows(input.root, set.changeSet.member.scope, set.json),
|
|
595
|
+
};
|
|
596
|
+
return { member: input.root, planDigest: set.planDigest, artifact, changeSet: set.changeSet, outputs: terraformPlannedOutputs(set.json), shape: terraformPlanShape(set.json, input.root) };
|
|
597
|
+
}
|
|
598
|
+
const { changeSet, json, ...planned } = await planRoot(input, targets, { env, ...(ctx.afterInit ? { afterInit: ctx.afterInit } : {}), ...(ctx.serial ? { serial: ctx.serial } : {}) });
|
|
599
|
+
// #4552: a choudoufu root's rows, keyed from the plan document while it is at hand.
|
|
600
|
+
const lockRows = changeSet?.member.planner === "choudoufu" ? terraformLockRows(input.root, changeSet.member.scope, json) : undefined;
|
|
601
|
+
return {
|
|
602
|
+
member: input.root,
|
|
603
|
+
planDigest: planned.planDigest,
|
|
604
|
+
artifact: { ...planned, ...(lockRows ? { lockRows } : {}) },
|
|
605
|
+
...(changeSet ? { changeSet } : {}),
|
|
606
|
+
// plywood#55: each changed resource's own digest, which a merged wave compares with the pull request's per resource.
|
|
607
|
+
resourceDigests: terraformResourceDigests(json),
|
|
608
|
+
outputs: terraformPlannedOutputs(json),
|
|
609
|
+
shape: terraformPlanShape(json, input.root),
|
|
610
|
+
...(targets ? { targets } : {}),
|
|
510
611
|
};
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
612
|
+
},
|
|
613
|
+
// The root's outputs as its state holds them now (#3183): what a dependent
|
|
614
|
+
// planned before this root applies reads through `stackOutput()`.
|
|
615
|
+
async outputs(ctx, step) {
|
|
616
|
+
const input = await filledInput(deps.resolveRoot, ctx, step);
|
|
617
|
+
requireRoot(input);
|
|
618
|
+
await initRoot(input, ctx.processEnv, ctx.serial);
|
|
619
|
+
return terraformOutputs(rootArgs(input, ctx.processEnv));
|
|
620
|
+
},
|
|
621
|
+
// #4447 (ws-107): a group core forms of components that read each other plans and applies as one composed run
|
|
622
|
+
// when `terraform.compose.enabled` is set (./compose-group.ts). Delegates, so the methods are read when called.
|
|
623
|
+
groupReads: (ctx, members) => terraformComposeGroup.groupReads(ctx, members),
|
|
624
|
+
// #4542: a member pointed at a release's recorded copy plans alone, since a composition reads the declared roots.
|
|
625
|
+
groupFallback: async (ctx, members) => members.some((m) => typeof m.step.dir === "string")
|
|
626
|
+
? { kind: "release-copy", reason: "a member deploys a release's recorded copy of its root, which a composition does not read" }
|
|
627
|
+
: terraformComposeGroup.groupFallback(ctx, members),
|
|
628
|
+
// #4542: the root's files, which a release cut records and a promote under it plans.
|
|
629
|
+
releaseInputs: (input, ctx) => terraformReleaseInputs(input, ctx),
|
|
630
|
+
// #4552: resource under choudoufu, the root under Terraform, tofu and Terragrunt, which refuse resource by name.
|
|
631
|
+
async defaultLockGrain(input, plan) {
|
|
632
|
+
return terraformDefaultLockGrain(await plannerOf(input, plan));
|
|
633
|
+
},
|
|
634
|
+
async lockGrainRefusal(input, grain, plan) {
|
|
635
|
+
if (grain !== "resource")
|
|
636
|
+
return undefined;
|
|
637
|
+
const binary = (await rootDir(input).catch(() => undefined))?.binary;
|
|
638
|
+
return terraformLockGrainRefusal(grain, await plannerOf(input, plan), binary);
|
|
639
|
+
},
|
|
640
|
+
// 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
|
|
641
|
+
// the backend's lock. A choudoufu root stays on the resource grain and never asks for this row.
|
|
642
|
+
targetLockRow(input) {
|
|
643
|
+
return typeof input?.root === "string" && input.root !== "" ? { key: rootRowKey(input.root), target: input.root, address: input.root } : undefined;
|
|
644
|
+
},
|
|
645
|
+
lockRows(input, plan) {
|
|
646
|
+
const kept = plan.artifact?.lockRows;
|
|
647
|
+
if (Array.isArray(kept))
|
|
648
|
+
return kept;
|
|
649
|
+
return plan.changeSet ? terraformLockRowsFromPart(input.root, plan.changeSet) : [];
|
|
650
|
+
},
|
|
651
|
+
// #4555: the root and the binary, for the step's span and run record.
|
|
652
|
+
traceFacts: async (input, outcome) => terraformTraceFacts(input, outcome, (await rootDir(input).catch(() => undefined))?.binary),
|
|
653
|
+
planGroup: (ctx, members) => {
|
|
654
|
+
// chant#4854: each member's lock grain reads the config at the wave's directory too.
|
|
655
|
+
for (const m of members)
|
|
656
|
+
if (m.input)
|
|
657
|
+
withContextCwd(m.ctx ?? ctx, m.input);
|
|
658
|
+
return terraformComposeGroup.planGroup(ctx, members);
|
|
659
|
+
},
|
|
660
|
+
runGroup: (ctx, run, members) => {
|
|
661
|
+
for (const m of members)
|
|
662
|
+
if (m.input)
|
|
663
|
+
withContextCwd(m.ctx ?? ctx, m.input);
|
|
664
|
+
return terraformComposeGroup.runGroup(ctx, run, members);
|
|
665
|
+
},
|
|
666
|
+
async run(ctx, step) {
|
|
667
|
+
const input = await filledInput(deps.resolveRoot, ctx, step);
|
|
668
|
+
const fromWave = ctx.plans?.[input.root];
|
|
669
|
+
if (isChoudoufuWavePlan(fromWave))
|
|
670
|
+
return runChoudoufuWave(ctx, input, fromWave);
|
|
671
|
+
if (isShapeArtifact(fromWave)) {
|
|
672
|
+
// A root previewed with stand-ins (#4463): plan it now with the real
|
|
673
|
+
// values, and apply that plan only when it is within the preview's shape.
|
|
674
|
+
const fresh = await planRoot(await readsForRun(input, deps.resolveRoot, ctx.serial), ctx.targets, { env: ctx.processEnv, ...(ctx.serial ? { serial: ctx.serial } : {}) });
|
|
675
|
+
const differences = planShapeDifferences(fromWave.shape, terraformPlanShape(fresh.json, input.root));
|
|
676
|
+
if (differences.length > 0)
|
|
677
|
+
throw new PlanShapeMovedError(input.root, differences);
|
|
678
|
+
const applied = await terraformApply({ ...rootArgs(input, ctx.processEnv), planFile: fresh.planFile, ...lockTimeoutOf(input) });
|
|
679
|
+
if (!applied.applied) {
|
|
680
|
+
throw new Error(`terraform-apply: root "${input.root}" refused the plan it was given (${applied.refused ?? "refused"}). ${applied.refusal ?? ""}`);
|
|
681
|
+
}
|
|
682
|
+
const outputs = await terraformOutputs(rootArgs(input, ctx.processEnv));
|
|
683
|
+
return { root: input.root, planDigest: fresh.planDigest, fromWavePlan: false, outputs };
|
|
684
|
+
}
|
|
685
|
+
const planned = isPlannedRoot(fromWave)
|
|
686
|
+
? fromWave
|
|
687
|
+
: await planRoot(await readsForRun(input, deps.resolveRoot, ctx.serial), ctx.targets, { env: ctx.processEnv, ...(ctx.serial ? { serial: ctx.serial } : {}) }).then(({ planFile, planDigest }) => ({ planFile, planDigest }));
|
|
688
|
+
const applied = await terraformApply({ ...rootArgs(input, ctx.processEnv), planFile: planned.planFile, ...lockTimeoutOf(input) });
|
|
581
689
|
if (!applied.applied) {
|
|
582
|
-
|
|
690
|
+
const message = `terraform-apply: root "${input.root}" refused the plan it was given (${applied.refused ?? "refused"}). ` +
|
|
691
|
+
(applied.refusal ?? "");
|
|
692
|
+
// A plan the wave approved that choudoufu refuses as no longer matching
|
|
693
|
+
// moved since the approval (#4553: one made against another estate is a
|
|
694
|
+
// failure). One this run made itself is planned afresh by the next run.
|
|
695
|
+
if (applied.refused === "approval-mismatch" && isPlannedRoot(fromWave))
|
|
696
|
+
throw new TerraformPlanMovedError(input.root, message);
|
|
697
|
+
throw new Error(message);
|
|
583
698
|
}
|
|
584
699
|
const outputs = await terraformOutputs(rootArgs(input, ctx.processEnv));
|
|
585
|
-
return { root: input.root, planDigest:
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
if (!applied.applied) {
|
|
592
|
-
const message = `terraform-apply: root "${input.root}" refused the plan it was given (${applied.refused ?? "refused"}). ` +
|
|
593
|
-
(applied.refusal ?? "");
|
|
594
|
-
// A plan the wave approved that choudoufu refuses as no longer matching
|
|
595
|
-
// moved since the approval (#4553: one made against another estate is a
|
|
596
|
-
// failure). One this run made itself is planned afresh by the next run.
|
|
597
|
-
if (applied.refused === "approval-mismatch" && isPlannedRoot(fromWave))
|
|
598
|
-
throw new TerraformPlanMovedError(input.root, message);
|
|
599
|
-
throw new Error(message);
|
|
600
|
-
}
|
|
601
|
-
const outputs = await terraformOutputs(rootArgs(input, ctx.processEnv));
|
|
602
|
-
return { root: input.root, planDigest: planned.planDigest, fromWavePlan: isPlannedRoot(fromWave), outputs };
|
|
603
|
-
},
|
|
604
|
-
};
|
|
700
|
+
return { root: input.root, planDigest: planned.planDigest, fromWavePlan: isPlannedRoot(fromWave), outputs };
|
|
701
|
+
},
|
|
702
|
+
};
|
|
703
|
+
}
|
|
704
|
+
/** `terraform-apply` with each root on the step's `binary`, else `terraform.binary`. */
|
|
705
|
+
export const terraformApplyCapability = terraformApplyCapabilityWith();
|
|
605
706
|
export const TERRAFORM_VERB_FAMILIES = {
|
|
606
707
|
apply: ["terraform-apply"],
|
|
607
708
|
// #4618: the binary runs outside waves, each a fixed operation; the two that change state on their own run under a gated request.
|
|
@@ -70,7 +70,8 @@ export interface GroupRunnerOptions extends ComposeProject {
|
|
|
70
70
|
/** What the group methods use, each replaceable in a test. */
|
|
71
71
|
export interface ComposeGroupDeps {
|
|
72
72
|
/** The project's config. Default: `loadChantConfigUpward` from the current directory. */
|
|
73
|
-
project
|
|
73
|
+
/** The project at the group's directory (`GroupContext.cwd`, chant#4854), else at `process.cwd()`. */
|
|
74
|
+
project?: (cwd?: string) => Promise<ComposeProject>;
|
|
74
75
|
/** The run for a composition. Default: `EstateRun` when `estate` is set, else `ComposedRun`. */
|
|
75
76
|
runner?: (o: GroupRunnerOptions) => ComposedRunner;
|
|
76
77
|
/**
|