Merge pull request #10036 from hashicorp/b-destroy-order
terraform: destroy graph must connect edges for proper target ordering
This commit is contained in:
commit
3b86dff9a2
|
@ -4963,6 +4963,43 @@ aws_instance.bar:
|
|||
`)
|
||||
}
|
||||
|
||||
func TestContext2Apply_targetedDestroyCountDeps(t *testing.T) {
|
||||
m := testModule(t, "apply-destroy-targeted-count")
|
||||
p := testProvider("aws")
|
||||
p.ApplyFn = testApplyFn
|
||||
p.DiffFn = testDiffFn
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Module: m,
|
||||
Providers: map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
},
|
||||
State: &State{
|
||||
Modules: []*ModuleState{
|
||||
&ModuleState{
|
||||
Path: rootModulePath,
|
||||
Resources: map[string]*ResourceState{
|
||||
"aws_instance.foo": resourceState("aws_instance", "i-bcd345"),
|
||||
"aws_instance.bar": resourceState("aws_instance", "i-abc123"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Targets: []string{"aws_instance.foo"},
|
||||
Destroy: true,
|
||||
})
|
||||
|
||||
if _, err := ctx.Plan(); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
state, err := ctx.Apply()
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
checkStateString(t, state, `<no state>`)
|
||||
}
|
||||
|
||||
// https://github.com/hashicorp/terraform/issues/4462
|
||||
func TestContext2Apply_targetedDestroyModule(t *testing.T) {
|
||||
m := testModule(t, "apply-targeted-module")
|
||||
|
|
|
@ -45,12 +45,17 @@ func (b *DestroyPlanGraphBuilder) Steps() []GraphTransformer {
|
|||
State: b.State,
|
||||
},
|
||||
|
||||
// Target
|
||||
&TargetsTransformer{Targets: b.Targets},
|
||||
|
||||
// Attach the configuration to any resources
|
||||
&AttachResourceConfigTransformer{Module: b.Module},
|
||||
|
||||
// Destruction ordering. We require this only so that
|
||||
// targeting below will prune the correct things.
|
||||
&DestroyEdgeTransformer{Module: b.Module, State: b.State},
|
||||
|
||||
// Target. Note we don't set "Destroy: true" here since we already
|
||||
// created proper destroy ordering.
|
||||
&TargetsTransformer{Targets: b.Targets},
|
||||
|
||||
// Single root
|
||||
&RootTransformer{},
|
||||
}
|
||||
|
|
|
@ -10,6 +10,11 @@ type NodePlanDestroyableResource struct {
|
|||
*NodeAbstractResource
|
||||
}
|
||||
|
||||
// GraphNodeDestroyer
|
||||
func (n *NodePlanDestroyableResource) DestroyAddr() *ResourceAddress {
|
||||
return n.Addr
|
||||
}
|
||||
|
||||
// GraphNodeEvalable
|
||||
func (n *NodePlanDestroyableResource) EvalTree() EvalNode {
|
||||
addr := n.NodeAbstractResource.Addr
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
resource "aws_instance" "foo" {
|
||||
count = 3
|
||||
}
|
||||
|
||||
resource "aws_instance" "bar" {
|
||||
instances = ["${aws_instance.foo.*.id}"]
|
||||
}
|
Loading…
Reference in New Issue