From 2e489d88f30e9d95efcdc5c43eb304c61a328291 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Tue, 7 Jan 2020 17:49:34 -0500 Subject: [PATCH] update terraform to work with new dag changes Also removing unnecessary uses of the Set.List --- terraform/graph.go | 20 -------------------- terraform/graph_builder.go | 8 -------- terraform/node_output.go | 4 ++-- terraform/transform_destroy_cbd.go | 2 +- terraform/transform_destroy_edge.go | 7 +++---- terraform/transform_output.go | 2 +- terraform/transform_provider.go | 2 +- terraform/transform_reference.go | 2 +- terraform/transform_targets.go | 20 ++++++++++---------- 9 files changed, 19 insertions(+), 48 deletions(-) diff --git a/terraform/graph.go b/terraform/graph.go index 58d45a7b6a..1ac8dac8ba 100644 --- a/terraform/graph.go +++ b/terraform/graph.go @@ -20,11 +20,6 @@ type Graph struct { // Path is the path in the module tree that this Graph represents. Path addrs.ModuleInstance - - // debugName is a name for reference in the debug output. This is usually - // to indicate what topmost builder was, and if this graph is a shadow or - // not. - debugName string } func (g *Graph) DirectedGraph() dag.Grapher { @@ -43,19 +38,10 @@ func (g *Graph) walk(walker GraphWalker) tfdiags.Diagnostics { ctx := walker.EnterPath(g.Path) defer walker.ExitPath(g.Path) - // Get the path for logs - path := ctx.Path().String() - - debugName := "walk-graph.json" - if g.debugName != "" { - debugName = g.debugName + "-" + debugName - } - // Walk the graph. var walkFn dag.WalkFunc walkFn = func(v dag.Vertex) (diags tfdiags.Diagnostics) { log.Printf("[TRACE] vertex %q: starting visit (%T)", dag.VertexName(v), v) - g.DebugVisitInfo(v, g.debugName) defer func() { log.Printf("[TRACE] vertex %q: visit complete", dag.VertexName(v)) @@ -84,8 +70,6 @@ func (g *Graph) walk(walker GraphWalker) tfdiags.Diagnostics { // then callback with the output. log.Printf("[TRACE] vertex %q: evaluating", dag.VertexName(v)) - g.DebugVertexInfo(v, fmt.Sprintf("evaluating %T(%s)", v, path)) - tree = walker.EnterEvalTree(v, tree) output, err := Eval(tree, vertexCtx) diags = diags.Append(walker.ExitEvalTree(v, output, err)) @@ -98,8 +82,6 @@ func (g *Graph) walk(walker GraphWalker) tfdiags.Diagnostics { if ev, ok := v.(GraphNodeDynamicExpandable); ok { log.Printf("[TRACE] vertex %q: expanding dynamic subgraph", dag.VertexName(v)) - g.DebugVertexInfo(v, fmt.Sprintf("expanding %T(%s)", v, path)) - g, err := ev.DynamicExpand(vertexCtx) if err != nil { diags = diags.Append(err) @@ -124,8 +106,6 @@ func (g *Graph) walk(walker GraphWalker) tfdiags.Diagnostics { if sn, ok := v.(GraphNodeSubgraph); ok { log.Printf("[TRACE] vertex %q: entering static subgraph", dag.VertexName(v)) - g.DebugVertexInfo(v, fmt.Sprintf("subgraph: %T(%s)", v, path)) - subDiags := sn.Subgraph().(*Graph).walk(walker) if subDiags.HasErrors() { log.Printf("[TRACE] vertex %q: static subgraph encountered errors", dag.VertexName(v)) diff --git a/terraform/graph_builder.go b/terraform/graph_builder.go index 71b71b7528..f631f83b58 100644 --- a/terraform/graph_builder.go +++ b/terraform/graph_builder.go @@ -46,15 +46,7 @@ func (b *BasicGraphBuilder) Build(path addrs.ModuleInstance) (*Graph, tfdiags.Di stepName = stepName[dot+1:] } - debugOp := g.DebugOperation(stepName, "") err := step.Transform(g) - - errMsg := "" - if err != nil { - errMsg = err.Error() - } - debugOp.End(errMsg) - if thisStepStr := g.StringWithNodeTypes(); thisStepStr != lastStepStr { log.Printf("[TRACE] Completed graph transform %T with new graph:\n%s ------", step, logging.Indent(thisStepStr)) lastStepStr = thisStepStr diff --git a/terraform/node_output.go b/terraform/node_output.go index bb3d065311..94300f27bb 100644 --- a/terraform/node_output.go +++ b/terraform/node_output.go @@ -44,7 +44,7 @@ func (n *NodeApplyableOutput) RemoveIfNotTargeted() bool { } // GraphNodeTargetDownstream -func (n *NodeApplyableOutput) TargetDownstream(targetedDeps, untargetedDeps *dag.Set) bool { +func (n *NodeApplyableOutput) TargetDownstream(targetedDeps, untargetedDeps dag.Set) bool { // If any of the direct dependencies of an output are targeted then // the output must always be targeted as well, so its value will always // be up-to-date at the completion of an apply walk. @@ -172,7 +172,7 @@ func (n *NodeDestroyableOutput) RemoveIfNotTargeted() bool { // This will keep the destroy node in the graph if its corresponding output // node is also in the destroy graph. -func (n *NodeDestroyableOutput) TargetDownstream(targetedDeps, untargetedDeps *dag.Set) bool { +func (n *NodeDestroyableOutput) TargetDownstream(targetedDeps, untargetedDeps dag.Set) bool { return true } diff --git a/terraform/transform_destroy_cbd.go b/terraform/transform_destroy_cbd.go index 0bfcda96ee..948cf0e67f 100644 --- a/terraform/transform_destroy_cbd.go +++ b/terraform/transform_destroy_cbd.go @@ -90,7 +90,7 @@ func (t *ForcedCBDTransformer) hasCBDDescendent(g *Graph, v dag.Vertex) bool { return true } - for _, ov := range s.List() { + for _, ov := range s { dn, ok := ov.(GraphNodeDestroyerCBD) if !ok { continue diff --git a/terraform/transform_destroy_edge.go b/terraform/transform_destroy_edge.go index 5092b3abbb..e3aedab563 100644 --- a/terraform/transform_destroy_edge.go +++ b/terraform/transform_destroy_edge.go @@ -178,12 +178,11 @@ func (t *DestroyEdgeTransformer) pruneResources(g *Graph) error { } // if there are only destroy dependencies, we don't need this node - des, err := g.Descendents(n) + descendents, err := g.Descendents(n) if err != nil { return err } - descendents := des.List() nonDestroyInstanceFound := false for _, v := range descendents { if _, ok := v.(*NodeApplyableResourceInstance); ok { @@ -197,8 +196,8 @@ func (t *DestroyEdgeTransformer) pruneResources(g *Graph) error { } // connect all the through-edges, then delete the node - for _, d := range g.DownEdges(n).List() { - for _, u := range g.UpEdges(n).List() { + for _, d := range g.DownEdges(n) { + for _, u := range g.UpEdges(n) { g.Connect(dag.BasicEdge(u, d)) } } diff --git a/terraform/transform_output.go b/terraform/transform_output.go index f68228b384..7f80e3ec3e 100644 --- a/terraform/transform_output.go +++ b/terraform/transform_output.go @@ -92,7 +92,7 @@ func (t *DestroyOutputTransformer) Transform(g *Graph) error { // the destroy node must depend on the eval node deps.Add(v) - for _, d := range deps.List() { + for _, d := range deps { log.Printf("[TRACE] %s depends on %s", node.Name(), dag.VertexName(d)) g.Connect(dag.BasicEdge(node, d)) } diff --git a/terraform/transform_provider.go b/terraform/transform_provider.go index 98cb7a8a33..ed9ccb63aa 100644 --- a/terraform/transform_provider.go +++ b/terraform/transform_provider.go @@ -242,7 +242,7 @@ func (t *CloseProviderTransformer) Transform(g *Graph) error { g.Connect(dag.BasicEdge(closer, p)) // connect all the provider's resources to the close node - for _, s := range g.UpEdges(p).List() { + for _, s := range g.UpEdges(p) { if _, ok := s.(GraphNodeProviderConsumer); ok { g.Connect(dag.BasicEdge(closer, s)) } diff --git a/terraform/transform_reference.go b/terraform/transform_reference.go index 371265bab9..48d38db4f0 100644 --- a/terraform/transform_reference.go +++ b/terraform/transform_reference.go @@ -137,7 +137,7 @@ func (t AttachDependenciesTransformer) Transform(g *Graph) error { // dedupe addrs when there's multiple instances involved, or // multiple paths in the un-reduced graph depMap := map[string]addrs.AbsResource{} - for _, d := range ans.List() { + for _, d := range ans { var addr addrs.AbsResource switch d := d.(type) { diff --git a/terraform/transform_targets.go b/terraform/transform_targets.go index d25274e68b..80cff53641 100644 --- a/terraform/transform_targets.go +++ b/terraform/transform_targets.go @@ -28,7 +28,7 @@ type GraphNodeTargetable interface { // they must get updated if any of their dependent resources get updated, // which would not normally be true if one of their dependencies were targeted. type GraphNodeTargetDownstream interface { - TargetDownstream(targeted, untargeted *dag.Set) bool + TargetDownstream(targeted, untargeted dag.Set) bool } // TargetsTransformer is a GraphTransformer that, when the user specifies a @@ -79,8 +79,8 @@ func (t *TargetsTransformer) Transform(g *Graph) error { // Returns a set of targeted nodes. A targeted node is either addressed // directly, address indirectly via its container, or it's a dependency of a // targeted node. Destroy mode keeps dependents instead of dependencies. -func (t *TargetsTransformer) selectTargetedNodes(g *Graph, addrs []addrs.Targetable) (*dag.Set, error) { - targetedNodes := new(dag.Set) +func (t *TargetsTransformer) selectTargetedNodes(g *Graph, addrs []addrs.Targetable) (dag.Set, error) { + targetedNodes := make(dag.Set) vertices := g.Vertices() @@ -95,7 +95,7 @@ func (t *TargetsTransformer) selectTargetedNodes(g *Graph, addrs []addrs.Targeta tn.SetTargets(addrs) } - var deps *dag.Set + var deps dag.Set var err error if t.Destroy { deps, err = g.Descendents(v) @@ -106,7 +106,7 @@ func (t *TargetsTransformer) selectTargetedNodes(g *Graph, addrs []addrs.Targeta return nil, err } - for _, d := range deps.List() { + for _, d := range deps { targetedNodes.Add(d) } } @@ -114,7 +114,7 @@ func (t *TargetsTransformer) selectTargetedNodes(g *Graph, addrs []addrs.Targeta return t.addDependencies(targetedNodes, g) } -func (t *TargetsTransformer) addDependencies(targetedNodes *dag.Set, g *Graph) (*dag.Set, error) { +func (t *TargetsTransformer) addDependencies(targetedNodes dag.Set, g *Graph) (dag.Set, error) { // Handle nodes that need to be included if their dependencies are included. // This requires multiple passes since we need to catch transitive // dependencies if and only if they are via other nodes that also @@ -150,7 +150,7 @@ func (t *TargetsTransformer) addDependencies(targetedNodes *dag.Set, g *Graph) ( continue } - for _, dv := range dependers.List() { + for _, dv := range dependers { if targetedNodes.Include(dv) { // Already present, so nothing to do continue @@ -186,14 +186,14 @@ func (t *TargetsTransformer) addDependencies(targetedNodes *dag.Set, g *Graph) ( // This essentially maintains the previous behavior where interpolation in // outputs would fail silently, but can now surface errors where the output // is required. -func filterPartialOutputs(v interface{}, targetedNodes *dag.Set, g *Graph) bool { +func filterPartialOutputs(v interface{}, targetedNodes dag.Set, g *Graph) bool { // should this just be done with TargetDownstream? if _, ok := v.(*NodeApplyableOutput); !ok { return true } dependers := g.UpEdges(v) - for _, d := range dependers.List() { + for _, d := range dependers { if _, ok := d.(*NodeCountBoundary); ok { continue } @@ -210,7 +210,7 @@ func filterPartialOutputs(v interface{}, targetedNodes *dag.Set, g *Graph) bool depends := g.DownEdges(v) - for _, d := range depends.List() { + for _, d := range depends { if !targetedNodes.Include(d) { log.Printf("[WARN] %s missing targeted dependency %s, removing from the graph", dag.VertexName(v), dag.VertexName(d))