@intentius/chant-lexicon-terraform 0.124.78 → 0.124.80

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/dist/change-set.d.ts +1 -0
  2. package/dist/change-set.d.ts.map +1 -1
  3. package/dist/change-set.js +19 -0
  4. package/dist/components/capability-plugin.d.ts +75 -2
  5. package/dist/components/capability-plugin.d.ts.map +1 -1
  6. package/dist/components/capability-plugin.js +250 -142
  7. package/dist/components/compose-group.d.ts +2 -1
  8. package/dist/components/compose-group.d.ts.map +1 -1
  9. package/dist/components/compose-group.js +6 -6
  10. package/dist/index.d.ts +1 -1
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +3 -1
  13. package/dist/integrity.json +2 -2
  14. package/dist/manifest.json +1 -1
  15. package/dist/op/activities/terraform.d.ts +33 -0
  16. package/dist/op/activities/terraform.d.ts.map +1 -1
  17. package/dist/op/activities/terraform.js +37 -5
  18. package/dist/state-reads.d.ts +20 -3
  19. package/dist/state-reads.d.ts.map +1 -1
  20. package/dist/state-reads.js +20 -4
  21. package/dist/terragrunt/capability.d.ts +129 -0
  22. package/dist/terragrunt/capability.d.ts.map +1 -0
  23. package/dist/terragrunt/capability.js +352 -0
  24. package/dist/terragrunt/index.d.ts +3 -1
  25. package/dist/terragrunt/index.d.ts.map +1 -1
  26. package/dist/terragrunt/index.js +3 -1
  27. package/dist/terragrunt/units.d.ts +9 -0
  28. package/dist/terragrunt/units.d.ts.map +1 -1
  29. package/dist/terragrunt/units.js +25 -0
  30. package/package.json +2 -2
  31. package/src/change-set.test.ts +27 -1
  32. package/src/change-set.ts +19 -0
  33. package/src/components/capability-plugin.test.ts +61 -6
  34. package/src/components/capability-plugin.ts +290 -139
  35. package/src/components/compose-group.ts +8 -7
  36. package/src/components/compose-op-wave.test.ts +134 -0
  37. package/src/components/terraform-apply-op-wave.test.ts +295 -0
  38. package/src/index.ts +5 -0
  39. package/src/op/activities/terraform.test.ts +21 -0
  40. package/src/op/activities/terraform.ts +64 -4
  41. package/src/state-reads.ts +23 -5
  42. package/src/terragrunt/capability.test.ts +348 -0
  43. package/src/terragrunt/capability.ts +437 -0
  44. package/src/terragrunt/index.ts +3 -1
  45. package/src/terragrunt/units.ts +25 -0
@@ -22,14 +22,17 @@ const planTargets: Array<string[] | undefined> = [];
22
22
  const planTexts: Array<boolean | undefined> = [];
23
23
  // #4463: a plan that fails, as one with a stand-in a validation block rejects does.
24
24
  let planError: Error | undefined;
25
+ // #4842: the env each activity was handed.
26
+ const envs: Array<[string, unknown]> = [];
25
27
 
26
28
  vi.mock("../op/activities/terraform", () => ({
27
29
  // The exit constants exit-codes.ts maps choudoufu's statuses with (#4553), as the module has them.
28
30
  CHOUDOUFU_APPROVAL_EXIT_CODE: 3,
29
31
  CHOUDOUFU_WAVE_EXIT: { landed: 0, error: 1, setMoved: 3, rootFailed: 4 },
30
32
  choudoufuWaveRoot: vi.fn(async () => waveRoot),
31
- choudoufuPlanSet: vi.fn(async (args: { root: string }) => {
33
+ choudoufuPlanSet: vi.fn(async (args: { root: string; env?: unknown }) => {
32
34
  calls.push(`plan-set ${args.root}`);
35
+ envs.push(["plan-set", args.env]);
33
36
  return {
34
37
  setDigest: `sha256:set-${args.root}`,
35
38
  rootDigest: `sha256:root-${args.root}`,
@@ -46,24 +49,28 @@ vi.mock("../op/activities/terraform", () => ({
46
49
  waveApplyArgs.push(args);
47
50
  return waveApply;
48
51
  }),
49
- terraformInit: vi.fn(async (args: { root: string }) => {
52
+ terraformInit: vi.fn(async (args: { root: string; env?: unknown }) => {
50
53
  calls.push(`init ${args.root}`);
54
+ envs.push(["init", args.env]);
51
55
  return { dir: `/x/${args.root}` };
52
56
  }),
53
- terraformPlan: vi.fn(async (args: { root: string; vars?: Record<string, unknown>; targets?: string[]; text?: boolean }) => {
57
+ terraformPlan: vi.fn(async (args: { root: string; vars?: Record<string, unknown>; targets?: string[]; text?: boolean; env?: unknown }) => {
54
58
  calls.push(`plan ${args.root} ${JSON.stringify(args.vars ?? {})}`);
59
+ envs.push(["plan", args.env]);
55
60
  planTargets.push(args.targets);
56
61
  planTexts.push(args.text);
57
62
  if (planError) throw planError;
58
63
  // `dir` as the real result has it (#4545 writes the plan document beside the plan file there).
59
64
  return { planFile: "chant.tfplan", dir: `/x/${args.root}`, planDigest: `jcs1-sha256:${args.root}`, json: planJson, ...(changeSet ? { changeSet } : {}) };
60
65
  }),
61
- terraformApply: vi.fn(async (args: { root: string; planFile: string }) => {
66
+ terraformApply: vi.fn(async (args: { root: string; planFile: string; env?: unknown }) => {
62
67
  calls.push(`apply ${args.root} ${args.planFile}`);
68
+ envs.push(["apply", args.env]);
63
69
  return { planFile: args.planFile, dir: `/x/${args.root}`, ...applyResult };
64
70
  }),
65
- terraformOutputs: vi.fn(async (args: { root: string }) => {
71
+ terraformOutputs: vi.fn(async (args: { root: string; env?: unknown }) => {
66
72
  calls.push(`output ${args.root}`);
73
+ envs.push(["output", args.env]);
67
74
  return { id: `${args.root}-id` };
68
75
  }),
69
76
  }));
@@ -82,6 +89,38 @@ beforeEach(() => {
82
89
  planTargets.length = 0;
83
90
  planTexts.length = 0;
84
91
  planError = undefined;
92
+ envs.length = 0;
93
+ });
94
+
95
+ describe("terraform-apply with a run hook's env and check after init (#4842)", () => {
96
+ const env = { AWS_ROLE_ARN: "arn:aws:iam::1:role/e01" };
97
+
98
+ test("plan and run hand processEnv to init, plan, apply and output, and call afterInit between init and plan", async () => {
99
+ const order: string[] = [];
100
+ const planned = await terraformApplyCapability.plan!({ env: "test", component: "e01", processEnv: env, afterInit: async () => void order.push(`check after ${calls.length} calls`) }, { root: "e01" });
101
+ expect(calls).toEqual(["init e01", "plan e01 {}"]);
102
+ expect(order).toEqual(["check after 1 calls"]);
103
+ await terraformApplyCapability.run({ env: "test", component: "e01", processEnv: env, plans: { e01: planned.artifact } }, { root: "e01" });
104
+ expect(envs).toEqual([["init", env], ["plan", env], ["apply", env], ["output", env]]);
105
+ });
106
+
107
+ test("a check after init that throws stops the plan", async () => {
108
+ await expect(terraformApplyCapability.plan!({ env: "test", component: "e01", afterInit: async () => { throw new Error("a module outside the list"); } }, { root: "e01" })).rejects.toThrow("a module outside the list");
109
+ expect(calls).toEqual(["init e01"]);
110
+ });
111
+
112
+ test("a choudoufu root planned as a one-root set gets the env, and the check before its plan", async () => {
113
+ waveRoot = { wave: true, root: "estates/e01" };
114
+ const order: string[] = [];
115
+ await terraformApplyCapability.plan!({ env: "test", component: "e01", processEnv: env, afterInit: async () => void order.push(`check after ${calls.length} calls`) }, { root: "e01" });
116
+ expect(order).toEqual(["check after 0 calls"]);
117
+ expect(envs).toEqual([["plan-set", env]]);
118
+ });
119
+
120
+ test("without them nothing changes", async () => {
121
+ await terraformApplyCapability.plan!({ env: "test", component: "e01" }, { root: "e01" });
122
+ expect(envs).toEqual([["init", undefined], ["plan", undefined]]);
123
+ });
85
124
  });
86
125
 
87
126
  describe("terraform-apply plans with one show -json (#4479)", () => {
@@ -208,7 +247,7 @@ describe("terraform-apply on a choudoufu root in a gated wave (#3459)", () => {
208
247
 
209
248
  describe("terraform-apply", () => {
210
249
  test("the plugin contributes it", () => {
211
- expect(terraformCapabilityPlugin.capabilities().map((c) => c.kind)).toEqual(["terraform-apply", "terraform-state-unlock", "terraform-state-push", "terraform-copy", "terraform-action"]);
250
+ expect(terraformCapabilityPlugin.capabilities().map((c) => c.kind)).toEqual(["terraform-apply", "terraform-state-unlock", "terraform-state-push", "terraform-copy", "terraform-action", "terragrunt-apply"]);
212
251
  });
213
252
 
214
253
  test("plan inits and plans the root, with its vars, and names the root as the member", async () => {
@@ -486,3 +525,19 @@ describe("terraform-apply previews a root outside a group with placeholders (#44
486
525
  expect(calls.some((c) => c.startsWith("apply"))).toBe(false);
487
526
  });
488
527
  });
528
+
529
+ describe("terraform-apply on a root whose plan changes only outputs (#4849)", () => {
530
+ test("its part names the outputs, so its change set is not empty", async () => {
531
+ const { terraformChangeSetPart } = await import("../change-set");
532
+ const { composeChangeSet, isEmptyChangeSet } = await import("@intentius/chant/change-set");
533
+ const plan = {
534
+ resource_changes: [{ address: "terraform_data.keep", mode: "managed", type: "terraform_data", name: "keep", change: { actions: ["no-op"], before: { input: "a" }, after: { input: "a" }, after_unknown: {} } }],
535
+ output_changes: { url: { actions: ["update"], before: "a", after: "b", after_unknown: false } },
536
+ };
537
+ planJson = plan;
538
+ changeSet = terraformChangeSetPart({ member: "e01", plan }) as unknown as Record<string, unknown>;
539
+ const planned = await terraformApplyCapability.plan!({ env: "test", component: "e01" }, { root: "e01" });
540
+ expect(planned.changeSet?.member.outputs).toEqual(["url"]);
541
+ expect(isEmptyChangeSet(composeChangeSet([planned.changeSet!]))).toBe(false);
542
+ });
543
+ });