mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Cover empty sets
This commit is contained in:
parent
4e17209bcc
commit
a25abbe7d8
@ -64,6 +64,12 @@ func evaluateResourceForEachExpressionKnown(expr hcl.Expression, ctx EvalContext
|
|||||||
return nil, true, diags
|
return nil, true, diags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the map is empty ({}), return an empty map, because cty will return nil when representing {} AsValueMap
|
||||||
|
// This also covers an empty set (toset([]))
|
||||||
|
if forEachVal.LengthInt() == 0 {
|
||||||
|
return map[string]cty.Value{}, true, diags
|
||||||
|
}
|
||||||
|
|
||||||
if forEachVal.Type().IsSetType() {
|
if forEachVal.Type().IsSetType() {
|
||||||
if forEachVal.Type().ElementType() != cty.String {
|
if forEachVal.Type().ElementType() != cty.String {
|
||||||
diags = diags.Append(&hcl.Diagnostic{
|
diags = diags.Append(&hcl.Diagnostic{
|
||||||
@ -84,10 +90,5 @@ func evaluateResourceForEachExpressionKnown(expr hcl.Expression, ctx EvalContext
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the map is empty ({}), return an empty map, because cty will return nil when representing {} AsValueMap
|
|
||||||
if forEachVal.LengthInt() == 0 {
|
|
||||||
return map[string]cty.Value{}, true, diags
|
|
||||||
}
|
|
||||||
|
|
||||||
return forEachVal.AsValueMap(), true, nil
|
return forEachVal.AsValueMap(), true, nil
|
||||||
}
|
}
|
||||||
|
@ -338,6 +338,8 @@ var.foo
|
|||||||
const testPlanGraphBuilderForEachStr = `
|
const testPlanGraphBuilderForEachStr = `
|
||||||
aws_instance.bar
|
aws_instance.bar
|
||||||
provider.aws
|
provider.aws
|
||||||
|
aws_instance.bar2
|
||||||
|
provider.aws
|
||||||
aws_instance.bat
|
aws_instance.bat
|
||||||
aws_instance.boo
|
aws_instance.boo
|
||||||
provider.aws
|
provider.aws
|
||||||
@ -349,6 +351,7 @@ aws_instance.foo
|
|||||||
provider.aws
|
provider.aws
|
||||||
meta.count-boundary (EachMode fixup)
|
meta.count-boundary (EachMode fixup)
|
||||||
aws_instance.bar
|
aws_instance.bar
|
||||||
|
aws_instance.bar2
|
||||||
aws_instance.bat
|
aws_instance.bat
|
||||||
aws_instance.baz
|
aws_instance.baz
|
||||||
aws_instance.boo
|
aws_instance.boo
|
||||||
@ -357,6 +360,7 @@ meta.count-boundary (EachMode fixup)
|
|||||||
provider.aws
|
provider.aws
|
||||||
provider.aws (close)
|
provider.aws (close)
|
||||||
aws_instance.bar
|
aws_instance.bar
|
||||||
|
aws_instance.bar2
|
||||||
aws_instance.bat
|
aws_instance.bat
|
||||||
aws_instance.baz
|
aws_instance.baz
|
||||||
aws_instance.boo
|
aws_instance.boo
|
||||||
|
3
terraform/testdata/plan-for-each/main.tf
vendored
3
terraform/testdata/plan-for-each/main.tf
vendored
@ -10,6 +10,9 @@ resource "aws_instance" "foo" {
|
|||||||
|
|
||||||
# sets
|
# sets
|
||||||
resource "aws_instance" "bar" {
|
resource "aws_instance" "bar" {
|
||||||
|
for_each = toset([])
|
||||||
|
}
|
||||||
|
resource "aws_instance" "bar2" {
|
||||||
for_each = toset(list("z", "y", "x"))
|
for_each = toset(list("z", "y", "x"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user