From 7a130f6169ec8fb56fd0e8a233b4e44db72b37f4 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Tue, 29 Oct 2024 12:35:40 -0400 Subject: [PATCH] tests for ephemeral conditions --- .../terraform/context_plan_ephemeral_test.go | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/internal/terraform/context_plan_ephemeral_test.go b/internal/terraform/context_plan_ephemeral_test.go index 730e858957..3e56926022 100644 --- a/internal/terraform/context_plan_ephemeral_test.go +++ b/internal/terraform/context_plan_ephemeral_test.go @@ -425,6 +425,54 @@ module "child" { }) }, }, + "resource precondition": { + module: map[string]string{ + "main.tf": ` +locals { + test_value = 2 +} +ephemeral "ephem_resource" "data" { + lifecycle { + precondition { + condition = local.test_value != 2 + error_message = "value should not be 2" + } + } +} +`, + }, + expectPlanDiagnostics: func(m *configs.Config) (diags tfdiags.Diagnostics) { + return diags.Append(&hcl.Diagnostic{ + Severity: hcl.DiagError, + Summary: "Resource precondition failed", + Detail: "value should not be 2", + }) + }, + }, + "resource postcondition": { + module: map[string]string{ + "main.tf": ` +locals { + test_value = 2 +} +ephemeral "ephem_resource" "data" { + lifecycle { + postcondition { + condition = self.value == "pass" + error_message = "value should be \"pass\"" + } + } +} +`, + }, + expectPlanDiagnostics: func(m *configs.Config) (diags tfdiags.Diagnostics) { + return diags.Append(&hcl.Diagnostic{ + Severity: hcl.DiagError, + Summary: "Resource postcondition failed", + Detail: `value should be "pass"`, + }) + }, + }, } { t.Run(name, func(t *testing.T) { if tc.toBeImplemented {