@intentius/chant-lexicon-terraform 0.124.77 → 0.124.79
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/change-set.d.ts +1 -0
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +19 -0
- package/dist/components/capability-plugin.d.ts +9 -1
- package/dist/components/capability-plugin.d.ts.map +1 -1
- package/dist/components/capability-plugin.js +44 -22
- package/dist/drift-record.d.ts +24 -0
- package/dist/drift-record.d.ts.map +1 -1
- package/dist/drift-record.js +52 -0
- package/dist/drift-rows.d.ts +49 -4
- package/dist/drift-rows.d.ts.map +1 -1
- package/dist/drift-rows.js +87 -19
- package/dist/integrity.json +2 -2
- package/dist/manifest.json +1 -1
- package/dist/op/activities/terraform.d.ts +11 -0
- package/dist/op/activities/terraform.d.ts.map +1 -1
- package/dist/op/activities/terraform.js +9 -1
- package/dist/terragrunt/capability.d.ts +129 -0
- package/dist/terragrunt/capability.d.ts.map +1 -0
- package/dist/terragrunt/capability.js +347 -0
- package/dist/terragrunt/index.d.ts +3 -1
- package/dist/terragrunt/index.d.ts.map +1 -1
- package/dist/terragrunt/index.js +3 -1
- package/dist/terragrunt/units.d.ts +9 -0
- package/dist/terragrunt/units.d.ts.map +1 -1
- package/dist/terragrunt/units.js +25 -0
- package/package.json +2 -2
- package/src/__fixtures__/drift-rows/refresh-plan-module.json +48 -0
- package/src/change-set.test.ts +27 -1
- package/src/change-set.ts +19 -0
- package/src/components/capability-plugin.test.ts +61 -6
- package/src/components/capability-plugin.ts +48 -23
- package/src/components/compose-op-wave.test.ts +134 -0
- package/src/drift-record.test.ts +62 -0
- package/src/drift-record.ts +58 -0
- package/src/drift-rows.test.ts +90 -1
- package/src/drift-rows.ts +89 -18
- package/src/op/activities/terraform.test.ts +21 -0
- package/src/op/activities/terraform.ts +20 -1
- package/src/terragrunt/capability.test.ts +327 -0
- package/src/terragrunt/capability.ts +431 -0
- package/src/terragrunt/index.ts +3 -1
- package/src/terragrunt/units.ts +25 -0
package/dist/change-set.d.ts
CHANGED
|
@@ -47,6 +47,7 @@ export interface TerraformChangeSetPartInput {
|
|
|
47
47
|
* One terraform-family root's part, from its `show -json` plan.
|
|
48
48
|
*
|
|
49
49
|
* Every `resource_changes` entry becomes an entry, no-op and read included.
|
|
50
|
+
* The outputs `output_changes` changes are the member's `outputs`.
|
|
50
51
|
* A plan stock marked `errored` is a failed member: its entries are kept,
|
|
51
52
|
* but nothing should apply it.
|
|
52
53
|
*/
|
package/dist/change-set.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"change-set.d.ts","sourceRoot":"","sources":["../src/change-set.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EACV,eAAe,EAIf,aAAa,EACb,gBAAgB,EAEjB,MAAM,6BAA6B,CAAC;AAyBrC;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,gBAAgB,CAK7E;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,OAAO,GAAG,eAAe,CAU3D;AAWD,iHAAiH;AACjH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CAQ/H;AA2CD,MAAM,WAAW,2BAA2B;IAC1C,+HAA+H;IAC/H,MAAM,EAAE,MAAM,CAAC;IACf,iDAAiD;IACjD,IAAI,EAAE,OAAO,CAAC;IACd,+EAA+E;IAC/E,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAC3B,mDAAmD;IACnD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,kEAAkE;IAClE,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB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E,CAwBnF"}
|
package/dist/change-set.js
CHANGED
|
@@ -132,6 +132,7 @@ function regionOf(change) {
|
|
|
132
132
|
* One terraform-family root's part, from its `show -json` plan.
|
|
133
133
|
*
|
|
134
134
|
* Every `resource_changes` entry becomes an entry, no-op and read included.
|
|
135
|
+
* The outputs `output_changes` changes are the member's `outputs`.
|
|
135
136
|
* A plan stock marked `errored` is a failed member: its entries are kept,
|
|
136
137
|
* but nothing should apply it.
|
|
137
138
|
*/
|
|
@@ -169,6 +170,7 @@ export function terraformChangeSetPart(input) {
|
|
|
169
170
|
});
|
|
170
171
|
const sideEffects = (Array.isArray(plan.action_invocations) ? plan.action_invocations : []).map(sideEffectFor);
|
|
171
172
|
const errored = plan.errored === true;
|
|
173
|
+
const outputs = changedOutputs(plan.output_changes);
|
|
172
174
|
return {
|
|
173
175
|
member: {
|
|
174
176
|
member: input.member,
|
|
@@ -179,12 +181,29 @@ export function terraformChangeSetPart(input) {
|
|
|
179
181
|
...(errored ? { error: `${planner} marked the plan errored` } : {}),
|
|
180
182
|
planDigest: terraformPlanDigest(plan),
|
|
181
183
|
...(input.nativeDigest ? { nativeDigest: input.nativeDigest } : {}),
|
|
184
|
+
...(outputs.length > 0 ? { outputs } : {}),
|
|
182
185
|
holes: [],
|
|
183
186
|
},
|
|
184
187
|
entries,
|
|
185
188
|
...(sideEffects.length > 0 ? { sideEffects } : {}),
|
|
186
189
|
};
|
|
187
190
|
}
|
|
191
|
+
/**
|
|
192
|
+
* The outputs a plan's `output_changes` changes, sorted (#4849): each whose
|
|
193
|
+
* actions are anything but `no-op`. A plan that changes only outputs is a
|
|
194
|
+
* change, as terragucci counts it.
|
|
195
|
+
*/
|
|
196
|
+
function changedOutputs(raw) {
|
|
197
|
+
if (!isObject(raw))
|
|
198
|
+
return [];
|
|
199
|
+
return Object.entries(raw)
|
|
200
|
+
.filter(([, change]) => {
|
|
201
|
+
const actions = isObject(change) && Array.isArray(change.actions) ? change.actions : [];
|
|
202
|
+
return actions.some((a) => a !== "no-op");
|
|
203
|
+
})
|
|
204
|
+
.map(([name]) => name)
|
|
205
|
+
.sort();
|
|
206
|
+
}
|
|
188
207
|
/**
|
|
189
208
|
* One `action_invocations` entry of a plan (Terraform 1.14): the action's
|
|
190
209
|
* address and type, and, for a lifecycle trigger, the resource and event.
|
|
@@ -119,6 +119,14 @@
|
|
|
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
|
+
* A wave's run hooks in the product's process (chant#4842) reach the step
|
|
123
|
+
* through its context. `processEnv` goes to every command for the root (a
|
|
124
|
+
* role's credentials, values from a secret store), and `afterInit` is
|
|
125
|
+
* called after `init` and before `plan`, or before `live-plan-set`, which
|
|
126
|
+
* inits and plans in one command. A `root` with no `terraform.roots` entry
|
|
127
|
+
* plans the step's `dir` as its directory, so a product can name each root
|
|
128
|
+
* by its path without writing an entry for it.
|
|
129
|
+
*
|
|
122
130
|
* Every plan also writes its `show -json` beside the plan file and names it
|
|
123
131
|
* as `artifact.planJson`, the document a wave's cost hold prices
|
|
124
132
|
* (`../cost-hold.ts`).
|
|
@@ -130,7 +138,7 @@ import type { EngineOutputSource, EnginePlannedOutputs } from "@intentius/chant/
|
|
|
130
138
|
import { type TerraformStateRead } from "../state-reads.js";
|
|
131
139
|
/** The `terraform-apply` step's input. */
|
|
132
140
|
export interface TerraformApplyStepInput {
|
|
133
|
-
/** Key into `terraform.roots`. Also the member's name in a wave's set digest. */
|
|
141
|
+
/** Key into `terraform.roots`. Also the member's name in a wave's set digest. With no such entry, `dir` is the root's directory (chant#4842). */
|
|
134
142
|
root: string;
|
|
135
143
|
/** Input variables, after the root's var files. See `TerraformPlanArgs.vars`. */
|
|
136
144
|
vars?: Record<string, unknown>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capability-plugin.d.ts","sourceRoot":"","sources":["../../src/components/capability-plugin.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"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;CAClC;AA8GD;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,OAAO,GAAG,cAAc,CAerE;AAED;;;;GAIG;AACH,wBAAgB,6BAA6B,CAAC,GAAG,EAAE;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAAG,oBAAoB,CAEhI;AAID;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,EAAE,kBAInC,CAAC;AA4BF,4GAA4G;AAC5G,eAAO,MAAM,iBAAiB,0BAA0B,CAAC;AAEzD,iHAAiH;AACjH,MAAM,WAAW,sBAAuB,SAAQ,iBAAiB;IAC/D,IAAI,EAAE,uBAAuB,CAAC;CAC/B;AAwFD;;;;;;;GAOG;AACH,qBAAa,uBAAwB,SAAQ,KAAK;aAEpB,IAAI,EAAE,MAAM;IADxC,QAAQ,CAAC,SAAS,QAAQ;IAC1B,YAA4B,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAGxD;CACF;AA6DD,eAAO,MAAM,wBAAwB,EAAE,UAAU,CAAC,uBAAuB,EAAE,wBAAwB,CA6HlG,CAAC;AAEF,eAAO,MAAM,uBAAuB;aAClC,KAAK,YAAG,iBAAiB;aAEzB,KAAK,YAAG,wBAAwB,EAAE,sBAAsB;aACxD,IAAI,YAAG,gBAAgB;aAEvB,MAAM,YAAG,kBAAkB;CACnB,CAAC;AAEX,eAAO,MAAM,yBAAyB,EAAE,gBAoBvC,CAAC"}
|
|
@@ -119,6 +119,14 @@
|
|
|
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
|
+
* A wave's run hooks in the product's process (chant#4842) reach the step
|
|
123
|
+
* through its context. `processEnv` goes to every command for the root (a
|
|
124
|
+
* role's credentials, values from a secret store), and `afterInit` is
|
|
125
|
+
* called after `init` and before `plan`, or before `live-plan-set`, which
|
|
126
|
+
* inits and plans in one command. A `root` with no `terraform.roots` entry
|
|
127
|
+
* plans the step's `dir` as its directory, so a product can name each root
|
|
128
|
+
* by its path without writing an entry for it.
|
|
129
|
+
*
|
|
122
130
|
* Every plan also writes its `show -json` beside the plan file and names it
|
|
123
131
|
* as `artifact.planJson`, the document a wave's cost hold prices
|
|
124
132
|
* (`../cost-hold.ts`).
|
|
@@ -147,6 +155,7 @@ import { conePlanDigest } from "../cone.js";
|
|
|
147
155
|
import { fillStateReads, stateReadsProblems, waitingReadsReason } from "../state-reads.js";
|
|
148
156
|
import { terraformStateOpCapabilities } from "../state-ops.js";
|
|
149
157
|
import { terraformActionCapability } from "../action-ops.js";
|
|
158
|
+
import { terragruntApply } from "../terragrunt/capability.js";
|
|
150
159
|
/** The lock timeout a step's plan and apply pass (#4545). */
|
|
151
160
|
function lockTimeoutOf(input) {
|
|
152
161
|
if (input.lockTimeout === false)
|
|
@@ -188,20 +197,22 @@ function waitingOnReads(ctx, input, waiting) {
|
|
|
188
197
|
};
|
|
189
198
|
return { member: input.root, planDigest, changeSet };
|
|
190
199
|
}
|
|
191
|
-
const rootArgs = (input) => ({ root: input.root, ...(input.cwd ? { cwd: input.cwd } : {}), ...(input.dir ? { dir: input.dir } : {}) });
|
|
200
|
+
const rootArgs = (input, env) => ({ root: input.root, ...(input.cwd ? { cwd: input.cwd } : {}), ...(input.dir ? { dir: input.dir } : {}), ...(env ? { env } : {}) });
|
|
192
201
|
function requireRoot(input) {
|
|
193
202
|
if (typeof input.root !== "string" || input.root === "") {
|
|
194
203
|
throw new Error('terraform-apply: "root" is required and names an entry in terraform.roots');
|
|
195
204
|
}
|
|
196
205
|
}
|
|
197
|
-
async function planRoot(input, targets) {
|
|
206
|
+
async function planRoot(input, targets, at = {}) {
|
|
198
207
|
requireRoot(input);
|
|
199
|
-
await terraformInit(rootArgs(input));
|
|
208
|
+
await terraformInit(rootArgs(input, at.env));
|
|
209
|
+
// chant#4842: the run hook's check, once init fetched the modules and providers and before the plan runs their code.
|
|
210
|
+
await at.afterInit?.();
|
|
200
211
|
// One `show -json` per plan (#4479): its document is the digest, the change
|
|
201
212
|
// set, the planned outputs and the shape. Nothing here reads the
|
|
202
213
|
// `-no-color` render, so the plan skips it.
|
|
203
214
|
const planned = await terraformPlan({
|
|
204
|
-
...rootArgs(input),
|
|
215
|
+
...rootArgs(input, at.env),
|
|
205
216
|
...(input.vars ? { vars: input.vars } : {}),
|
|
206
217
|
...(targets && targets.length > 0 ? { targets } : {}),
|
|
207
218
|
...lockTimeoutOf(input),
|
|
@@ -321,7 +332,8 @@ async function rootDir(input) {
|
|
|
321
332
|
const start = resolve(input.cwd ?? process.cwd());
|
|
322
333
|
const { config, configPath } = await loadChantConfigUpward(start);
|
|
323
334
|
const terraform = config.terraform;
|
|
324
|
-
|
|
335
|
+
// chant#4842: a root with no entry and a dir of its own is that directory.
|
|
336
|
+
const declared = terraform?.roots?.[input.root]?.dir ?? input.dir;
|
|
325
337
|
if (declared === undefined)
|
|
326
338
|
return undefined;
|
|
327
339
|
const dir = input.dir ?? declared;
|
|
@@ -350,9 +362,10 @@ async function previewRoot(ctx, input, unresolved, targets) {
|
|
|
350
362
|
return waitingRoot(ctx, input, unresolved, stand);
|
|
351
363
|
let planned;
|
|
352
364
|
try {
|
|
353
|
-
await terraformInit(rootArgs(input));
|
|
365
|
+
await terraformInit(rootArgs(input, ctx.processEnv));
|
|
366
|
+
await ctx.afterInit?.();
|
|
354
367
|
planned = await terraformPlan({
|
|
355
|
-
...rootArgs(input),
|
|
368
|
+
...rootArgs(input, ctx.processEnv),
|
|
356
369
|
vars: stand.vars,
|
|
357
370
|
planFile: PREVIEW_PLAN_FILE,
|
|
358
371
|
...(targets ? { targets } : {}),
|
|
@@ -427,7 +440,7 @@ function isChoudoufuWavePlan(value) {
|
|
|
427
440
|
/** Apply a choudoufu root through `live-wave-apply`, carrying its resume file either way. */
|
|
428
441
|
async function runChoudoufuWave(ctx, input, planned) {
|
|
429
442
|
const applied = await choudoufuWaveApply({
|
|
430
|
-
...rootArgs(input),
|
|
443
|
+
...rootArgs(input, ctx.processEnv),
|
|
431
444
|
planSetFile: planned.choudoufu.planSetFile,
|
|
432
445
|
setDigest: planned.choudoufu.setDigest,
|
|
433
446
|
...(ctx.carried?.[input.root] !== undefined ? { carried: ctx.carried[input.root] } : {}),
|
|
@@ -440,7 +453,7 @@ async function runChoudoufuWave(ctx, input, planned) {
|
|
|
440
453
|
throw new TerraformPlanMovedError(input.root, message);
|
|
441
454
|
throw new Error(message);
|
|
442
455
|
}
|
|
443
|
-
const outputs = await terraformOutputs(rootArgs(input));
|
|
456
|
+
const outputs = await terraformOutputs(rootArgs(input, ctx.processEnv));
|
|
444
457
|
return { root: input.root, planDigest: planned.planDigest, fromWavePlan: true, outputs };
|
|
445
458
|
}
|
|
446
459
|
/** The input a `run` that plans for itself plans with (#4545): its reads filled, or an error naming the upstream to apply first. */
|
|
@@ -484,9 +497,12 @@ export const terraformApplyCapability = {
|
|
|
484
497
|
if (unresolved.length > 0)
|
|
485
498
|
return previewRoot(ctx, input, unresolved, targets);
|
|
486
499
|
// A targeted root plans with `plan -target`, and a cone plan with `plan -cone` (#4545), never as a choudoufu one-root set.
|
|
487
|
-
const
|
|
500
|
+
const env = ctx.processEnv;
|
|
501
|
+
const wave = targets || input.cone ? { wave: false } : await choudoufuWaveRoot({ ...rootArgs(input, env), ...(input.vars ? { vars: input.vars } : {}) });
|
|
488
502
|
if (wave.wave) {
|
|
489
|
-
|
|
503
|
+
// chant#4842: live-plan-set inits and plans in one command, so the run hook's check comes before it.
|
|
504
|
+
await ctx.afterInit?.();
|
|
505
|
+
const set = await choudoufuPlanSet(rootArgs(input, env));
|
|
490
506
|
const artifact = {
|
|
491
507
|
planDigest: set.planDigest,
|
|
492
508
|
choudoufu: { planSetFile: set.planSetFile, setDigest: set.setDigest },
|
|
@@ -494,7 +510,7 @@ export const terraformApplyCapability = {
|
|
|
494
510
|
};
|
|
495
511
|
return { member: input.root, planDigest: set.planDigest, artifact, changeSet: set.changeSet, outputs: terraformPlannedOutputs(set.json), shape: terraformPlanShape(set.json, input.root) };
|
|
496
512
|
}
|
|
497
|
-
const { changeSet, json, ...planned } = await planRoot(input, targets);
|
|
513
|
+
const { changeSet, json, ...planned } = await planRoot(input, targets, { env, ...(ctx.afterInit ? { afterInit: ctx.afterInit } : {}) });
|
|
498
514
|
// #4552: a choudoufu root's rows, keyed from the plan document while it is at hand.
|
|
499
515
|
const lockRows = changeSet?.member.planner === "choudoufu" ? terraformLockRows(input.root, changeSet.member.scope, json) : undefined;
|
|
500
516
|
return {
|
|
@@ -511,10 +527,10 @@ export const terraformApplyCapability = {
|
|
|
511
527
|
},
|
|
512
528
|
// The root's outputs as its state holds them now (#3183): what a dependent
|
|
513
529
|
// planned before this root applies reads through `stackOutput()`.
|
|
514
|
-
async outputs(
|
|
530
|
+
async outputs(ctx, input) {
|
|
515
531
|
requireRoot(input);
|
|
516
|
-
await terraformInit(rootArgs(input));
|
|
517
|
-
return terraformOutputs(rootArgs(input));
|
|
532
|
+
await terraformInit(rootArgs(input, ctx.processEnv));
|
|
533
|
+
return terraformOutputs(rootArgs(input, ctx.processEnv));
|
|
518
534
|
},
|
|
519
535
|
// #4447 (ws-107): a group core forms of components that read each other plans and applies as one composed run
|
|
520
536
|
// when `terraform.compose.enabled` is set (./compose-group.ts). Delegates, so the methods are read when called.
|
|
@@ -557,21 +573,21 @@ export const terraformApplyCapability = {
|
|
|
557
573
|
if (isShapeArtifact(fromWave)) {
|
|
558
574
|
// A root previewed with stand-ins (#4463): plan it now with the real
|
|
559
575
|
// values, and apply that plan only when it is within the preview's shape.
|
|
560
|
-
const fresh = await planRoot(await readsForRun(input), ctx.targets);
|
|
576
|
+
const fresh = await planRoot(await readsForRun(input), ctx.targets, { env: ctx.processEnv });
|
|
561
577
|
const differences = planShapeDifferences(fromWave.shape, terraformPlanShape(fresh.json, input.root));
|
|
562
578
|
if (differences.length > 0)
|
|
563
579
|
throw new PlanShapeMovedError(input.root, differences);
|
|
564
|
-
const applied = await terraformApply({ ...rootArgs(input), planFile: fresh.planFile, ...lockTimeoutOf(input) });
|
|
580
|
+
const applied = await terraformApply({ ...rootArgs(input, ctx.processEnv), planFile: fresh.planFile, ...lockTimeoutOf(input) });
|
|
565
581
|
if (!applied.applied) {
|
|
566
582
|
throw new Error(`terraform-apply: root "${input.root}" refused the plan it was given (${applied.refused ?? "refused"}). ${applied.refusal ?? ""}`);
|
|
567
583
|
}
|
|
568
|
-
const outputs = await terraformOutputs(rootArgs(input));
|
|
584
|
+
const outputs = await terraformOutputs(rootArgs(input, ctx.processEnv));
|
|
569
585
|
return { root: input.root, planDigest: fresh.planDigest, fromWavePlan: false, outputs };
|
|
570
586
|
}
|
|
571
587
|
const planned = isPlannedRoot(fromWave)
|
|
572
588
|
? fromWave
|
|
573
|
-
: await planRoot(await readsForRun(input), ctx.targets).then(({ planFile, planDigest }) => ({ planFile, planDigest }));
|
|
574
|
-
const applied = await terraformApply({ ...rootArgs(input), planFile: planned.planFile, ...lockTimeoutOf(input) });
|
|
589
|
+
: await planRoot(await readsForRun(input), ctx.targets, { env: ctx.processEnv }).then(({ planFile, planDigest }) => ({ planFile, planDigest }));
|
|
590
|
+
const applied = await terraformApply({ ...rootArgs(input, ctx.processEnv), planFile: planned.planFile, ...lockTimeoutOf(input) });
|
|
575
591
|
if (!applied.applied) {
|
|
576
592
|
const message = `terraform-apply: root "${input.root}" refused the plan it was given (${applied.refused ?? "refused"}). ` +
|
|
577
593
|
(applied.refusal ?? "");
|
|
@@ -582,7 +598,7 @@ export const terraformApplyCapability = {
|
|
|
582
598
|
throw new TerraformPlanMovedError(input.root, message);
|
|
583
599
|
throw new Error(message);
|
|
584
600
|
}
|
|
585
|
-
const outputs = await terraformOutputs(rootArgs(input));
|
|
601
|
+
const outputs = await terraformOutputs(rootArgs(input, ctx.processEnv));
|
|
586
602
|
return { root: input.root, planDigest: planned.planDigest, fromWavePlan: isPlannedRoot(fromWave), outputs };
|
|
587
603
|
},
|
|
588
604
|
};
|
|
@@ -600,7 +616,13 @@ export const terraformCapabilityPlugin = {
|
|
|
600
616
|
return ownPackageVersion(import.meta.url);
|
|
601
617
|
},
|
|
602
618
|
capabilities() {
|
|
603
|
-
return [
|
|
619
|
+
return [
|
|
620
|
+
terraformApplyCapability,
|
|
621
|
+
...terraformStateOpCapabilities.map((c) => c),
|
|
622
|
+
terraformActionCapability,
|
|
623
|
+
// #4842: Terragrunt units as an op wave's step, found at plan time and run with one run --all.
|
|
624
|
+
terragruntApply,
|
|
625
|
+
];
|
|
604
626
|
},
|
|
605
627
|
families() {
|
|
606
628
|
return TERRAFORM_VERB_FAMILIES;
|
package/dist/drift-record.d.ts
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* | `live-plan -json` | `ownership` | `bound[]`: in-sync, owned by its `source`. `unowned[]` and `adoptable[]`: unclaimed. `ABSENT`: pending. Any other omission: not-observed. `foreign[]`: undeclared, foreign. `controller_held[]`: runtime |
|
|
12
12
|
* | `live-ls -json` | `ownership` | `declared: false`: undeclared. A gap no live-plan row answers: not-observed |
|
|
13
13
|
* | live-plan and a plan together | `plan` | bound with a planned update or replace: drifted with paths, the live-plan ownership kept |
|
|
14
|
+
* | `show -json` of a live root's full plan | `plan` | planned create: missing. Planned delete or forget: undeclared. Update or any pair of actions: drifted with paths, declared then live. No-op: in-sync |
|
|
14
15
|
*
|
|
15
16
|
* A state read never says in-sync or drifted: `driftRecord` refuses it.
|
|
16
17
|
*
|
|
@@ -77,6 +78,29 @@ export interface TerraformPlanDriftInput extends DriftAdapterBase {
|
|
|
77
78
|
* configuration is the change set's to show and not drift.
|
|
78
79
|
*/
|
|
79
80
|
export declare function terraformPlanDriftRecords(input: TerraformPlanDriftInput): DriftRecord[];
|
|
81
|
+
export interface TerraformLivePlanDriftInput extends DriftAdapterBase {
|
|
82
|
+
/** The engine that planned the root. Default `choudoufu`, which plans a live root. */
|
|
83
|
+
engine?: "choudoufu" | "terraform" | "tofu";
|
|
84
|
+
/** `show -json <planfile>` of the root's full plan, parsed. */
|
|
85
|
+
plan: unknown;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* A live root's records from its full plan, read as drift (#4812). A root
|
|
89
|
+
* under live resource markers takes no refresh-only plan, and its plan reads
|
|
90
|
+
* the live system, so what the plan would change is what moved outside the
|
|
91
|
+
* code: one record per managed instance in `resource_changes`, a planned
|
|
92
|
+
* create missing (the object no longer exists), a planned delete or forget
|
|
93
|
+
* undeclared (it exists outside the code), an update or any pair of actions
|
|
94
|
+
* drifted with the plan's paths, declared before and live after, and a
|
|
95
|
+
* no-op in-sync. A path whose declared value is known only after the apply
|
|
96
|
+
* is not a difference and is left out. `resource_drift` is not read.
|
|
97
|
+
*
|
|
98
|
+
* The rules are drift-rows' `live: true` read (`./drift-rows.ts`), so the
|
|
99
|
+
* records that are not in-sync are its rows. `choudoufuLivePlusPlanDriftRecords`
|
|
100
|
+
* is the read for a root whose `live-plan -json` was taken too: it keeps
|
|
101
|
+
* live-plan's ownership, which a plan alone does not give.
|
|
102
|
+
*/
|
|
103
|
+
export declare function terraformLivePlanDriftRecords(input: TerraformLivePlanDriftInput): DriftRecord[];
|
|
80
104
|
export interface ChoudoufuLivePlanDriftInput extends DriftAdapterBase {
|
|
81
105
|
/** `choudoufu live-plan -json`, parsed. */
|
|
82
106
|
livePlan: unknown;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drift-record.d.ts","sourceRoot":"","sources":["../src/drift-record.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"drift-record.d.ts","sourceRoot":"","sources":["../src/drift-record.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,OAAO,EAGL,KAAK,gBAAgB,EAKrB,KAAK,WAAW,EACjB,MAAM,+BAA+B,CAAC;AAiEvC,MAAM,WAAW,wBAAyB,SAAQ,gBAAgB;IAChE,MAAM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Q,CAAC,MAAM,CAAC,CAAC;CAC7B;AAED;;;;;;;;GAQG;AACH,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,yBAAyB,GAAG,WAAW,EAAE,CAmD3F;AAED,kGAAkG;AAClG,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,gBAAgB,GAAG;IAAE,QAAQ,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,WAAW,EAAE,CAM1H;AAID,MAAM,WAAW,+BAAgC,SAAQ,gBAAgB;IACvE,2CAA2C;IAC3C,QAAQ,EAAE,OAAO,CAAC;IAClB,kEAAkE;IAClE,IAAI,EAAE,OAAO,CAAC;IACd,+DAA+D;IAC/D,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;;GAOG;AACH,wBAAgB,iCAAiC,CAAC,KAAK,EAAE,+BAA+B,GAAG,WAAW,EAAE,CAqBvG"}
|
package/dist/drift-record.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* | `live-plan -json` | `ownership` | `bound[]`: in-sync, owned by its `source`. `unowned[]` and `adoptable[]`: unclaimed. `ABSENT`: pending. Any other omission: not-observed. `foreign[]`: undeclared, foreign. `controller_held[]`: runtime |
|
|
12
12
|
* | `live-ls -json` | `ownership` | `declared: false`: undeclared. A gap no live-plan row answers: not-observed |
|
|
13
13
|
* | live-plan and a plan together | `plan` | bound with a planned update or replace: drifted with paths, the live-plan ownership kept |
|
|
14
|
+
* | `show -json` of a live root's full plan | `plan` | planned create: missing. Planned delete or forget: undeclared. Update or any pair of actions: drifted with paths, declared then live. No-op: in-sync |
|
|
14
15
|
*
|
|
15
16
|
* A state read never says in-sync or drifted: `driftRecord` refuses it.
|
|
16
17
|
*
|
|
@@ -170,6 +171,57 @@ export function terraformPlanDriftRecords(input) {
|
|
|
170
171
|
return driftRecord({ ...at, status: "in-sync" });
|
|
171
172
|
});
|
|
172
173
|
}
|
|
174
|
+
/**
|
|
175
|
+
* A live root's records from its full plan, read as drift (#4812). A root
|
|
176
|
+
* under live resource markers takes no refresh-only plan, and its plan reads
|
|
177
|
+
* the live system, so what the plan would change is what moved outside the
|
|
178
|
+
* code: one record per managed instance in `resource_changes`, a planned
|
|
179
|
+
* create missing (the object no longer exists), a planned delete or forget
|
|
180
|
+
* undeclared (it exists outside the code), an update or any pair of actions
|
|
181
|
+
* drifted with the plan's paths, declared before and live after, and a
|
|
182
|
+
* no-op in-sync. A path whose declared value is known only after the apply
|
|
183
|
+
* is not a difference and is left out. `resource_drift` is not read.
|
|
184
|
+
*
|
|
185
|
+
* The rules are drift-rows' `live: true` read (`./drift-rows.ts`), so the
|
|
186
|
+
* records that are not in-sync are its rows. `choudoufuLivePlusPlanDriftRecords`
|
|
187
|
+
* is the read for a root whose `live-plan -json` was taken too: it keeps
|
|
188
|
+
* live-plan's ownership, which a plan alone does not give.
|
|
189
|
+
*/
|
|
190
|
+
export function terraformLivePlanDriftRecords(input) {
|
|
191
|
+
const engine = input.engine ?? "choudoufu";
|
|
192
|
+
const doc = isObject(input.plan) ? input.plan : {};
|
|
193
|
+
const version = input.version ?? asString(doc.terraform_version);
|
|
194
|
+
const evidence = { tool: engine, ...(version ? { version } : {}), command: `${engine} show -json` };
|
|
195
|
+
const index = indexPlan(input.plan);
|
|
196
|
+
const types = new Map();
|
|
197
|
+
for (const entry of asArray(doc.resource_changes)) {
|
|
198
|
+
if (isObject(entry) && asString(entry.address) && asString(entry.type))
|
|
199
|
+
types.set(entry.address, entry.type);
|
|
200
|
+
}
|
|
201
|
+
const out = [];
|
|
202
|
+
for (const [address, change] of index.changes) {
|
|
203
|
+
if (isDataAddress(address))
|
|
204
|
+
continue;
|
|
205
|
+
const type = types.get(address);
|
|
206
|
+
const at = { ...common(input, engine, "plan", address), ...(type ? { resourceType: type } : {}), evidence };
|
|
207
|
+
const actions = change.actions.filter((a) => a !== "no-op" && a !== "read");
|
|
208
|
+
if (actions.length === 0) {
|
|
209
|
+
out.push(driftRecord({ ...at, status: "in-sync" }));
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
if (change.actions.length === 1 && actions[0] === "create") {
|
|
213
|
+
out.push(driftRecord({ ...at, status: "missing" }));
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
if (change.actions.length === 1 && (actions[0] === "delete" || actions[0] === "forget")) {
|
|
217
|
+
out.push(driftRecord({ ...at, status: "undeclared" }));
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
const attributes = change.changes.filter((c) => c.after !== KNOWN_AFTER_APPLY).map((c) => attributeOf(c, true));
|
|
221
|
+
out.push(driftRecord({ ...at, status: "drifted", ...(attributes.length > 0 ? { attributes } : {}) }));
|
|
222
|
+
}
|
|
223
|
+
return out.sort(byAddress);
|
|
224
|
+
}
|
|
173
225
|
// ── choudoufu live-plan ────────────────────────────────────────────────────────
|
|
174
226
|
const BOUND_SOURCES = ["marker", "record", "derived", "cache"];
|
|
175
227
|
/**
|
package/dist/drift-rows.d.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Drift rows (#4580): one row per object a plan found drifted, by address,
|
|
3
3
|
* with its action and the object's real name, counted the way a product's
|
|
4
4
|
* drift report counts. `./drift-record.ts` answers a different question (the
|
|
5
|
-
* status of each instance the plan names), so it skips create
|
|
6
|
-
*
|
|
5
|
+
* status of each instance the plan names, redacted), so it skips create
|
|
6
|
+
* rows and carries no names.
|
|
7
7
|
*
|
|
8
8
|
* A stock root's refresh-only plan reports drift as `resource_drift`, and
|
|
9
9
|
* every entry there is one row, data blocks and creates included. A full
|
|
@@ -14,8 +14,15 @@
|
|
|
14
14
|
* Data blocks, no-op and read entries are not drift.
|
|
15
15
|
*
|
|
16
16
|
* These are terragucci's rules (packages/terragucci/src/report/drift.ts:
|
|
17
|
-
* `liveDrift`, `driftCount`, `driftNames`), so a row count here
|
|
18
|
-
* count its report gives for the same plan.
|
|
17
|
+
* `driftPlan`, `liveDrift`, `driftCount`, `driftNames`), so a row count here
|
|
18
|
+
* equals the count its report gives for the same plan.
|
|
19
|
+
*
|
|
20
|
+
* Behind every row is a whole change (#4812): the plan's entry for the
|
|
21
|
+
* object, shaped as a `resource_changes[]` entry with its actions, full
|
|
22
|
+
* before and after and their masks (`terraformPlanDriftChanges`). A drift
|
|
23
|
+
* report is a plan report over those changes: `terraformDriftPlan` puts a
|
|
24
|
+
* refresh-only plan's drift in place of its changes, and
|
|
25
|
+
* `terraformLivePlanDrift` reads a live root's full plan as drift.
|
|
19
26
|
*
|
|
20
27
|
* A row carries no attribute values. Its `name` is the first non-empty
|
|
21
28
|
* string among `name`, `id`, `bucket`, `function_name` and `arn`, read from
|
|
@@ -49,6 +56,44 @@ export interface TerraformPlanDriftRowsOptions {
|
|
|
49
56
|
*/
|
|
50
57
|
live?: boolean;
|
|
51
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* The drift a plan (`show -json`, parsed) found as whole changes (#4812),
|
|
61
|
+
* one per drifted object in the plan's order, each shaped as a
|
|
62
|
+
* `resource_changes[]` entry: `address`, `mode`, `type`, `name`,
|
|
63
|
+
* `module_address`, `index`, `deposed` and `provider_name` as the plan has
|
|
64
|
+
* them, and `change` with its actions, its full before and after, and their
|
|
65
|
+
* masks. A stock root's are its `resource_drift` entries unchanged. A live
|
|
66
|
+
* root's are its full plan's changes seen from the other side: a create
|
|
67
|
+
* there is a `delete` (the object no longer exists), a delete a `create`
|
|
68
|
+
* (an object exists outside the code), any pair of actions an `update`, the
|
|
69
|
+
* code's value before and the live one after, the sensitive masks swapped
|
|
70
|
+
* with them and an unknown value replaced by the live one.
|
|
71
|
+
*
|
|
72
|
+
* Values are not redacted: a change carries what the plan carries, masks
|
|
73
|
+
* included, for a report that renders the plan. A drift record
|
|
74
|
+
* (`./drift-record.ts`) is the redacted read.
|
|
75
|
+
*
|
|
76
|
+
* Its length is the drift count, and `terraformPlanDriftRows` is one row
|
|
77
|
+
* per entry. A malformed `resource_drift` entry that is not an object is
|
|
78
|
+
* passed on as the plan has it, and its row has the address `""`.
|
|
79
|
+
*/
|
|
80
|
+
export declare function terraformPlanDriftChanges(plan: unknown, options?: TerraformPlanDriftRowsOptions): Record<string, unknown>[];
|
|
81
|
+
/**
|
|
82
|
+
* A refresh-only plan as its drift report reads it: the drift found in place
|
|
83
|
+
* of the changes proposed, so the report is built from the same JSON as a
|
|
84
|
+
* plan's and code waiting on the default branch never shows in it.
|
|
85
|
+
* `resource_changes` becomes `terraformPlanDriftChanges(plan)`; the rest of
|
|
86
|
+
* the document is kept. Anything not an object is returned as it is.
|
|
87
|
+
*/
|
|
88
|
+
export declare function terraformDriftPlan(plan: unknown): unknown;
|
|
89
|
+
/**
|
|
90
|
+
* A full plan of a root under live resource markers, as drift: its
|
|
91
|
+
* `resource_drift` becomes `terraformPlanDriftChanges(plan, { live: true })`
|
|
92
|
+
* and the rest of the document is kept, so it reads as a refresh-only plan
|
|
93
|
+
* would (`terraformDriftPlan`, and every function here without `live`).
|
|
94
|
+
* Anything not an object is returned as it is.
|
|
95
|
+
*/
|
|
96
|
+
export declare function terraformLivePlanDrift(plan: unknown): unknown;
|
|
52
97
|
/**
|
|
53
98
|
* The drift a plan (`show -json`, parsed) found, one row per drifted object
|
|
54
99
|
* in the plan's order. Its length is the drift count.
|
package/dist/drift-rows.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drift-rows.d.ts","sourceRoot":"","sources":["../src/drift-rows.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"drift-rows.d.ts","sourceRoot":"","sources":["../src/drift-rows.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAMH,0BAA0B;AAC1B,MAAM,WAAW,iBAAiB;IAChC,iEAAiE;IACjE,OAAO,EAAE,MAAM,CAAC;IAChB;;;;;OAKG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,mDAAmD;IACnD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,mEAAmE;IACnE,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,6BAA6B;IAC5C;;;;OAIG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AA4ED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,GAAE,6BAAkC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAG/H;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAGzD;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAG7D;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,GAAE,6BAAkC,GAAG,iBAAiB,EAAE,CAEtH;AAED,6FAA6F;AAC7F,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,GAAE,6BAAkC,GAAG,MAAM,CAE1G;AAED,8EAA8E;AAC9E,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,GAAE,6BAAkC,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAIvH"}
|
package/dist/drift-rows.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Drift rows (#4580): one row per object a plan found drifted, by address,
|
|
3
3
|
* with its action and the object's real name, counted the way a product's
|
|
4
4
|
* drift report counts. `./drift-record.ts` answers a different question (the
|
|
5
|
-
* status of each instance the plan names), so it skips create
|
|
6
|
-
*
|
|
5
|
+
* status of each instance the plan names, redacted), so it skips create
|
|
6
|
+
* rows and carries no names.
|
|
7
7
|
*
|
|
8
8
|
* A stock root's refresh-only plan reports drift as `resource_drift`, and
|
|
9
9
|
* every entry there is one row, data blocks and creates included. A full
|
|
@@ -14,8 +14,15 @@
|
|
|
14
14
|
* Data blocks, no-op and read entries are not drift.
|
|
15
15
|
*
|
|
16
16
|
* These are terragucci's rules (packages/terragucci/src/report/drift.ts:
|
|
17
|
-
* `liveDrift`, `driftCount`, `driftNames`), so a row count here
|
|
18
|
-
* count its report gives for the same plan.
|
|
17
|
+
* `driftPlan`, `liveDrift`, `driftCount`, `driftNames`), so a row count here
|
|
18
|
+
* equals the count its report gives for the same plan.
|
|
19
|
+
*
|
|
20
|
+
* Behind every row is a whole change (#4812): the plan's entry for the
|
|
21
|
+
* object, shaped as a `resource_changes[]` entry with its actions, full
|
|
22
|
+
* before and after and their masks (`terraformPlanDriftChanges`). A drift
|
|
23
|
+
* report is a plan report over those changes: `terraformDriftPlan` puts a
|
|
24
|
+
* refresh-only plan's drift in place of its changes, and
|
|
25
|
+
* `terraformLivePlanDrift` reads a live root's full plan as drift.
|
|
19
26
|
*
|
|
20
27
|
* A row carries no attribute values. Its `name` is the first non-empty
|
|
21
28
|
* string among `name`, `id`, `bucket`, `function_name` and `arn`, read from
|
|
@@ -54,17 +61,22 @@ function stockAction(actions) {
|
|
|
54
61
|
return "replace";
|
|
55
62
|
return "update";
|
|
56
63
|
}
|
|
57
|
-
/**
|
|
58
|
-
function
|
|
59
|
-
|
|
60
|
-
return list.map((entry) => {
|
|
64
|
+
/** One row per whole change. */
|
|
65
|
+
function rowsOf(changes) {
|
|
66
|
+
return changes.map((entry) => {
|
|
61
67
|
const ch = isObject(entry) && isObject(entry.change) ? entry.change : {};
|
|
62
68
|
const actions = Array.isArray(ch.actions) ? ch.actions.map(String) : [];
|
|
63
69
|
return rowOf(entry, stockAction(actions), [ch.after, ch.before]);
|
|
64
70
|
});
|
|
65
71
|
}
|
|
66
|
-
/**
|
|
67
|
-
|
|
72
|
+
/**
|
|
73
|
+
* A live root's full plan, its changes read as drift: each one the plan
|
|
74
|
+
* would make, seen from the other side, as terragucci's `liveDrift` builds
|
|
75
|
+
* it. The code's value is before and the live value after, the masks swap
|
|
76
|
+
* with them, and a value the plan knows only after the apply takes the live
|
|
77
|
+
* one, since it is not a difference.
|
|
78
|
+
*/
|
|
79
|
+
function liveChanges(doc) {
|
|
68
80
|
const list = Array.isArray(doc.resource_changes) ? doc.resource_changes : [];
|
|
69
81
|
const out = [];
|
|
70
82
|
for (const entry of list) {
|
|
@@ -75,24 +87,80 @@ function liveRows(doc) {
|
|
|
75
87
|
if (actions.length === 0 || actions.every((a) => a === "no-op" || a === "read"))
|
|
76
88
|
continue;
|
|
77
89
|
const action = actions.length === 1 ? (FLIP[actions[0]] ?? actions[0]) : "update";
|
|
78
|
-
const live =
|
|
79
|
-
let code =
|
|
80
|
-
// A value the plan knows only after the apply is not a difference: the live one stands for it.
|
|
90
|
+
const live = (ch.before ?? null);
|
|
91
|
+
let code = (ch.after ?? null);
|
|
81
92
|
const unknown = isObject(ch.after_unknown) ? ch.after_unknown : {};
|
|
82
|
-
if (code && live)
|
|
83
|
-
|
|
84
|
-
|
|
93
|
+
if (isObject(code) && isObject(live)) {
|
|
94
|
+
const known = live;
|
|
95
|
+
code = { ...code, ...Object.fromEntries(Object.keys(unknown).filter((k) => unknown[k] === true && k in known).map((k) => [k, known[k]])) };
|
|
96
|
+
}
|
|
97
|
+
out.push({
|
|
98
|
+
...entry,
|
|
99
|
+
change: { actions: [action], before: code, after: live, before_sensitive: ch.after_sensitive ?? false, after_sensitive: ch.before_sensitive ?? false },
|
|
100
|
+
});
|
|
85
101
|
}
|
|
86
102
|
return out;
|
|
87
103
|
}
|
|
104
|
+
/** A refresh-only plan's `resource_drift`, each entry as the plan has it. */
|
|
105
|
+
function stockChanges(doc) {
|
|
106
|
+
return (Array.isArray(doc.resource_drift) ? [...doc.resource_drift] : []);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The drift a plan (`show -json`, parsed) found as whole changes (#4812),
|
|
110
|
+
* one per drifted object in the plan's order, each shaped as a
|
|
111
|
+
* `resource_changes[]` entry: `address`, `mode`, `type`, `name`,
|
|
112
|
+
* `module_address`, `index`, `deposed` and `provider_name` as the plan has
|
|
113
|
+
* them, and `change` with its actions, its full before and after, and their
|
|
114
|
+
* masks. A stock root's are its `resource_drift` entries unchanged. A live
|
|
115
|
+
* root's are its full plan's changes seen from the other side: a create
|
|
116
|
+
* there is a `delete` (the object no longer exists), a delete a `create`
|
|
117
|
+
* (an object exists outside the code), any pair of actions an `update`, the
|
|
118
|
+
* code's value before and the live one after, the sensitive masks swapped
|
|
119
|
+
* with them and an unknown value replaced by the live one.
|
|
120
|
+
*
|
|
121
|
+
* Values are not redacted: a change carries what the plan carries, masks
|
|
122
|
+
* included, for a report that renders the plan. A drift record
|
|
123
|
+
* (`./drift-record.ts`) is the redacted read.
|
|
124
|
+
*
|
|
125
|
+
* Its length is the drift count, and `terraformPlanDriftRows` is one row
|
|
126
|
+
* per entry. A malformed `resource_drift` entry that is not an object is
|
|
127
|
+
* passed on as the plan has it, and its row has the address `""`.
|
|
128
|
+
*/
|
|
129
|
+
export function terraformPlanDriftChanges(plan, options = {}) {
|
|
130
|
+
if (!isObject(plan))
|
|
131
|
+
return [];
|
|
132
|
+
return options.live ? liveChanges(plan) : stockChanges(plan);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* A refresh-only plan as its drift report reads it: the drift found in place
|
|
136
|
+
* of the changes proposed, so the report is built from the same JSON as a
|
|
137
|
+
* plan's and code waiting on the default branch never shows in it.
|
|
138
|
+
* `resource_changes` becomes `terraformPlanDriftChanges(plan)`; the rest of
|
|
139
|
+
* the document is kept. Anything not an object is returned as it is.
|
|
140
|
+
*/
|
|
141
|
+
export function terraformDriftPlan(plan) {
|
|
142
|
+
if (!isObject(plan))
|
|
143
|
+
return plan;
|
|
144
|
+
return { ...plan, resource_changes: terraformPlanDriftChanges(plan) };
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* A full plan of a root under live resource markers, as drift: its
|
|
148
|
+
* `resource_drift` becomes `terraformPlanDriftChanges(plan, { live: true })`
|
|
149
|
+
* and the rest of the document is kept, so it reads as a refresh-only plan
|
|
150
|
+
* would (`terraformDriftPlan`, and every function here without `live`).
|
|
151
|
+
* Anything not an object is returned as it is.
|
|
152
|
+
*/
|
|
153
|
+
export function terraformLivePlanDrift(plan) {
|
|
154
|
+
if (!isObject(plan))
|
|
155
|
+
return plan;
|
|
156
|
+
return { ...plan, resource_drift: terraformPlanDriftChanges(plan, { live: true }) };
|
|
157
|
+
}
|
|
88
158
|
/**
|
|
89
159
|
* The drift a plan (`show -json`, parsed) found, one row per drifted object
|
|
90
160
|
* in the plan's order. Its length is the drift count.
|
|
91
161
|
*/
|
|
92
162
|
export function terraformPlanDriftRows(plan, options = {}) {
|
|
93
|
-
|
|
94
|
-
return [];
|
|
95
|
-
return options.live ? liveRows(plan) : stockRows(plan);
|
|
163
|
+
return rowsOf(terraformPlanDriftChanges(plan, options));
|
|
96
164
|
}
|
|
97
165
|
/** How many objects a plan found drifted: `terraformPlanDriftRows(plan, options).length`. */
|
|
98
166
|
export function terraformPlanDriftCount(plan, options = {}) {
|
package/dist/integrity.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"algorithm": "sha256",
|
|
3
3
|
"artifacts": {
|
|
4
|
-
"manifest.json": "
|
|
4
|
+
"manifest.json": "da6c0e0d6f80c5d1593e0805b276a42bcbcc9ecd52703eba14f1624a2c78bb92",
|
|
5
5
|
"meta.json": "ca3d163bab055381827226140568f3bef7eaac187cebd76878e0b63e9e442356",
|
|
6
6
|
"types/index.d.ts": "022927e6a7b351cc4cf52d5f973f60ccd140e5810e17b32fb8868965aa1db161",
|
|
7
7
|
"rules/plan-before-apply.ts": "7c10245b2c3335253b48ee7d8b075d89f43116bde20313a5d1031b343fef1282",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"rules/tf047.ts": "bfa86f85c4c5efff297280fc2f15104d6319fa96dfc444a31829fb7353224092",
|
|
60
60
|
"skills/chant-terraform.md": "53dd11c7b289652f92fdaf2c03766abda46d8964e31fe709e8b142ced4f19c50"
|
|
61
61
|
},
|
|
62
|
-
"composite": "
|
|
62
|
+
"composite": "f1d5d36796f03ea217a57010c7cc16ca18c64ead1eeeae9426758cf9e1ee6662"
|
|
63
63
|
}
|