2015-02-07 18:02:45 -06:00
|
|
|
package terraform
|
|
|
|
|
|
|
|
import (
|
2015-02-11 19:47:30 -06:00
|
|
|
"log"
|
|
|
|
|
2015-02-07 18:02:45 -06:00
|
|
|
"github.com/hashicorp/terraform/dag"
|
|
|
|
)
|
|
|
|
|
|
|
|
// GraphNodeExapndable is an interface that nodes can implement to
|
|
|
|
// signal that they can be expanded. Expanded nodes turn into
|
|
|
|
// GraphNodeSubgraph nodes within the graph.
|
|
|
|
type GraphNodeExpandable interface {
|
2015-02-11 19:01:08 -06:00
|
|
|
Expand(GraphBuilder) (GraphNodeSubgraph, error)
|
2015-02-07 18:02:45 -06:00
|
|
|
}
|
|
|
|
|
2015-02-08 16:00:13 -06:00
|
|
|
// GraphNodeDynamicExpandable is an interface that nodes can implement
|
|
|
|
// to signal that they can be expanded at eval-time (hence dynamic).
|
|
|
|
// These nodes are given the eval context and are expected to return
|
|
|
|
// a new subgraph.
|
|
|
|
type GraphNodeDynamicExpandable interface {
|
|
|
|
DynamicExpand(EvalContext) (*Graph, error)
|
|
|
|
}
|
|
|
|
|
2015-02-07 18:02:45 -06:00
|
|
|
// GraphNodeSubgraph is an interface a node can implement if it has
|
|
|
|
// a larger subgraph that should be walked.
|
|
|
|
type GraphNodeSubgraph interface {
|
|
|
|
Subgraph() *Graph
|
|
|
|
}
|
|
|
|
|
|
|
|
// ExpandTransform is a transformer that does a subgraph expansion
|
|
|
|
// at graph transform time (vs. at eval time). The benefit of earlier
|
|
|
|
// subgraph expansion is that errors with the graph build can be detected
|
|
|
|
// at an earlier stage.
|
|
|
|
type ExpandTransform struct {
|
|
|
|
Builder GraphBuilder
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *ExpandTransform) Transform(v dag.Vertex) (dag.Vertex, error) {
|
|
|
|
ev, ok := v.(GraphNodeExpandable)
|
|
|
|
if !ok {
|
|
|
|
// This isn't an expandable vertex, so just ignore it.
|
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Expand the subgraph!
|
2015-02-11 19:47:30 -06:00
|
|
|
log.Printf("[DEBUG] vertex %s: static expanding", dag.VertexName(ev))
|
2015-02-11 19:01:08 -06:00
|
|
|
return ev.Expand(t.Builder)
|
2015-02-07 18:02:45 -06:00
|
|
|
}
|
2015-02-11 19:47:30 -06:00
|
|
|
|
|
|
|
type GraphNodeBasicSubgraph struct {
|
|
|
|
NameValue string
|
|
|
|
Graph *Graph
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *GraphNodeBasicSubgraph) Name() string {
|
|
|
|
return n.NameValue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *GraphNodeBasicSubgraph) Subgraph() *Graph {
|
|
|
|
return n.Graph
|
|
|
|
}
|
2015-05-13 11:33:29 -05:00
|
|
|
|
2015-05-14 22:54:33 -05:00
|
|
|
func (n *GraphNodeBasicSubgraph) FlattenGraph() *Graph {
|
|
|
|
return n.Graph
|
2015-05-13 11:33:29 -05:00
|
|
|
}
|