Merge pull request #25543 from hashicorp/jbardin/prune-root-temps

ensure root module locals and vars are pruned
This commit is contained in:
James Bardin 2020-07-10 14:31:41 -04:00 committed by GitHub
commit 26fb544e43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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