terraform: only omit vars on full destroys

This commit is contained in:
Mitchell Hashimoto 2015-05-06 20:55:14 -07:00
parent 19b33326be
commit 6b2e0b938d
4 changed files with 13 additions and 7 deletions

View File

@ -153,7 +153,7 @@ func (b *BuiltinGraphBuilder) Steps(path []string) []GraphTransformer {
if len(path) <= 1 {
steps = append(steps,
// Create the destruction nodes
&DestroyTransformer{},
&DestroyTransformer{FullDestroy: b.Destroy},
&CreateBeforeDestroyTransformer{},
b.conditional(&conditionalOpts{
If: func() bool { return !b.Verbose },

View File

@ -62,7 +62,7 @@ func (n *GraphNodeConfigOutput) Proxy() bool {
}
// GraphNodeDestroyEdgeInclude impl.
func (n *GraphNodeConfigOutput) DestroyEdgeInclude() bool {
func (n *GraphNodeConfigOutput) DestroyEdgeInclude(bool) bool {
return false
}

View File

@ -56,11 +56,14 @@ func (n *GraphNodeConfigVariable) VariableName() string {
}
// GraphNodeDestroyEdgeInclude impl.
func (n *GraphNodeConfigVariable) DestroyEdgeInclude() bool {
func (n *GraphNodeConfigVariable) DestroyEdgeInclude(full bool) bool {
// Don't include variables as dependencies in destroy nodes.
// Destroy nodes don't interpolate anyways and this has a possibility
// to create cycles. See GH-1835
return false
//
// We include the variable on non-full destroys because it might
// be used for count interpolation.
return !full
}
// GraphNodeProxy impl.

View File

@ -49,12 +49,14 @@ type GraphNodeDestroyPrunable interface {
// as an edge within the destroy graph. This is usually done because it
// might cause unnecessary cycles.
type GraphNodeDestroyEdgeInclude interface {
DestroyEdgeInclude() bool
DestroyEdgeInclude(bool) bool
}
// DestroyTransformer is a GraphTransformer that creates the destruction
// nodes for things that _might_ be destroyed.
type DestroyTransformer struct{}
type DestroyTransformer struct {
FullDestroy bool
}
func (t *DestroyTransformer) Transform(g *Graph) error {
var connect, remove []dag.Edge
@ -111,7 +113,8 @@ func (t *DestroyTransformer) transform(
for _, edgeRaw := range downEdges {
// If this thing specifically requests to not be depended on
// by destroy nodes, then don't.
if i, ok := edgeRaw.(GraphNodeDestroyEdgeInclude); ok && !i.DestroyEdgeInclude() {
if i, ok := edgeRaw.(GraphNodeDestroyEdgeInclude); ok &&
!i.DestroyEdgeInclude(t.FullDestroy) {
continue
}