From bec4641867b47b660a6254cda67d29e1a7f88756 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Tue, 14 May 2019 16:09:19 -0700 Subject: [PATCH] core: Don't panic if NodeApplyableResourceInstance has no config This is a "should never happen" case, because we shouldn't ever have resources in the plan that aren't in the configuration, but since we've got a report of a crash here (which went away before we got a chance to debug it) here's just an extra guard to ensure that we'll still exit gracefully in that case. If we see this error crop up again in future, it'd be nice to gather a full trace log so we can see what GraphNodeAttachResourceConfig did and why it did not attach a configuration. --- terraform/node_resource_apply_instance.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/terraform/node_resource_apply_instance.go b/terraform/node_resource_apply_instance.go index 4209605e2..dad7bfc5f 100644 --- a/terraform/node_resource_apply_instance.go +++ b/terraform/node_resource_apply_instance.go @@ -10,6 +10,7 @@ import ( "github.com/hashicorp/terraform/plans" "github.com/hashicorp/terraform/providers" "github.com/hashicorp/terraform/states" + "github.com/hashicorp/terraform/tfdiags" ) // NodeApplyableResourceInstance represents a resource instance that is @@ -107,6 +108,27 @@ func (n *NodeApplyableResourceInstance) EvalTree() EvalNode { // Determine the dependencies for the state. stateDeps := n.StateReferences() + if n.Config == nil { + // This should not be possible, but we've got here in at least one + // case as discussed in the following issue: + // https://github.com/hashicorp/terraform/issues/21258 + // To avoid an outright crash here, we'll instead return an explicit + // error. + var diags tfdiags.Diagnostics + diags = diags.Append(tfdiags.Sourceless( + tfdiags.Error, + "Resource node has no configuration attached", + fmt.Sprintf( + "The graph node for %s has no configuration attached to it. This suggests a bug in Terraform's apply graph builder; please report it!", + addr, + ), + )) + err := diags.Err() + return &EvalReturnError{ + Error: &err, + } + } + // Eval info is different depending on what kind of resource this is switch n.Config.Mode { case addrs.ManagedResourceMode: