From 70c555cfd39dac207fd6ae9ff8a29b1b59cdfd8c Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Thu, 6 Sep 2018 14:53:40 -0700 Subject: [PATCH] core: EvalDiff to panic earlier if it gets back nil value from provider It's not possible for a normal RPC-based provider to get into this situation because a nil value can't go over the wire, but it's easy to cause this by not correctly configuring a provider mock during tests. By panicking early here we produce a more helpful error message and stack trace than we'd otherwise produce if we let this nil value escape out into the rest of Terraform. --- terraform/eval_diff.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/terraform/eval_diff.go b/terraform/eval_diff.go index 45b458e4ca..93aba85df1 100644 --- a/terraform/eval_diff.go +++ b/terraform/eval_diff.go @@ -164,6 +164,13 @@ func (n *EvalDiff) Eval(ctx EvalContext) (interface{}, error) { plannedNewVal := resp.PlannedState plannedPrivate := resp.PlannedPrivate + if plannedNewVal == cty.NilVal { + // Should never happen. Since real-world providers return via RPC a nil + // is always a bug in the client-side stub. This is more likely caused + // by an incompletely-configured mock provider in tests, though. + panic(fmt.Sprintf("PlanResourceChange of %s produced nil value", absAddr.String())) + } + // We allow the planned new value to disagree with configuration _values_ // here, since that allows the provider to do special logic like a // DiffSuppressFunc, but we still require that the provider produces