6 "github.com/hashicorp/terraform/config"
7 "github.com/hashicorp/terraform/config/module"
10 // NodeApplyableModuleVariable represents a module variable input during
12 type NodeApplyableModuleVariable struct {
14 Config *config.Variable // Config is the var in the config
15 Value *config.RawConfig // Value is the value that is set
17 Module *module.Tree // Antiquated, want to remove
20 func (n *NodeApplyableModuleVariable) Name() string {
21 result := fmt.Sprintf("var.%s", n.Config.Name)
22 if len(n.PathValue) > 1 {
23 result = fmt.Sprintf("%s.%s", modulePrefixStr(n.PathValue), result)
30 func (n *NodeApplyableModuleVariable) Path() []string {
31 // We execute in the parent scope (above our own module) so that
32 // we can access the proper interpolations.
33 if len(n.PathValue) > 2 {
34 return n.PathValue[:len(n.PathValue)-1]
40 // RemovableIfNotTargeted
41 func (n *NodeApplyableModuleVariable) RemoveIfNotTargeted() bool {
42 // We need to add this so that this node will be removed if
43 // it isn't targeted or a dependency of a target.
47 // GraphNodeReferenceGlobal
48 func (n *NodeApplyableModuleVariable) ReferenceGlobal() bool {
49 // We have to create fully qualified references because we cross
50 // boundaries here: our ReferenceableName is in one path and our
51 // References are from another path.
55 // GraphNodeReferenceable
56 func (n *NodeApplyableModuleVariable) ReferenceableName() []string {
57 return []string{n.Name()}
60 // GraphNodeReferencer
61 func (n *NodeApplyableModuleVariable) References() []string {
62 // If we have no value set, we depend on nothing
67 // Can't depend on anything if we're in the root
68 if len(n.PathValue) < 2 {
72 // Otherwise, we depend on anything that is in our value, but
73 // specifically in the namespace of the parent path.
74 // Create the prefix based on the path
76 if p := n.Path(); len(p) > 0 {
77 prefix = modulePrefixStr(p)
80 result := ReferencesFromConfig(n.Value)
81 return modulePrefixList(result, prefix)
85 func (n *NodeApplyableModuleVariable) EvalTree() EvalNode {
86 // If we have no value, do nothing
91 // Otherwise, interpolate the value of this variable and set it
92 // within the variables mapping.
93 var config *ResourceConfig
94 variables := make(map[string]interface{})
104 VariableValues: variables,
107 &EvalCoerceMapVariable{
108 Variables: variables,
109 ModulePath: n.PathValue,
110 ModuleTree: n.Module,
113 &EvalTypeCheckVariable{
114 Variables: variables,
115 ModulePath: n.PathValue,
116 ModuleTree: n.Module,
120 Module: &n.PathValue[len(n.PathValue)-1],
121 Variables: variables,