terraform: destroy module nodes show up in plan destroy
This commit is contained in:
parent
e68327e765
commit
480a414c40
|
@ -1582,7 +1582,7 @@ func TestContext2Plan_moduleDestroy(t *testing.T) {
|
|||
actual := strings.TrimSpace(plan.String())
|
||||
expected := strings.TrimSpace(testTerraformPlanModuleDestroyStr)
|
||||
if actual != expected {
|
||||
t.Fatalf("bad:\n%s", actual)
|
||||
t.Fatalf("bad:\n%s\n\nexpected:\n\n%s", actual, expected)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1634,7 +1634,7 @@ func TestContext2Plan_moduleDestroyCycle(t *testing.T) {
|
|||
actual := strings.TrimSpace(plan.String())
|
||||
expected := strings.TrimSpace(testTerraformPlanModuleDestroyCycleStr)
|
||||
if actual != expected {
|
||||
t.Fatalf("bad:\n%s", actual)
|
||||
t.Fatalf("bad:\n%s\n\nexpected:\n\n%s", actual, expected)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1684,7 +1684,7 @@ func TestContext2Plan_moduleDestroyMultivar(t *testing.T) {
|
|||
actual := strings.TrimSpace(plan.String())
|
||||
expected := strings.TrimSpace(testTerraformPlanModuleDestroyMultivarStr)
|
||||
if actual != expected {
|
||||
t.Fatalf("bad:\n%s", actual)
|
||||
t.Fatalf("bad:\n%s\n\nexpected:\n\n%s", actual, expected)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,6 +44,9 @@ func (b *DestroyPlanGraphBuilder) Steps() []GraphTransformer {
|
|||
// Attach the configuration to any resources
|
||||
&AttachResourceConfigTransformer{Module: b.Module},
|
||||
|
||||
// Module destroy nodes
|
||||
&ModuleDestroyTransformer{State: b.State},
|
||||
|
||||
// Single root
|
||||
&RootTransformer{},
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ func (n *GraphNodeConfigModule) Expand(b GraphBuilder) (GraphNodeSubgraph, error
|
|||
|
||||
{
|
||||
// Add the destroy marker to the graph
|
||||
t := &ModuleDestroyTransformer{}
|
||||
t := &ModuleDestroyTransformerOld{}
|
||||
if err := t.Transform(graph); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
package terraform
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// NodeDestroyableModule represents a module destruction.
|
||||
type NodeDestroyableModuleVariable struct {
|
||||
PathValue []string
|
||||
}
|
||||
|
||||
func (n *NodeDestroyableModuleVariable) Name() string {
|
||||
result := "plan-destroy"
|
||||
if len(n.PathValue) > 1 {
|
||||
result = fmt.Sprintf("%s.%s", modulePrefixStr(n.PathValue), result)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// GraphNodeSubPath
|
||||
func (n *NodeDestroyableModuleVariable) Path() []string {
|
||||
return n.PathValue
|
||||
}
|
||||
|
||||
// GraphNodeEvalable
|
||||
func (n *NodeDestroyableModuleVariable) EvalTree() EvalNode {
|
||||
return &EvalDiffDestroyModule{Path: n.PathValue}
|
||||
}
|
|
@ -1,62 +1,37 @@
|
|||
package terraform
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/terraform/dag"
|
||||
)
|
||||
|
||||
// ModuleDestroyTransformer is a GraphTransformer that adds a node
|
||||
// to the graph that will just mark the full module for destroy in
|
||||
// the destroy scenario.
|
||||
type ModuleDestroyTransformer struct{}
|
||||
// to the graph that will add a module destroy node for all modules in
|
||||
// the state.
|
||||
//
|
||||
// NOTE: This is _completely unnecessary_ in the new graph worlds. This is
|
||||
// only done to make old tests pass. However, this node does nothing in
|
||||
// the new apply graph.
|
||||
type ModuleDestroyTransformer struct {
|
||||
State *State
|
||||
}
|
||||
|
||||
func (t *ModuleDestroyTransformer) Transform(g *Graph) error {
|
||||
// Create the node
|
||||
n := &graphNodeModuleDestroy{Path: g.Path}
|
||||
// If empty do nothing
|
||||
if t.State.Empty() {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Add it to the graph. We don't need any edges because
|
||||
// it can happen whenever.
|
||||
g.Add(n)
|
||||
for _, ms := range t.State.Modules {
|
||||
// Just a silly edge case that is required to get old tests to pass.
|
||||
// It is probably a bug with the old graph but we mimic it here
|
||||
// so that old tests pass.
|
||||
if len(ms.Path) <= 1 {
|
||||
continue
|
||||
}
|
||||
|
||||
// Create the node
|
||||
n := &NodeDestroyableModuleVariable{PathValue: ms.Path}
|
||||
|
||||
// Add it to the graph. We don't need any edges because
|
||||
// it can happen whenever.
|
||||
g.Add(n)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type graphNodeModuleDestroy struct {
|
||||
Path []string
|
||||
}
|
||||
|
||||
func (n *graphNodeModuleDestroy) Name() string {
|
||||
return "plan-destroy"
|
||||
}
|
||||
|
||||
// GraphNodeEvalable impl.
|
||||
func (n *graphNodeModuleDestroy) EvalTree() EvalNode {
|
||||
return &EvalOpFilter{
|
||||
Ops: []walkOperation{walkPlanDestroy},
|
||||
Node: &EvalDiffDestroyModule{Path: n.Path},
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
package terraform
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/terraform/dag"
|
||||
)
|
||||
|
||||
// ModuleDestroyTransformer is a GraphTransformer that adds a node
|
||||
// to the graph that will just mark the full module for destroy in
|
||||
// the destroy scenario.
|
||||
type ModuleDestroyTransformerOld struct{}
|
||||
|
||||
func (t *ModuleDestroyTransformerOld) Transform(g *Graph) error {
|
||||
// Create the node
|
||||
n := &graphNodeModuleDestroy{Path: g.Path}
|
||||
|
||||
// Add it to the graph. We don't need any edges because
|
||||
// it can happen whenever.
|
||||
g.Add(n)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type graphNodeModuleDestroy struct {
|
||||
Path []string
|
||||
}
|
||||
|
||||
func (n *graphNodeModuleDestroy) Name() string {
|
||||
return "plan-destroy"
|
||||
}
|
||||
|
||||
// GraphNodeEvalable impl.
|
||||
func (n *graphNodeModuleDestroy) EvalTree() EvalNode {
|
||||
return &EvalOpFilter{
|
||||
Ops: []walkOperation{walkPlanDestroy},
|
||||
Node: &EvalDiffDestroyModule{Path: n.Path},
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
Loading…
Reference in New Issue