mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-25 08:21:07 -06:00
terraform: RootVariableTransform
This commit is contained in:
parent
993c29f34a
commit
0463ad74a8
@ -63,6 +63,9 @@ func (b *ApplyGraphBuilder) Steps() []GraphTransformer {
|
||||
&MissingProvisionerTransformer{Provisioners: b.Provisioners},
|
||||
&ProvisionerTransformer{},
|
||||
|
||||
// Add root variables
|
||||
&RootVariableTransformer{Module: b.Module},
|
||||
|
||||
// Add module variables
|
||||
&ModuleVariableTransformer{Module: b.Module},
|
||||
|
||||
|
22
terraform/node_root_variable.go
Normal file
22
terraform/node_root_variable.go
Normal file
@ -0,0 +1,22 @@
|
||||
package terraform
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/terraform/config"
|
||||
)
|
||||
|
||||
// NodeRootVariable represents a root variable input.
|
||||
type NodeRootVariable struct {
|
||||
Config *config.Variable
|
||||
}
|
||||
|
||||
func (n *NodeRootVariable) Name() string {
|
||||
result := fmt.Sprintf("var.%s", n.Config.Name)
|
||||
return result
|
||||
}
|
||||
|
||||
// GraphNodeReferenceable
|
||||
func (n *NodeRootVariable) ReferenceableName() []string {
|
||||
return []string{n.Name()}
|
||||
}
|
40
terraform/transform_variable.go
Normal file
40
terraform/transform_variable.go
Normal file
@ -0,0 +1,40 @@
|
||||
package terraform
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform/config/module"
|
||||
)
|
||||
|
||||
// RootVariableTransformer is a GraphTransformer that adds all the root
|
||||
// variables to the graph.
|
||||
//
|
||||
// Root variables are currently no-ops but they must be added to the
|
||||
// graph since downstream things that depend on them must be able to
|
||||
// reach them.
|
||||
type RootVariableTransformer struct {
|
||||
Module *module.Tree
|
||||
}
|
||||
|
||||
func (t *RootVariableTransformer) Transform(g *Graph) error {
|
||||
// If no config, no variables
|
||||
if t.Module == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// If we have no vars, we're done!
|
||||
vars := t.Module.Config().Variables
|
||||
if len(vars) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Add all variables here
|
||||
for _, v := range vars {
|
||||
node := &NodeRootVariable{
|
||||
Config: v,
|
||||
}
|
||||
|
||||
// Add it!
|
||||
g.Add(node)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user