mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-30 10:47:14 -06:00
5b66953d1d
A local value is similar to an output in that it exists only within state and just always evaluates its value as best it can with the current state. Therefore it has a single graph node type for all walks, which will deal with that evaluation operation.
41 lines
818 B
Go
41 lines
818 B
Go
package terraform
|
|
|
|
import (
|
|
"github.com/hashicorp/terraform/config/module"
|
|
)
|
|
|
|
// LocalTransformer is a GraphTransformer that adds all the local values
|
|
// from the configuration to the graph.
|
|
type LocalTransformer struct {
|
|
Module *module.Tree
|
|
}
|
|
|
|
func (t *LocalTransformer) Transform(g *Graph) error {
|
|
return t.transformModule(g, t.Module)
|
|
}
|
|
|
|
func (t *LocalTransformer) transformModule(g *Graph, m *module.Tree) error {
|
|
if m == nil {
|
|
// Can't have any locals if there's no config
|
|
return nil
|
|
}
|
|
|
|
for _, local := range m.Config().Locals {
|
|
node := &NodeLocal{
|
|
PathValue: normalizeModulePath(m.Path()),
|
|
Config: local,
|
|
}
|
|
|
|
g.Add(node)
|
|
}
|
|
|
|
// Also populate locals for child modules
|
|
for _, c := range m.Children() {
|
|
if err := t.transformModule(g, c); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|