github.com/kanishk98/terraform@v1.3.0-dev.0.20220917174235-661ca8088a6a/internal/terraform/transform_variable.go (about) 1 package terraform 2 3 import ( 4 "github.com/hashicorp/terraform/internal/addrs" 5 "github.com/hashicorp/terraform/internal/configs" 6 ) 7 8 // RootVariableTransformer is a GraphTransformer that adds all the root 9 // variables to the graph. 10 // 11 // Root variables are currently no-ops but they must be added to the 12 // graph since downstream things that depend on them must be able to 13 // reach them. 14 type RootVariableTransformer struct { 15 Config *configs.Config 16 17 RawValues InputValues 18 } 19 20 func (t *RootVariableTransformer) Transform(g *Graph) error { 21 // We can have no variables if we have no config. 22 if t.Config == nil { 23 return nil 24 } 25 26 // We're only considering root module variables here, since child 27 // module variables are handled by ModuleVariableTransformer. 28 vars := t.Config.Module.Variables 29 30 // Add all variables here 31 for _, v := range vars { 32 node := &NodeRootVariable{ 33 Addr: addrs.InputVariable{ 34 Name: v.Name, 35 }, 36 Config: v, 37 RawValue: t.RawValues[v.Name], 38 } 39 g.Add(node) 40 } 41 42 return nil 43 }