diff --git a/terraform/graph_config_node_module.go b/terraform/graph_config_node_module.go index 347c964bd..308b47ca1 100644 --- a/terraform/graph_config_node_module.go +++ b/terraform/graph_config_node_module.go @@ -63,6 +63,14 @@ func (n *GraphNodeConfigModule) Expand(b GraphBuilder) (GraphNodeSubgraph, error return nil, err } + { + // Add the destroy marker to the graph + t := &ModuleDestroyTransformer{} + if err := t.Transform(graph); err != nil { + return nil, err + } + } + // Build the actual subgraph node return &graphNodeModuleExpanded{ Original: n, @@ -148,15 +156,6 @@ func (n *graphNodeModuleExpanded) EvalTree() EvalNode { Config: &resourceConfig, Variables: n.Variables, }, - - &EvalOpFilter{ - Ops: []walkOperation{walkPlanDestroy}, - Node: &EvalSequence{ - Nodes: []EvalNode{ - &EvalDiffDestroyModule{Path: n.Graph.Path}, - }, - }, - }, }, } } diff --git a/terraform/graph_config_node_module_test.go b/terraform/graph_config_node_module_test.go index d3cbdfb1d..6000c20de 100644 --- a/terraform/graph_config_node_module_test.go +++ b/terraform/graph_config_node_module_test.go @@ -73,8 +73,10 @@ aws_instance.bar aws_instance.foo module inputs module inputs +plan-destroy ` const testGraphNodeModuleExpandFlattenStr = ` aws_instance.foo +plan-destroy ` diff --git a/terraform/transform_flatten_test.go b/terraform/transform_flatten_test.go index 749102469..92f7cac7a 100644 --- a/terraform/transform_flatten_test.go +++ b/terraform/transform_flatten_test.go @@ -74,6 +74,7 @@ module.child.aws_instance.child module.child.var.var module.child.output.output module.child.aws_instance.child +module.child.plan-destroy module.child.var.var aws_instance.parent ` @@ -88,6 +89,7 @@ module.child.aws_instance.child module.child.var.var module.child.output.output module.child.aws_instance.child +module.child.plan-destroy module.child.var.var aws_instance.parent ` diff --git a/terraform/transform_module.go b/terraform/transform_module.go index 7154ff70b..ca6586265 100644 --- a/terraform/transform_module.go +++ b/terraform/transform_module.go @@ -1,6 +1,7 @@ package terraform import ( + "fmt" "github.com/hashicorp/terraform/dag" ) @@ -42,21 +43,10 @@ func (t *ModuleDestroyTransformer) Transform(g *Graph) error { // Create the node n := &graphNodeModuleDestroy{Path: g.Path} - // Add it to the graph + // Add it to the graph. We don't need any edges because + // it can happen whenever. g.Add(n) - // Connect the inputs to the bottom of the graph so that it happens - // first. - for _, v := range g.Vertices() { - if v == n { - continue - } - - if g.DownEdges(v).Len() == 0 { - g.Connect(dag.BasicEdge(v, n)) - } - } - return nil } @@ -65,7 +55,7 @@ type graphNodeModuleDestroy struct { } func (n *graphNodeModuleDestroy) Name() string { - return "module destroy (for plan)" + return "plan-destroy" } // GraphNodeEvalable impl. @@ -76,6 +66,29 @@ func (n *graphNodeModuleDestroy) EvalTree() EvalNode { } } +// GraphNodeFlattenable impl. +func (n *graphNodeModuleDestroy) Flatten(p []string) (dag.Vertex, error) { + return &graphNodeModuleDestroyFlat{ + graphNodeModuleDestroy: n, + PathValue: p, + }, nil +} + +type graphNodeModuleDestroyFlat struct { + *graphNodeModuleDestroy + + PathValue []string +} + +func (n *graphNodeModuleDestroyFlat) Name() string { + return fmt.Sprintf( + "%s.%s", modulePrefixStr(n.PathValue), n.graphNodeModuleDestroy.Name()) +} + +func (n *graphNodeModuleDestroyFlat) Path() []string { + return n.PathValue +} + type graphNodeModuleInput struct { Variables map[string]string }