core: Remove module input transformer

The nodes it adds were immediately skipped by flattening and therefore
never had any effect. That makes the transformer effectively dead code
and removable. This was the only usage of FlattenSkip so we can remove
that as well.
This commit is contained in:
Paul Hinze 2016-04-13 11:14:10 -05:00
parent 012d06489f
commit d992f8d52d
4 changed files with 2 additions and 107 deletions

View File

@ -57,12 +57,6 @@ func (n *GraphNodeConfigModule) Expand(b GraphBuilder) (GraphNodeSubgraph, error
return nil, err
}
// Add the parameters node to the module
t := &ModuleInputTransformer{Variables: make(map[string]string)}
if err := t.Transform(graph); err != nil {
return nil, err
}
{
// Add the destroy marker to the graph
t := &ModuleDestroyTransformer{}
@ -75,7 +69,7 @@ func (n *GraphNodeConfigModule) Expand(b GraphBuilder) (GraphNodeSubgraph, error
return &graphNodeModuleExpanded{
Original: n,
Graph: graph,
Variables: t.Variables,
Variables: make(map[string]string),
}, nil
}
@ -169,11 +163,6 @@ func (n *graphNodeModuleExpanded) FlattenGraph() *Graph {
// flattening. We have to skip some nodes (graphNodeModuleSkippable)
// as well as setup the variable values.
for _, v := range graph.Vertices() {
if sn, ok := v.(graphNodeModuleSkippable); ok && sn.FlattenSkip() {
graph.Remove(v)
continue
}
// If this is a variable, then look it up in the raw configuration.
// If it exists in the raw configuration, set the value of it.
if vn, ok := v.(*GraphNodeConfigVariable); ok && input != nil {
@ -204,12 +193,6 @@ func (n *graphNodeModuleExpanded) Subgraph() *Graph {
return n.Graph
}
// This interface can be implemented to be skipped/ignored when
// flattening the module graph.
type graphNodeModuleSkippable interface {
FlattenSkip() bool
}
func modulePrefixStr(p []string) string {
parts := make([]string, 0, len(p)*2)
for _, p := range p[1:] {

View File

@ -71,8 +71,6 @@ const testGraphNodeModuleExpandStr = `
aws_instance.bar
aws_instance.foo
aws_instance.foo
module inputs
module inputs
plan-destroy
`

View File

@ -2,38 +2,10 @@ package terraform
import (
"fmt"
"github.com/hashicorp/terraform/dag"
)
// ModuleInputTransformer is a GraphTransformer that adds a node to the
// graph for setting the module input variables for the remainder of the
// graph.
type ModuleInputTransformer struct {
Variables map[string]string
}
func (t *ModuleInputTransformer) Transform(g *Graph) error {
// Create the node
n := &graphNodeModuleInput{Variables: t.Variables}
// Add it to the graph
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
}
// ModuleDestroyTransformer is a GraphTransformer that adds a node
// to the graph that will just mark the full module for destroy in
// the destroy scenario.
@ -88,21 +60,3 @@ func (n *graphNodeModuleDestroyFlat) Name() string {
func (n *graphNodeModuleDestroyFlat) Path() []string {
return n.PathValue
}
type graphNodeModuleInput struct {
Variables map[string]string
}
func (n *graphNodeModuleInput) Name() string {
return "module inputs"
}
// GraphNodeEvalable impl.
func (n *graphNodeModuleInput) EvalTree() EvalNode {
return &EvalSetVariables{Variables: n.Variables}
}
// graphNodeModuleSkippable impl.
func (n *graphNodeModuleInput) FlattenSkip() bool {
return true
}

View File

@ -1,41 +1 @@
package terraform
import (
"strings"
"testing"
"github.com/hashicorp/terraform/dag"
)
func TestModuleInputTransformer(t *testing.T) {
var g Graph
g.Add(1)
g.Add(2)
g.Add(3)
g.Connect(dag.BasicEdge(1, 2))
g.Connect(dag.BasicEdge(1, 3))
{
tf := &ModuleInputTransformer{}
if err := tf.Transform(&g); err != nil {
t.Fatalf("err: %s", err)
}
}
actual := strings.TrimSpace(g.String())
expected := strings.TrimSpace(testModuleInputTransformStr)
if actual != expected {
t.Fatalf("bad:\n\n%s", actual)
}
}
const testModuleInputTransformStr = `
1
2
3
2
module inputs
3
module inputs
module inputs
`