From a33e4bcdf0ecedd6853239e534256b03479ee045 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 17 Aug 2014 14:33:54 -0700 Subject: [PATCH] helper/schema: properly validate sub-resources --- helper/schema/resource.go | 4 ++++ helper/schema/resource_test.go | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/helper/schema/resource.go b/helper/schema/resource.go index 64ae3fcd3c..0eef486b1e 100644 --- a/helper/schema/resource.go +++ b/helper/schema/resource.go @@ -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 { diff --git a/helper/schema/resource_test.go b/helper/schema/resource_test.go index f0690a65a7..ff76cf6282 100644 --- a/helper/schema/resource_test.go +++ b/helper/schema/resource_test.go @@ -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 {