Move things around, add test for resource references

This commit is contained in:
Pam Selle 2019-08-28 14:02:11 -04:00
parent 0f3d8b4884
commit 35016a5ea3
3 changed files with 34 additions and 2 deletions

View File

@ -50,7 +50,7 @@ func evaluateResourceForEachExpressionKnown(expr hcl.Expression, ctx EvalContext
Subject: expr.Range().Ptr(),
})
return nil, true, diags
case !forEachVal.IsWhollyKnown():
case !forEachVal.IsKnown():
return map[string]cty.Value{}, false, diags
}
@ -74,6 +74,11 @@ func evaluateResourceForEachExpressionKnown(expr hcl.Expression, ctx EvalContext
})
return nil, true, diags
}
// For sets, we need to recursively check ...and add reasoning why this works here
if !forEachVal.IsWhollyKnown() {
return map[string]cty.Value{}, false, diags
}
}
// If the map is empty ({}), return an empty map, because cty will return nil when representing {} AsValueMap

View File

@ -553,7 +553,25 @@ aws_instance.foo["e30a7edcc42a846684f2a4eea5f3cd261d33c46d"]:
ID = foo
provider = provider.aws
foo = foo
type = aws_instance`
type = aws_instance
aws_instance.one["a"]:
ID = foo
provider = provider.aws
aws_instance.one["b"]:
ID = foo
provider = provider.aws
aws_instance.two["a"]:
ID = foo
provider = provider.aws
Dependencies:
aws_instance.one
aws_instance.two["b"]:
ID = foo
provider = provider.aws
Dependencies:
aws_instance.one`
const testTerraformApplyMinimalStr = `
aws_instance.bar:
ID = foo

View File

@ -9,3 +9,12 @@ resource "aws_instance" "foo" {
)
foo = "foo"
}
# referencing another resource, which means it has some unknown values in it
resource "aws_instance" "one" {
for_each = toset(["a", "b"])
}
resource "aws_instance" "two" {
for_each = aws_instance.one
}