ensure root module locals and vars are pruned

The pruneUnusedNodes transformer was skipping root level locals and
variables, causing them to be left in the graph during a full destroy.
Use the return value from temporaryValue to indicate if the node is
truly temporary or not, rather then keeping the entire root module.
This commit is contained in:
James Bardin 2020-07-09 15:54:42 -04:00
parent 0a46ded3e7
commit a0567458e2
2 changed files with 17 additions and 10 deletions

View File

@ -1,11 +1,19 @@
data "test_data_source" "bar" {
for_each = {
a = "b"
}
foo = "zing"
}
data "test_data_source" "foo" { data "test_data_source" "foo" {
for_each = data.test_data_source.bar
foo = "ok" foo = "ok"
} }
locals { locals {
l = [ l = [
{ {
name = data.test_data_source.foo.id name = data.test_data_source.foo["a"].id
val = "null" val = "null"
}, },
] ]

View File

@ -252,17 +252,16 @@ func (m *pruneUnusedNodesMod) removeUnused(g *Graph) {
// dealing with complex looping and labels // dealing with complex looping and labels
func() { func() {
n := nodes[i] n := nodes[i]
switch n.(type) { switch n := n.(type) {
case graphNodeTemporaryValue: case graphNodeTemporaryValue:
// temporary value, which consist of variables, locals, and // root module outputs indicate they are not temporary by
// outputs, must be kept if anything refers to them. // returning false here.
if n, ok := n.(GraphNodeModulePath); ok { if !n.temporaryValue() {
// root outputs always have an implicit dependency on return
// remote state.
if n.ModulePath().IsRoot() {
return
}
} }
// temporary values, which consist of variables, locals,
// and outputs, must be kept if anything refers to them.
for _, v := range g.UpEdges(n) { for _, v := range g.UpEdges(n) {
// keep any value which is connected through a // keep any value which is connected through a
// reference // reference