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.
This commit is contained in:
parent
80ffe0c9fe
commit
bec4641867
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue