github.com/trawler/terraform@v0.10.8-0.20171106022149-4b1c7a1d9b48/terraform/transform_expand.go (about) 1 package terraform 2 3 import ( 4 "log" 5 6 "github.com/hashicorp/terraform/dag" 7 ) 8 9 // GraphNodeExapndable is an interface that nodes can implement to 10 // signal that they can be expanded. Expanded nodes turn into 11 // GraphNodeSubgraph nodes within the graph. 12 type GraphNodeExpandable interface { 13 Expand(GraphBuilder) (GraphNodeSubgraph, error) 14 } 15 16 // GraphNodeDynamicExpandable is an interface that nodes can implement 17 // to signal that they can be expanded at eval-time (hence dynamic). 18 // These nodes are given the eval context and are expected to return 19 // a new subgraph. 20 type GraphNodeDynamicExpandable interface { 21 DynamicExpand(EvalContext) (*Graph, error) 22 } 23 24 // GraphNodeSubgraph is an interface a node can implement if it has 25 // a larger subgraph that should be walked. 26 type GraphNodeSubgraph interface { 27 Subgraph() dag.Grapher 28 } 29 30 // ExpandTransform is a transformer that does a subgraph expansion 31 // at graph transform time (vs. at eval time). The benefit of earlier 32 // subgraph expansion is that errors with the graph build can be detected 33 // at an earlier stage. 34 type ExpandTransform struct { 35 Builder GraphBuilder 36 } 37 38 func (t *ExpandTransform) Transform(v dag.Vertex) (dag.Vertex, error) { 39 ev, ok := v.(GraphNodeExpandable) 40 if !ok { 41 // This isn't an expandable vertex, so just ignore it. 42 return v, nil 43 } 44 45 // Expand the subgraph! 46 log.Printf("[DEBUG] vertex %q: static expanding", dag.VertexName(ev)) 47 return ev.Expand(t.Builder) 48 }