Skip to content

Commit

Permalink
Make sure outputs are removed when targeting
Browse files Browse the repository at this point in the history
Similar to NodeApplyableOuptut, NodeDestroyableOutputs also need to stay
in the graph if any ancestor nodes

Use the same GraphNodeTargetDownstream method to keep them from being
pruned, since they are dependent on the output node and all its
descendants.
  • Loading branch information
jbardin committed Jan 31, 2018
1 parent ca4178b commit 7fbc35a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
20 changes: 19 additions & 1 deletion terraform/context_apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7741,6 +7741,12 @@ func TestContext2Apply_destroyProvisionerWithOutput(t *testing.T) {
Resources: map[string]*ResourceState{
"aws_instance.foo": resourceState("aws_instance", "1"),
},
Outputs: map[string]*OutputState{
"value": {
Type: "string",
Value: "3",
},
},
},
&ModuleState{
Path: []string{"root", "mod"},
Expand All @@ -7759,18 +7765,30 @@ func TestContext2Apply_destroyProvisionerWithOutput(t *testing.T) {
},
},
Destroy: true,

// targeting the source of the value used by all resources shoudl still
// destroy them all.
Targets: []string{"module.mod.aws_instance.baz"},
})

if _, err := ctx.Plan(); err != nil {
t.Fatal(err)
}

if _, err := ctx.Apply(); err != nil {
state, err := ctx.Apply()
if err != nil {
t.Fatal(err)
}
if !pr.ApplyCalled {
t.Fatal("provisioner not called")
}

// confirm all outputs were removed too
for _, mod := range state.Modules {
if len(mod.Outputs) > 0 {
t.Fatalf("output left in module state: %#v\n", mod)
}
}
}

func TestContext2Apply_targetedDestroyCountDeps(t *testing.T) {
Expand Down
6 changes: 6 additions & 0 deletions terraform/node_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ func (n *NodeDestroyableOutput) RemoveIfNotTargeted() bool {
return true
}

// This will keep the destroy node in the graph if its corresponding output
// node is also in the destroy graph.
func (n *NodeDestroyableOutput) TargetDownstream(targetedDeps, untargetedDeps *dag.Set) bool {
return true
}

// GraphNodeReferencer
func (n *NodeDestroyableOutput) References() []string {
var result []string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ module "mod2" {
source = "./mod2"
value = "${module.mod.value}"
}

output "value" {
value = "${local.value}"
}

0 comments on commit 7fbc35a

Please sign in to comment.