mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-27 09:21:14 -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() {
|
for it.Next() {
|
||||||
kv, ev := it.Element()
|
kv, ev := it.Element()
|
||||||
if ev.IsNull() {
|
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{
|
diags = append(diags, &proto.Diagnostic{
|
||||||
Severity: proto.Diagnostic_ERROR,
|
Severity: proto.Diagnostic_ERROR,
|
||||||
Summary: "Null value found in list",
|
Summary: "Null value found in list",
|
||||||
Detail: "Null values are not allowed for this attribute value.",
|
Detail: "Null values are not allowed for this attribute value.",
|
||||||
Attribute: convert.PathToAttributePath(append(path, cty.IndexStep{Key: kv})),
|
Attribute: convert.PathToAttributePath(p),
|
||||||
})
|
})
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -1352,6 +1352,17 @@ func TestValidateNulls(t *testing.T) {
|
|||||||
}),
|
}),
|
||||||
Err: true,
|
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) {
|
t.Run(strconv.Itoa(i), func(t *testing.T) {
|
||||||
d := validateConfigNulls(tc.Cfg, nil)
|
d := validateConfigNulls(tc.Cfg, nil)
|
||||||
|
Loading…
Reference in New Issue
Block a user