Merge pull request #28766 from hashicorp/jbardin/deposed-orphan

Fix crash with deposed instances in orphaned resources
This commit is contained in:
James Bardin 2021-05-20 10:56:24 -04:00 committed by GitHub
commit b842360070
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 2 deletions

View File

@ -399,7 +399,6 @@ func (n *NodeAbstractResourceInstance) planDestroy(ctx EvalContext, currentState
Before: cty.NullVal(cty.DynamicPseudoType), Before: cty.NullVal(cty.DynamicPseudoType),
After: cty.NullVal(cty.DynamicPseudoType), After: cty.NullVal(cty.DynamicPseudoType),
}, },
Private: currentState.Private,
ProviderAddr: n.ResolvedProvider, ProviderAddr: n.ResolvedProvider,
} }
return noop, nil return noop, nil

View File

@ -79,7 +79,12 @@ func (t *OrphanResourceInstanceTransformer) transform(g *Graph, ms *states.Modul
} }
} }
for key := range rs.Instances { for key, inst := range rs.Instances {
// deposed instances will be taken care of separately
if inst.Current == nil {
continue
}
addr := rs.Addr.Instance(key) addr := rs.Addr.Instance(key)
abstract := NewNodeAbstractResourceInstance(addr) abstract := NewNodeAbstractResourceInstance(addr)
var node dag.Vertex = abstract var node dag.Vertex = abstract

View File

@ -50,6 +50,26 @@ func TestOrphanResourceInstanceTransformer(t *testing.T) {
Module: addrs.RootModule, Module: addrs.RootModule,
}, },
) )
// A deposed orphan should not be handled by this transformer
s.SetResourceInstanceDeposed(
addrs.Resource{
Mode: addrs.ManagedResourceMode,
Type: "test_instance",
Name: "deposed",
}.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance),
states.NewDeposedKey(),
&states.ResourceInstanceObjectSrc{
AttrsFlat: map[string]string{
"id": "foo",
},
Status: states.ObjectReady,
},
addrs.AbsProviderConfig{
Provider: addrs.NewDefaultProvider("test"),
Module: addrs.RootModule,
},
)
}) })
g := Graph{Path: addrs.RootModuleInstance} g := Graph{Path: addrs.RootModuleInstance}