github.com/muratcelep/terraform@v1.1.0-beta2-not-internal-4/not-internal/terraform/node_root_variable.go (about) 1 package terraform 2 3 import ( 4 "github.com/muratcelep/terraform/not-internal/addrs" 5 "github.com/muratcelep/terraform/not-internal/configs" 6 "github.com/muratcelep/terraform/not-internal/dag" 7 "github.com/muratcelep/terraform/not-internal/tfdiags" 8 ) 9 10 // NodeRootVariable represents a root variable input. 11 type NodeRootVariable struct { 12 Addr addrs.InputVariable 13 Config *configs.Variable 14 } 15 16 var ( 17 _ GraphNodeModuleInstance = (*NodeRootVariable)(nil) 18 _ GraphNodeReferenceable = (*NodeRootVariable)(nil) 19 ) 20 21 func (n *NodeRootVariable) Name() string { 22 return n.Addr.String() 23 } 24 25 // GraphNodeModuleInstance 26 func (n *NodeRootVariable) Path() addrs.ModuleInstance { 27 return addrs.RootModuleInstance 28 } 29 30 func (n *NodeRootVariable) ModulePath() addrs.Module { 31 return addrs.RootModule 32 } 33 34 // GraphNodeReferenceable 35 func (n *NodeRootVariable) ReferenceableAddrs() []addrs.Referenceable { 36 return []addrs.Referenceable{n.Addr} 37 } 38 39 // GraphNodeExecutable 40 func (n *NodeRootVariable) Execute(ctx EvalContext, op walkOperation) tfdiags.Diagnostics { 41 // We don't actually need to _evaluate_ a root module variable, because 42 // its value is always constant and already stashed away in our EvalContext. 43 // However, we might need to run some user-defined validation rules against 44 // the value. 45 46 if n.Config == nil || len(n.Config.Validations) == 0 { 47 return nil // nothing to do 48 } 49 50 return evalVariableValidations( 51 addrs.RootModuleInstance.InputVariable(n.Addr.Name), 52 n.Config, 53 nil, // not set for root module variables 54 ctx, 55 ) 56 } 57 58 // dag.GraphNodeDotter impl. 59 func (n *NodeRootVariable) DotNode(name string, opts *dag.DotOpts) *dag.DotNode { 60 return &dag.DotNode{ 61 Name: name, 62 Attrs: map[string]string{ 63 "label": n.Name(), 64 "shape": "note", 65 }, 66 } 67 }