mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 01:41:48 -06:00
d060a3d0e8
While we don't have any expansion info during validation, we can try to evaluate variable expressions to catch some basic errors. Do this by creating module instance RepetitionData with unknown values. This unfortunately will still miss the incorrect usage of count/each values, but that would require the module call's each mode, which is not available at this time.
66 lines
1.6 KiB
Go
66 lines
1.6 KiB
Go
package terraform
|
|
|
|
import (
|
|
"github.com/hashicorp/terraform/addrs"
|
|
"github.com/hashicorp/terraform/configs"
|
|
"github.com/hashicorp/terraform/dag"
|
|
)
|
|
|
|
// NodeRootVariable represents a root variable input.
|
|
type NodeRootVariable struct {
|
|
Addr addrs.InputVariable
|
|
Config *configs.Variable
|
|
}
|
|
|
|
var (
|
|
_ GraphNodeModuleInstance = (*NodeRootVariable)(nil)
|
|
_ GraphNodeReferenceable = (*NodeRootVariable)(nil)
|
|
)
|
|
|
|
func (n *NodeRootVariable) Name() string {
|
|
return n.Addr.String()
|
|
}
|
|
|
|
// GraphNodeModuleInstance
|
|
func (n *NodeRootVariable) Path() addrs.ModuleInstance {
|
|
return addrs.RootModuleInstance
|
|
}
|
|
|
|
func (n *NodeRootVariable) ModulePath() addrs.Module {
|
|
return addrs.RootModule
|
|
}
|
|
|
|
// GraphNodeReferenceable
|
|
func (n *NodeRootVariable) ReferenceableAddrs() []addrs.Referenceable {
|
|
return []addrs.Referenceable{n.Addr}
|
|
}
|
|
|
|
// GraphNodeEvalable
|
|
func (n *NodeRootVariable) EvalTree() EvalNode {
|
|
// We don't actually need to _evaluate_ a root module variable, because
|
|
// its value is always constant and already stashed away in our EvalContext.
|
|
// However, we might need to run some user-defined validation rules against
|
|
// the value.
|
|
|
|
if n.Config == nil || len(n.Config.Validations) == 0 {
|
|
return &EvalSequence{} // nothing to do
|
|
}
|
|
|
|
return &evalVariableValidations{
|
|
Addr: addrs.RootModuleInstance.InputVariable(n.Addr.Name),
|
|
Config: n.Config,
|
|
Expr: nil, // not set for root module variables
|
|
}
|
|
}
|
|
|
|
// dag.GraphNodeDotter impl.
|
|
func (n *NodeRootVariable) DotNode(name string, opts *dag.DotOpts) *dag.DotNode {
|
|
return &dag.DotNode{
|
|
Name: name,
|
|
Attrs: map[string]string{
|
|
"label": n.Name(),
|
|
"shape": "note",
|
|
},
|
|
}
|
|
}
|