github.com/rmenn/terraform@v0.3.8-0.20150225065417-fc84b3a78802/terraform/transform_module.go (about)

     1  package terraform
     2  
     3  import (
     4  	"github.com/hashicorp/terraform/dag"
     5  )
     6  
     7  // ModuleInputTransformer is a GraphTransformer that adds a node to the
     8  // graph for setting the module input variables for the remainder of the
     9  // graph.
    10  type ModuleInputTransformer struct {
    11  	Variables map[string]string
    12  }
    13  
    14  func (t *ModuleInputTransformer) Transform(g *Graph) error {
    15  	// Create the node
    16  	n := &graphNodeModuleInput{Variables: t.Variables}
    17  
    18  	// Add it to the graph
    19  	g.Add(n)
    20  
    21  	// Connect the inputs to the bottom of the graph so that it happens
    22  	// first.
    23  	for _, v := range g.Vertices() {
    24  		if v == n {
    25  			continue
    26  		}
    27  
    28  		if g.DownEdges(v).Len() == 0 {
    29  			g.Connect(dag.BasicEdge(v, n))
    30  		}
    31  	}
    32  
    33  	return nil
    34  }
    35  
    36  type graphNodeModuleInput struct {
    37  	Variables map[string]string
    38  }
    39  
    40  func (n *graphNodeModuleInput) Name() string {
    41  	return "module inputs"
    42  }
    43  
    44  // GraphNodeEvalable impl.
    45  func (n *graphNodeModuleInput) EvalTree() EvalNode {
    46  	return &EvalSetVariables{Variables: n.Variables}
    47  }