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.
This commit is contained in:
Martin Atkins 2018-09-06 14:53:40 -07:00
parent 8cc8bacce3
commit 70c555cfd3
1 changed files with 7 additions and 0 deletions

View File

@ -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