From 649f9831e7841062970186e7d2a0933d7ee94a49 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Fri, 15 Sep 2023 14:48:29 -0400 Subject: [PATCH] internal/configs: CoerceValue error for omitted attribute requirements --- internal/configs/configschema/coerce_value.go | 4 +++- internal/configs/configschema/coerce_value_test.go | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/internal/configs/configschema/coerce_value.go b/internal/configs/configschema/coerce_value.go index fec6b35118..9c47257d45 100644 --- a/internal/configs/configschema/coerce_value.go +++ b/internal/configs/configschema/coerce_value.go @@ -67,8 +67,10 @@ func (b *Block) coerceValue(in cty.Value, path cty.Path) (cty.Value, error) { val = in.GetAttr(name) case attrS.Computed || attrS.Optional: val = cty.NullVal(attrType) - default: + case attrS.Required: return cty.UnknownVal(impliedType), path.NewErrorf("attribute %q is required", name) + default: + return cty.UnknownVal(impliedType), path.NewErrorf("attribute %q has none of required, optional, or computed set", name) } val, err := convert.Convert(val, attrConvType) diff --git a/internal/configs/configschema/coerce_value_test.go b/internal/configs/configschema/coerce_value_test.go index 3deeff719b..697724c6c1 100644 --- a/internal/configs/configschema/coerce_value_test.go +++ b/internal/configs/configschema/coerce_value_test.go @@ -446,6 +446,20 @@ func TestCoerceValue(t *testing.T) { }), ``, }, + "omitted attribute requirements": { + &Block{ + Attributes: map[string]*Attribute{ + "foo": { + Type: cty.String, + }, + }, + }, + cty.EmptyObjectVal, + cty.ObjectVal(map[string]cty.Value{ + "foo": cty.UnknownVal(cty.String), + }), + `attribute "foo" has none of required, optional, or computed set`, + }, "dynamic value attributes": { &Block{ BlockTypes: map[string]*NestedBlock{