Merge pull request #28043 from hashicorp/jbardin/missing-deposed-state
do not panic if there is no deposed state
This commit is contained in:
commit
c5428959b5
|
@ -159,6 +159,11 @@ func (n *NodeDestroyDeposedResourceInstanceObject) Execute(ctx EvalContext, op w
|
||||||
return diags.Append(err)
|
return diags.Append(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if state == nil {
|
||||||
|
diags = diags.Append(fmt.Errorf("missing deposed state for %s (%s)", n.Addr, n.DeposedKey))
|
||||||
|
return diags
|
||||||
|
}
|
||||||
|
|
||||||
change, destroyPlanDiags := n.planDestroy(ctx, state, n.DeposedKey)
|
change, destroyPlanDiags := n.planDestroy(ctx, state, n.DeposedKey)
|
||||||
diags = diags.Append(destroyPlanDiags)
|
diags = diags.Append(destroyPlanDiags)
|
||||||
if diags.HasErrors() {
|
if diags.HasErrors() {
|
||||||
|
|
|
@ -176,3 +176,28 @@ aws_instance.foo: (1 deposed)
|
||||||
Deposed ID 1 = i-abc123
|
Deposed ID 1 = i-abc123
|
||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNodeDestroyDeposedResourceInstanceObject_ExecuteMissingState(t *testing.T) {
|
||||||
|
p := simpleMockProvider()
|
||||||
|
ctx := &MockEvalContext{
|
||||||
|
StateState: states.NewState().SyncWrapper(),
|
||||||
|
ProviderProvider: simpleMockProvider(),
|
||||||
|
ProviderSchemaSchema: p.ProviderSchema(),
|
||||||
|
ChangesChanges: plans.NewChanges().SyncWrapper(),
|
||||||
|
}
|
||||||
|
|
||||||
|
node := NodeDestroyDeposedResourceInstanceObject{
|
||||||
|
NodeAbstractResourceInstance: &NodeAbstractResourceInstance{
|
||||||
|
Addr: mustResourceInstanceAddr("test_object.foo"),
|
||||||
|
NodeAbstractResource: NodeAbstractResource{
|
||||||
|
ResolvedProvider: mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
DeposedKey: states.NewDeposedKey(),
|
||||||
|
}
|
||||||
|
err := node.Execute(ctx, walkApply)
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("expected error")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue