Skip to content

Commit a33e4bc

Browse files
committed
helper/schema: properly validate sub-resources
1 parent c3f1f49 commit a33e4bc

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

helper/schema/resource.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ func (r *Resource) InternalValidate() error {
7676
}
7777

7878
switch t := v.Elem.(type) {
79+
case *Resource:
80+
if err := t.InternalValidate(); err != nil {
81+
return err
82+
}
7983
case *Schema:
8084
bad := t.Computed || t.Optional || t.Required
8185
if bad {

helper/schema/resource_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,42 @@ func TestResourceInternalValidate(t *testing.T) {
108108
},
109109
true,
110110
},
111+
112+
// Sub-resource invalid
113+
{
114+
&Resource{
115+
Schema: map[string]*Schema{
116+
"foo": &Schema{
117+
Type: TypeList,
118+
Elem: &Resource{
119+
Schema: map[string]*Schema{
120+
"foo": new(Schema),
121+
},
122+
},
123+
},
124+
},
125+
},
126+
true,
127+
},
128+
129+
// Sub-resource valid
130+
{
131+
&Resource{
132+
Schema: map[string]*Schema{
133+
"foo": &Schema{
134+
Type: TypeList,
135+
Elem: &Resource{
136+
Schema: map[string]*Schema{
137+
"foo": &Schema{
138+
Type: TypeInt,
139+
},
140+
},
141+
},
142+
},
143+
},
144+
},
145+
false,
146+
},
111147
}
112148

113149
for i, tc := range cases {

0 commit comments

Comments
 (0)