mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-14 01:13:59 -06:00
This introduces a new GraphNode, GraphNodeExecutable, which will gradually replace GraphNodeEvalable as part of the overall removal of EvalTree()s. Terraform's Graph.walk function will now check if a node is GraphNodeExecutable and run walker.Execute instead of running through the EvalTree() and Eval(). For the time being, terraform will panic if a node implements both GraphNodeExecutable and GraphNodeEvalable. This will be removed when we've finished removing all GraphNodeEvalable implementations. The new GraphWalker function, Execute(), is meant to replace both EnterEvalTree and ExitEvalTree, and wraps the call to the GraphNodeExecutable's Execute function.
33 lines
1.4 KiB
Go
33 lines
1.4 KiB
Go
package terraform
|
|
|
|
import (
|
|
"github.com/hashicorp/terraform/addrs"
|
|
"github.com/hashicorp/terraform/dag"
|
|
"github.com/hashicorp/terraform/tfdiags"
|
|
)
|
|
|
|
// GraphWalker is an interface that can be implemented that when used
|
|
// with Graph.Walk will invoke the given callbacks under certain events.
|
|
type GraphWalker interface {
|
|
EvalContext() EvalContext
|
|
EnterPath(addrs.ModuleInstance) EvalContext
|
|
ExitPath(addrs.ModuleInstance)
|
|
EnterEvalTree(dag.Vertex, EvalNode) EvalNode
|
|
ExitEvalTree(dag.Vertex, interface{}, error) tfdiags.Diagnostics
|
|
Execute(EvalContext, GraphNodeExecutable) tfdiags.Diagnostics
|
|
}
|
|
|
|
// NullGraphWalker is a GraphWalker implementation that does nothing.
|
|
// This can be embedded within other GraphWalker implementations for easily
|
|
// implementing all the required functions.
|
|
type NullGraphWalker struct{}
|
|
|
|
func (NullGraphWalker) EvalContext() EvalContext { return new(MockEvalContext) }
|
|
func (NullGraphWalker) EnterPath(addrs.ModuleInstance) EvalContext { return new(MockEvalContext) }
|
|
func (NullGraphWalker) ExitPath(addrs.ModuleInstance) {}
|
|
func (NullGraphWalker) EnterEvalTree(v dag.Vertex, n EvalNode) EvalNode { return n }
|
|
func (NullGraphWalker) ExitEvalTree(dag.Vertex, interface{}, error) tfdiags.Diagnostics {
|
|
return nil
|
|
}
|
|
func (NullGraphWalker) Execute(EvalContext, GraphNodeExecutable) tfdiags.Diagnostics { return nil }
|