forked from hashicorp/terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transform_module.go
47 lines (37 loc) · 970 Bytes
/
transform_module.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package terraform
import (
"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
}
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}
}