2015-02-07 22:29:55 +01:00
|
|
|
package terraform
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/hashicorp/terraform/dag"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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 {
|
2015-05-01 23:19:32 +02:00
|
|
|
EnterPath([]string) EvalContext
|
|
|
|
ExitPath([]string)
|
2015-02-07 22:29:55 +01:00
|
|
|
EnterVertex(dag.Vertex)
|
2015-02-08 23:00:13 +01:00
|
|
|
ExitVertex(dag.Vertex, error)
|
2015-02-07 22:29:55 +01:00
|
|
|
EnterEvalTree(dag.Vertex, EvalNode) EvalNode
|
2015-02-12 03:00:22 +01:00
|
|
|
ExitEvalTree(dag.Vertex, interface{}, error) error
|
2015-02-07 22:29:55 +01:00
|
|
|
}
|
|
|
|
|
2016-11-03 20:04:04 +01:00
|
|
|
// GrpahWalkerPanicwrapper can be optionally implemented to catch panics
|
|
|
|
// that occur while walking the graph. This is not generally recommended
|
|
|
|
// since panics should crash Terraform and result in a bug report. However,
|
|
|
|
// this is particularly useful for situations like the shadow graph where
|
|
|
|
// you don't ever want to cause a panic.
|
|
|
|
type GraphWalkerPanicwrapper interface {
|
|
|
|
GraphWalker
|
|
|
|
|
|
|
|
// Panic is called when a panic occurs. This will halt the panic from
|
|
|
|
// propogating so if the walker wants it to crash still it should panic
|
|
|
|
// again. This is called from within a defer so runtime/debug.Stack can
|
|
|
|
// be used to get the stack trace of the panic.
|
|
|
|
Panic(dag.Vertex, interface{})
|
|
|
|
}
|
|
|
|
|
|
|
|
// GraphWalkerPanicwrap wraps an existing Graphwalker to wrap and swallow
|
|
|
|
// the panics. This doesn't lose the panics since the panics are still
|
|
|
|
// returned as errors as part of a graph walk.
|
|
|
|
func GraphWalkerPanicwrap(w GraphWalker) GraphWalkerPanicwrapper {
|
|
|
|
return &graphWalkerPanicwrapper{
|
|
|
|
GraphWalker: w,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type graphWalkerPanicwrapper struct {
|
|
|
|
GraphWalker
|
|
|
|
}
|
|
|
|
|
|
|
|
func (graphWalkerPanicwrapper) Panic(dag.Vertex, interface{}) {}
|
|
|
|
|
2015-02-07 22:29:55 +01:00
|
|
|
// 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{}
|
|
|
|
|
2016-11-03 20:04:04 +01:00
|
|
|
func (NullGraphWalker) EnterPath([]string) EvalContext { return new(MockEvalContext) }
|
2015-05-01 23:19:32 +02:00
|
|
|
func (NullGraphWalker) ExitPath([]string) {}
|
2015-02-07 22:29:55 +01:00
|
|
|
func (NullGraphWalker) EnterVertex(dag.Vertex) {}
|
2015-02-08 23:00:13 +01:00
|
|
|
func (NullGraphWalker) ExitVertex(dag.Vertex, error) {}
|
2015-02-07 22:29:55 +01:00
|
|
|
func (NullGraphWalker) EnterEvalTree(v dag.Vertex, n EvalNode) EvalNode { return n }
|
2015-02-12 03:00:22 +01:00
|
|
|
func (NullGraphWalker) ExitEvalTree(dag.Vertex, interface{}, error) error {
|
|
|
|
return nil
|
|
|
|
}
|