remove root output eval nodes from destroy

If we're adding a node to remove a root output from the state, the
output itself does not need to be re-evaluated. The exception for root
outputs caused them to be missed when we refactored resource destruction
to only use the existing state.
This commit is contained in:
James Bardin 2020-07-07 11:10:15 -04:00
parent b62640d2d5
commit 2555f6f988
3 changed files with 9 additions and 8 deletions

View File

@ -165,7 +165,7 @@ func (b *ApplyGraphBuilder) Steps() []GraphTransformer {
// directly. A destroy is identical to a normal apply, except for the
// fact that we also have configuration to evaluate. While the rest of
// the unused nodes can be programmatically pruned (via
// pruneUnusedNodesTransformer), root module outputs only have an
// pruneUnusedNodesTransformer), root module outputs always have an
// implied dependency on remote state. This means that if they exist in
// the configuration, the only signal to remove them is via the destroy
// command itself.

View File

@ -207,10 +207,10 @@ func (t *pruneUnusedNodesTransformer) Transform(g *Graph) error {
modules = append(modules, mod)
}
// Sort them by path length, longest first, so that start with the deepest
// modules. The order of modules at the same tree level doesn't matter, we
// just need to ensure that child modules are processed before parent
// modules.
// Sort them by path length, longest first, so that we start with the
// deepest modules. The order of modules at the same tree level doesn't
// matter, we just need to ensure that child modules are processed before
// parent modules.
sort.Slice(modules, func(i, j int) bool {
return len(modules[i].addr) > len(modules[j].addr)
})

View File

@ -88,13 +88,14 @@ func (t *destroyRootOutputTransformer) Transform(g *Graph) error {
deps := g.UpEdges(v)
// the destroy node must depend on the eval node
deps.Add(v)
for _, d := range deps {
log.Printf("[TRACE] %s depends on %s", node.Name(), dag.VertexName(d))
g.Connect(dag.BasicEdge(node, d))
}
// We no longer need the expand node, since we intend to remove this
// output from the state.
g.Remove(v)
}
return nil
}