mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-26 00:41:27 -06:00
Merge pull request #21884 from hashicorp/jbardin/validate-null-diags
don't append nil elements to a diagnostic cty.Path
This commit is contained in:
commit
8e8eb6d6d3
@ -1374,11 +1374,19 @@ func validateConfigNulls(v cty.Value, path cty.Path) []*proto.Diagnostic {
|
||||
for it.Next() {
|
||||
kv, ev := it.Element()
|
||||
if ev.IsNull() {
|
||||
// if this is a set, the kv is also going to be null which
|
||||
// isn't a valid path element, so we can't append it to the
|
||||
// diagnostic.
|
||||
p := path
|
||||
if !kv.IsNull() {
|
||||
p = append(p, cty.IndexStep{Key: kv})
|
||||
}
|
||||
|
||||
diags = append(diags, &proto.Diagnostic{
|
||||
Severity: proto.Diagnostic_ERROR,
|
||||
Summary: "Null value found in list",
|
||||
Detail: "Null values are not allowed for this attribute value.",
|
||||
Attribute: convert.PathToAttributePath(append(path, cty.IndexStep{Key: kv})),
|
||||
Attribute: convert.PathToAttributePath(p),
|
||||
})
|
||||
continue
|
||||
}
|
||||
|
@ -1352,6 +1352,17 @@ func TestValidateNulls(t *testing.T) {
|
||||
}),
|
||||
Err: true,
|
||||
},
|
||||
{
|
||||
Cfg: cty.ObjectVal(map[string]cty.Value{
|
||||
"object": cty.ObjectVal(map[string]cty.Value{
|
||||
"list": cty.SetVal([]cty.Value{
|
||||
cty.StringVal("string"),
|
||||
cty.NullVal(cty.String),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
Err: true,
|
||||
},
|
||||
} {
|
||||
t.Run(strconv.Itoa(i), func(t *testing.T) {
|
||||
d := validateConfigNulls(tc.Cfg, nil)
|
||||
|
Loading…
Reference in New Issue
Block a user