diff --git a/ext/typeexpr/get_type.go b/ext/typeexpr/get_type.go index 98a861e9..890cf8ed 100644 --- a/ext/typeexpr/get_type.go +++ b/ext/typeexpr/get_type.go @@ -249,7 +249,7 @@ func getType(expr hcl.Expression, constraint, withDefaults bool) (cty.Type, *Def // If a default is set for an optional attribute, verify that it is // convertible to the attribute type. if defaultVal, ok := defaultValues[attrName]; ok { - _, err := convert.Convert(defaultVal, aty) + convertedDefaultVal, err := convert.Convert(defaultVal, aty) if err != nil { diags = append(diags, &hcl.Diagnostic{ Severity: hcl.DiagError, @@ -258,6 +258,8 @@ func getType(expr hcl.Expression, constraint, withDefaults bool) (cty.Type, *Def Subject: defaultExpr.Range().Ptr(), }) delete(defaultValues, attrName) + } else { + defaultValues[attrName] = convertedDefaultVal } } diff --git a/ext/typeexpr/get_type_test.go b/ext/typeexpr/get_type_test.go index 2dca23d2..0249dffb 100644 --- a/ext/typeexpr/get_type_test.go +++ b/ext/typeexpr/get_type_test.go @@ -504,7 +504,9 @@ func TestGetTypeDefaults(t *testing.T) { }, []string{"b"}), }, []string{"a"}), DefaultValues: map[string]cty.Value{ - "a": cty.EmptyObjectVal, + "a": cty.ObjectVal(map[string]cty.Value{ + "b": cty.NullVal(cty.Number), + }), }, Children: map[string]*Defaults{ "a": {