update terraform to work with new dag changes

Also removing unnecessary uses of the Set.List
This commit is contained in:
James Bardin 2020-01-07 17:49:34 -05:00
parent 0c1ab6142b
commit 2e489d88f3
9 changed files with 19 additions and 48 deletions

View File

@ -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))

View File

@ -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

View File

@ -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
}

View File

@ -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

View File

@ -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))
}
}

View File

@ -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))
}

View File

@ -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))
}

View File

@ -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) {

View File

@ -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))