From 8882dcaf86fc8f24dbf362283b5991261eb834a5 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Thu, 7 Feb 2019 17:33:17 -0800 Subject: [PATCH] core: Fix TestContext2Plan_dataResourceBecomesComputed Now that ProposedNewState uses null to represent Computed attributes not set in the configuration, the provider must fill in the unknown value for "computed" in its plan result. It seems that this test was incorrectly updated during our bulk-fix after integrating the HCL2 work, but it didn't really matter because the ReadDataSource function isn't called in the happy path anyway. But to make the intent clearer here, we also now make ReadDataSource return an error if it is called, making it explicit that no call is expected. --- terraform/context_plan_test.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/terraform/context_plan_test.go b/terraform/context_plan_test.go index f5eadd40b..f95f59068 100644 --- a/terraform/context_plan_test.go +++ b/terraform/context_plan_test.go @@ -1985,8 +1985,12 @@ func TestContext2Plan_dataResourceBecomesComputed(t *testing.T) { } p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse { + fooVal := req.ProposedNewState.GetAttr("foo") return providers.PlanResourceChangeResponse{ - PlannedState: req.ProposedNewState, + PlannedState: cty.ObjectVal(map[string]cty.Value{ + "foo": fooVal, + "computed": cty.UnknownVal(cty.String), + }), PlannedPrivate: req.PriorPrivate, } } @@ -1995,9 +1999,9 @@ func TestContext2Plan_dataResourceBecomesComputed(t *testing.T) { ty := schema.ImpliedType() p.ReadDataSourceResponse = providers.ReadDataSourceResponse{ - State: cty.ObjectVal(map[string]cty.Value{ - "foo": cty.UnknownVal(cty.String), - }), + // This should not be called, because the configuration for the + // data resource contains an unknown value for "foo". + Diagnostics: tfdiags.Diagnostics(nil).Append(fmt.Errorf("ReadDataSource called, but should not have been")), } ctx := testContext2(t, &ContextOpts{