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" { 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