mirror of
https://github.com/opentffoundation/opentf.git
synced 2026-03-14 04:01:09 -04:00
helper/schema: properly validate sub-resources
This commit is contained in:
@@ -76,6 +76,10 @@ func (r *Resource) InternalValidate() error {
|
||||
}
|
||||
|
||||
switch t := v.Elem.(type) {
|
||||
case *Resource:
|
||||
if err := t.InternalValidate(); err != nil {
|
||||
return err
|
||||
}
|
||||
case *Schema:
|
||||
bad := t.Computed || t.Optional || t.Required
|
||||
if bad {
|
||||
|
||||
@@ -108,6 +108,42 @@ func TestResourceInternalValidate(t *testing.T) {
|
||||
},
|
||||
true,
|
||||
},
|
||||
|
||||
// Sub-resource invalid
|
||||
{
|
||||
&Resource{
|
||||
Schema: map[string]*Schema{
|
||||
"foo": &Schema{
|
||||
Type: TypeList,
|
||||
Elem: &Resource{
|
||||
Schema: map[string]*Schema{
|
||||
"foo": new(Schema),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
true,
|
||||
},
|
||||
|
||||
// Sub-resource valid
|
||||
{
|
||||
&Resource{
|
||||
Schema: map[string]*Schema{
|
||||
"foo": &Schema{
|
||||
Type: TypeList,
|
||||
Elem: &Resource{
|
||||
Schema: map[string]*Schema{
|
||||
"foo": &Schema{
|
||||
Type: TypeInt,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
false,
|
||||
},
|
||||
}
|
||||
|
||||
for i, tc := range cases {
|
||||
|
||||
Reference in New Issue
Block a user