6 "github.com/hashicorp/terraform/dag"
9 // GraphTransformer is the interface that transformers implement. This
10 // interface is only for transforms that need entire graph visibility.
11 type GraphTransformer interface {
12 Transform(*Graph) error
15 // GraphVertexTransformer is an interface that transforms a single
16 // Vertex within with graph. This is a specialization of GraphTransformer
17 // that makes it easy to do vertex replacement.
19 // The GraphTransformer that runs through the GraphVertexTransformers is
21 type GraphVertexTransformer interface {
22 Transform(dag.Vertex) (dag.Vertex, error)
25 // GraphTransformIf is a helper function that conditionally returns a
26 // GraphTransformer given. This is useful for calling inline a sequence
27 // of transforms without having to split it up into multiple append() calls.
28 func GraphTransformIf(f func() bool, then GraphTransformer) GraphTransformer {
36 type graphTransformerMulti struct {
37 Transforms []GraphTransformer
40 func (t *graphTransformerMulti) Transform(g *Graph) error {
41 var lastStepStr string
42 for _, t := range t.Transforms {
43 log.Printf("[TRACE] (graphTransformerMulti) Executing graph transform %T", t)
44 if err := t.Transform(g); err != nil {
47 if thisStepStr := g.StringWithNodeTypes(); thisStepStr != lastStepStr {
48 log.Printf("[TRACE] (graphTransformerMulti) Completed graph transform %T with new graph:\n%s------", t, thisStepStr)
49 lastStepStr = thisStepStr
51 log.Printf("[TRACE] (graphTransformerMulti) Completed graph transform %T (no changes)", t)
58 // GraphTransformMulti combines multiple graph transformers into a single
59 // GraphTransformer that runs all the individual graph transformers.
60 func GraphTransformMulti(ts ...GraphTransformer) GraphTransformer {
61 return &graphTransformerMulti{Transforms: ts}