diff --git a/config/hcl2shim/flatmap.go b/config/hcl2shim/flatmap.go index e42e3beb9..514368a51 100644 --- a/config/hcl2shim/flatmap.go +++ b/config/hcl2shim/flatmap.go @@ -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)) } diff --git a/config/hcl2shim/flatmap_test.go b/config/hcl2shim/flatmap_test.go index 7b4d822f4..0beeb864f 100644 --- a/config/hcl2shim/flatmap_test.go +++ b/config/hcl2shim/flatmap_test.go @@ -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 {