From ee49be73be94d947bd75d668080111c8cdbabec1 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Thu, 6 Sep 2018 16:53:46 -0700 Subject: [PATCH] core: Don't panic if ApplyResourceChange returns invalid new value The provider is allowed to return a partial result if it also includes error diagnostics. Real providers still return at least a null value in that case due to the RPC format, but test mocks are often more sloppy. --- terraform/eval_apply.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/terraform/eval_apply.go b/terraform/eval_apply.go index 02cff0d5c..16369745e 100644 --- a/terraform/eval_apply.go +++ b/terraform/eval_apply.go @@ -76,6 +76,13 @@ func (n *EvalApply) Eval(ctx EvalContext) (interface{}, error) { // incomplete. newVal := resp.NewState + // newVal should never be cty.NilVal in a real case, but it can happen + // sometimes in sloppy mocks in tests where error diagnostics are returned + // and the mock implementation doesn't populate the value at all. + if newVal == cty.NilVal { + newVal = cty.NullVal(schema.ImpliedType()) + } + for _, err := range newVal.Type().TestConformance(schema.ImpliedType()) { diags = diags.Append(tfdiags.Sourceless( tfdiags.Error,