return a nil flatmap when presented with a NullVal

A nil flatmap will be encoded as a NullVal of the correct type. When
Converting a NullVal back to a flatmap, return nil immediately rather
than attempting to build the values.
This commit is contained in:
James Bardin 2018-07-10 15:51:35 -04:00 committed by Martin Atkins
parent ac8ee20233
commit c28ce02f2a
2 changed files with 12 additions and 0 deletions

View File

@ -21,6 +21,10 @@ import (
// so the given value must not have any maps of complex types or the result
// is undefined.
func FlatmapValueFromHCL2(v cty.Value) map[string]string {
if v.IsNull() {
return nil
}
if !v.Type().IsObjectType() {
panic(fmt.Sprintf("HCL2ValueFromFlatmap called on %#v", v.Type()))
}

View File

@ -228,6 +228,14 @@ func TestFlatmapValueFromHCL2(t *testing.T) {
"foo.0.bap.%": UnknownVariableValue,
},
},
{
cty.NullVal(cty.Object(map[string]cty.Type{
"foo": cty.Set(cty.Object(map[string]cty.Type{
"bar": cty.String,
})),
})),
nil,
},
}
for _, test := range tests {