From a104ecb69d284f2bfa55edd66d270bc499f71c1d Mon Sep 17 00:00:00 2001 From: James Bardin Date: Fri, 6 Mar 2020 16:34:18 -0500 Subject: [PATCH] GraphNodeExpand is not used --- terraform/graph.go | 13 ----- terraform/transform_expand.go | 39 --------------- terraform/transform_expand_test.go | 77 ------------------------------ 3 files changed, 129 deletions(-) delete mode 100644 terraform/transform_expand_test.go diff --git a/terraform/graph.go b/terraform/graph.go index 11cec4974..373819f7e 100644 --- a/terraform/graph.go +++ b/terraform/graph.go @@ -101,19 +101,6 @@ func (g *Graph) walk(walker GraphWalker) tfdiags.Diagnostics { log.Printf("[TRACE] vertex %q: produced no dynamic subgraph", dag.VertexName(v)) } } - - // If the node has a subgraph, then walk the subgraph - if sn, ok := v.(GraphNodeSubgraph); ok { - log.Printf("[TRACE] vertex %q: entering static subgraph", dag.VertexName(v)) - - subDiags := sn.Subgraph().(*Graph).walk(walker) - if subDiags.HasErrors() { - log.Printf("[TRACE] vertex %q: static subgraph encountered errors", dag.VertexName(v)) - return - } - log.Printf("[TRACE] vertex %q: static subgraph completed successfully", dag.VertexName(v)) - } - return } diff --git a/terraform/transform_expand.go b/terraform/transform_expand.go index 982c098b8..dca71b630 100644 --- a/terraform/transform_expand.go +++ b/terraform/transform_expand.go @@ -1,18 +1,5 @@ package terraform -import ( - "log" - - "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 { - Expand(GraphBuilder) (GraphNodeSubgraph, error) -} - // 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 @@ -20,29 +7,3 @@ type GraphNodeExpandable interface { type GraphNodeDynamicExpandable interface { DynamicExpand(EvalContext) (*Graph, error) } - -// GraphNodeSubgraph is an interface a node can implement if it has -// a larger subgraph that should be walked. -type GraphNodeSubgraph interface { - Subgraph() dag.Grapher -} - -// 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! - log.Printf("[DEBUG] vertex %q: static expanding", dag.VertexName(ev)) - return ev.Expand(t.Builder) -} diff --git a/terraform/transform_expand_test.go b/terraform/transform_expand_test.go deleted file mode 100644 index d422eddf0..000000000 --- a/terraform/transform_expand_test.go +++ /dev/null @@ -1,77 +0,0 @@ -package terraform - -import ( - "strings" - "testing" - - "github.com/hashicorp/terraform/dag" -) - -func TestExpandTransform_impl(t *testing.T) { - var _ GraphVertexTransformer = new(ExpandTransform) -} - -func TestExpandTransform(t *testing.T) { - var g Graph - g.Add(1) - g.Add(2) - g.Connect(dag.BasicEdge(1, 2)) - - tf := &ExpandTransform{} - out, err := tf.Transform(&testExpandable{ - Result: &g, - }) - if err != nil { - t.Fatalf("err: %s", err) - } - - sn, ok := out.(GraphNodeSubgraph) - if !ok { - t.Fatalf("not subgraph: %#v", out) - } - - actual := strings.TrimSpace(sn.Subgraph().(*Graph).String()) - expected := strings.TrimSpace(testExpandTransformStr) - if actual != expected { - t.Fatalf("bad: %s", actual) - } -} - -func TestExpandTransform_nonExpandable(t *testing.T) { - tf := &ExpandTransform{} - out, err := tf.Transform(42) - if err != nil { - t.Fatalf("err: %s", err) - } - if out != 42 { - t.Fatalf("bad: %#v", out) - } -} - -type testExpandable struct { - // Inputs - Result *Graph - ResultError error - - // Outputs - Builder GraphBuilder -} - -func (n *testExpandable) Expand(b GraphBuilder) (GraphNodeSubgraph, error) { - n.Builder = b - return &testSubgraph{n.Result}, n.ResultError -} - -type testSubgraph struct { - Graph *Graph -} - -func (n *testSubgraph) Subgraph() dag.Grapher { - return n.Graph -} - -const testExpandTransformStr = ` -1 - 2 -2 -`