-
Notifications
You must be signed in to change notification settings - Fork 9.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prune unused resources from graph #2775
Conversation
|
||
// Do a depth first walk from the leaves and remove things. | ||
return g.ReverseDepthFirstWalk(leaves, func(v dag.Vertex, depth int) error { | ||
println("NAME: " + v.(dag.NamedVertex).Name()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stray print here
Clarified that comment, will merge shortly after tests pass. |
(force pushed with a rebase on master to verify that tests still pass with latest core changes) |
LGTM |
Prune unused resources from graph
For `terraform destroy`, we currently build up the same graph we do for `plan` and `apply` and we do a walk with a special Diff that says "destroy everything". We have fought the interpolation subsystem time and again through this code path. Beginning in #2775 we gained a new feature to selectively prune out problematic graph nodes. The past chain of destroy fixes I have been involved with (#6557, #6599, #6753) have attempted to massage the "noop" definitions to properly handle the edge cases reported. "Variable is depended on by provider config" is another edge case we add here and try to fix. This dive only makes me more convinced that the whole `terraform destroy` code path needs to be reworked. For now, I went with a "surgical strike" approach to the problem expressed in #7047. I found a couple of issues with the existing Noop and DestroyEdgeInclude logic, especially with regards to flattening, but I'm explicitly ignoring these for now so we can get this particular bug fixed ahead of the 0.7 release. My hope is that we can circle around with a fully specced initiative to refactor `terraform destroy`'s graph to be more state-derived than config-derived. Until then, this fixes #7407
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Fixes #2766
This is a hammer approach to fixing #2766. I feel compelled to explain why such a change is necessary.
The issue with #2766 is that we're interpolating a module variable during a destroy plan. As such, of course, the interpolation fails (because the data it is interpolating is from a resource that has been destroyed).
In an ideal world, what we want to do is say: don't interpolate if this variable is only used by resources that are being destroyed. But, I couldn't think of any clean way to do this.
This lead to plan B, which is this PR: don't evaluate any nodes that don't need to be evaluated. This is a depth-first optimization that asks every node: are you a noop? if it says yes, it removes it.
This PR makes two prun-able changes:
This fixes the bug and passes all other tests.
I'm fairly confident this won't introduce new bugs, but also confident that by tuning the prunes more carefully, we can probably also remove other bugs.