From 3cdb84a814ee09111da6cfd951e4ad4165947f4f Mon Sep 17 00:00:00 2001 From: Samsondeen Dare Date: Thu, 19 Dec 2024 09:36:34 +0100 Subject: [PATCH] minor improvements --- .../plan_mocked_provider_overridden.tftest.hcl | 15 +++++++++++++++ internal/moduletest/eval_context.go | 2 +- internal/providers/mock.go | 4 ++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/internal/command/testdata/test/mocking/tests/plan_mocked_provider_overridden.tftest.hcl b/internal/command/testdata/test/mocking/tests/plan_mocked_provider_overridden.tftest.hcl index 665fb77503f5..354ce2b7b2cf 100644 --- a/internal/command/testdata/test/mocking/tests/plan_mocked_provider_overridden.tftest.hcl +++ b/internal/command/testdata/test/mocking/tests/plan_mocked_provider_overridden.tftest.hcl @@ -24,6 +24,16 @@ mock_provider "test" { } } + +override_resource { + target = test_resource.secondary[0] + override_computed = true + values = { + id = "ssss" + } +} + + variables { instances = 2 child_instances = 1 @@ -37,4 +47,9 @@ run "test" { error_message = "plan should override the value when override_computed is true" } + assert { + condition = test_resource.secondary[0].id == "ssss" + error_message = "plan should override the value when override_computed is true" + } + } diff --git a/internal/moduletest/eval_context.go b/internal/moduletest/eval_context.go index 0c4583b706a8..623d71f4fb4a 100644 --- a/internal/moduletest/eval_context.go +++ b/internal/moduletest/eval_context.go @@ -141,7 +141,7 @@ func (ec *EvalContext) Evaluate() (Status, cty.Value, tfdiags.Diagnostics) { diags = diags.Append(&hcl.Diagnostic{ Severity: hcl.DiagError, Summary: "Unknown condition value", - Detail: "Condition expression could not be evaluated at this time. This means you have executed a `run` block with `command = plan` and one of the values your condition depended on is not known until after the plan has been applied. Either remove this value from your condition, or execute an `apply` command from this `run` block.", + Detail: "Condition expression could not be evaluated at this time. This means you have executed a `run` block with `command = plan` and one of the values your condition depended on is not known until after the plan has been applied. Either remove this value from your condition, or execute an `apply` command from this `run` block. Alternatively, if there is an override for this value, you can make it available during the plan phase by setting `override_computed = true` in the `override_` block.", Subject: rule.Condition.Range().Ptr(), Expression: rule.Condition, EvalContext: hclCtx, diff --git a/internal/providers/mock.go b/internal/providers/mock.go index 9af422e96d20..c23dacf09442 100644 --- a/internal/providers/mock.go +++ b/internal/providers/mock.go @@ -182,8 +182,8 @@ func (m *Mock) PlanResourceChange(request PlanResourceChangeRequest) PlanResourc panic(fmt.Errorf("failed to retrieve schema for resource %s", request.TypeName)) } - // If the provider was overriden in the test (via override_*), the mock provider is not called at all, - // so we can be certain that this provider is not mocked. + // If the provider was overriden via override_* blocks, the mock provider is not called at all, + // so we can continue to make computed values as unknown here (until mock defaults support plan command). value, diags := mocking.PlanComputedValuesForResource(request.ProposedNewState, &mocking.MockedData{ ComputedAsUnknown: true, }, resource.Block)