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" {
for_each = data.test_data_source.bar
foo = "ok"
}
locals {
l = [
{
name = data.test_data_source.foo.id
name = data.test_data_source.foo["a"].id
val = "null"
},
]

View File

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