mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-25 16:31:10 -06:00
terraform: detect null values in for_each sets
Previously, passing `[null, null]` to `for_each` caused a panic. This commit detects this invalid usage and returns an error instead. Fixes #24047
This commit is contained in:
parent
678760b61a
commit
0ef7d6dea7
@ -89,6 +89,22 @@ func evaluateResourceForEachExpressionKnown(expr hcl.Expression, ctx EvalContext
|
||||
if !forEachVal.IsWhollyKnown() {
|
||||
return map[string]cty.Value{}, false, diags
|
||||
}
|
||||
|
||||
// A set of strings may contain null, which makes it impossible to
|
||||
// convert to a map, so we must return an error
|
||||
it := forEachVal.ElementIterator()
|
||||
for it.Next() {
|
||||
item, _ := it.Element()
|
||||
if item.IsNull() {
|
||||
diags = diags.Append(&hcl.Diagnostic{
|
||||
Severity: hcl.DiagError,
|
||||
Summary: "Invalid for_each set argument",
|
||||
Detail: fmt.Sprintf(`The given "for_each" argument value is unsuitable: "for_each" sets must not contain null values.`),
|
||||
Subject: expr.Range().Ptr(),
|
||||
})
|
||||
return nil, true, diags
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return forEachVal.AsValueMap(), true, nil
|
||||
|
Loading…
Reference in New Issue
Block a user