run AttachStateTransformer in destroy plan
The AttachStateTransformer was never run in the destroy plan. This means that resource without configuration that used a non-default provider would not be connected to the correct provider for the plan. The test that was attempting to catch this only worked because the temporary graph used in the DestroyEdgeTransformer would add the state and detect some issues.
This commit is contained in:
parent
a0ba481cad
commit
9edb719aaa
|
@ -10236,29 +10236,16 @@ func TestContext2Apply_destroyWithProviders(t *testing.T) {
|
||||||
p.ApplyFn = testApplyFn
|
p.ApplyFn = testApplyFn
|
||||||
p.DiffFn = testDiffFn
|
p.DiffFn = testDiffFn
|
||||||
|
|
||||||
s := MustShimLegacyState(&State{
|
state := states.NewState()
|
||||||
Modules: []*ModuleState{
|
removed := state.EnsureModule(addrs.RootModuleInstance.Child("mod", addrs.NoKey).Child("removed", addrs.NoKey))
|
||||||
&ModuleState{
|
removed.SetResourceInstanceCurrent(
|
||||||
Path: rootModulePath,
|
mustResourceInstanceAddr("aws_instance.child").Resource,
|
||||||
|
&states.ResourceInstanceObjectSrc{
|
||||||
|
Status: states.ObjectReady,
|
||||||
|
AttrsJSON: []byte(`{"id":"bar"}`),
|
||||||
},
|
},
|
||||||
&ModuleState{
|
mustProviderConfig("provider.aws.baz"),
|
||||||
Path: []string{"root", "child"},
|
)
|
||||||
},
|
|
||||||
&ModuleState{
|
|
||||||
Path: []string{"root", "mod", "removed"},
|
|
||||||
Resources: map[string]*ResourceState{
|
|
||||||
"aws_instance.child": &ResourceState{
|
|
||||||
Type: "aws_instance",
|
|
||||||
Primary: &InstanceState{
|
|
||||||
ID: "bar",
|
|
||||||
},
|
|
||||||
// this provider doesn't exist
|
|
||||||
Provider: "provider.aws.baz",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
ctx := testContext2(t, &ContextOpts{
|
ctx := testContext2(t, &ContextOpts{
|
||||||
Config: m,
|
Config: m,
|
||||||
|
@ -10267,7 +10254,7 @@ func TestContext2Apply_destroyWithProviders(t *testing.T) {
|
||||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
State: s,
|
State: state,
|
||||||
Destroy: true,
|
Destroy: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -10277,12 +10264,10 @@ func TestContext2Apply_destroyWithProviders(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// correct the state
|
// correct the state
|
||||||
s.Modules["module.mod.module.removed"].Resources["aws_instance.child"].ProviderConfig = addrs.AbsProviderConfig{
|
state.Modules["module.mod.module.removed"].Resources["aws_instance.child"].ProviderConfig = addrs.ProviderConfig{
|
||||||
Provider: addrs.NewLegacyProvider("aws"),
|
Type: addrs.NewLegacyProvider("aws"),
|
||||||
Module: addrs.RootModuleInstance,
|
|
||||||
Alias: "bar",
|
Alias: "bar",
|
||||||
}
|
}.Absolute(addrs.RootModuleInstance)
|
||||||
|
|
||||||
if _, diags := ctx.Plan(); diags.HasErrors() {
|
if _, diags := ctx.Plan(); diags.HasErrors() {
|
||||||
t.Fatal(diags.Err())
|
t.Fatal(diags.Err())
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,6 +72,9 @@ func (b *DestroyPlanGraphBuilder) Steps() []GraphTransformer {
|
||||||
State: b.State,
|
State: b.State,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Attach the state
|
||||||
|
&AttachStateTransformer{State: b.State},
|
||||||
|
|
||||||
// Attach the configuration to any resources
|
// Attach the configuration to any resources
|
||||||
&AttachResourceConfigTransformer{Config: b.Config},
|
&AttachResourceConfigTransformer{Config: b.Config},
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue