terraform: add module destroy node to graph

This commit is contained in:
Mitchell Hashimoto 2015-05-01 18:26:35 -07:00
parent 1f10dfef2d
commit 23b6acc29d
4 changed files with 39 additions and 23 deletions

View File

@ -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},
},
},
},
},
}
}

View File

@ -73,8 +73,10 @@ aws_instance.bar
aws_instance.foo
module inputs
module inputs
plan-destroy
`
const testGraphNodeModuleExpandFlattenStr = `
aws_instance.foo
plan-destroy
`

View File

@ -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
`

View File

@ -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
}