mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 01:41:48 -06:00
return a NullVal when presented with a nil flatmap
This allows us to decode the cty.Value back to a nil map, rather than trying to create a map with nil values.
This commit is contained in:
parent
479c6b2466
commit
ac8ee20233
@ -131,6 +131,9 @@ func flatmapValueFromHCL2Seq(m map[string]string, prefix string, val cty.Value)
|
||||
// The result may contain null values if the given map does not contain keys
|
||||
// for all of the different key paths implied by the given type.
|
||||
func HCL2ValueFromFlatmap(m map[string]string, ty cty.Type) (cty.Value, error) {
|
||||
if m == nil {
|
||||
return cty.NullVal(ty), nil
|
||||
}
|
||||
if !ty.IsObjectType() {
|
||||
panic(fmt.Sprintf("HCL2ValueFromFlatmap called on %#v", ty))
|
||||
}
|
||||
|
@ -522,6 +522,19 @@ func TestHCL2ValueFromFlatmap(t *testing.T) {
|
||||
}),
|
||||
WantErr: `invalid count value for "foo." in state: strconv.Atoi: parsing "not-valid": invalid syntax`,
|
||||
},
|
||||
{
|
||||
Flatmap: nil,
|
||||
Type: cty.Object(map[string]cty.Type{
|
||||
"foo": cty.Set(cty.Object(map[string]cty.Type{
|
||||
"bar": cty.String,
|
||||
})),
|
||||
}),
|
||||
Want: cty.NullVal(cty.Object(map[string]cty.Type{
|
||||
"foo": cty.Set(cty.Object(map[string]cty.Type{
|
||||
"bar": cty.String,
|
||||
})),
|
||||
})),
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
|
Loading…
Reference in New Issue
Block a user