diff --git a/helper/schema/schema.go b/helper/schema/schema.go index 69c12759c..11906e373 100644 --- a/helper/schema/schema.go +++ b/helper/schema/schema.go @@ -178,14 +178,15 @@ func (m schemaMap) InternalValidate() error { return fmt.Errorf("%s: ComputedWhen can only be set with Computed", k) } - if v.Type == TypeList { + if v.Type == TypeList || v.Type == TypeSet { if v.Elem == nil { return fmt.Errorf("%s: Elem must be set for lists", k) } - // TODO: test - if v.Set != nil { + if v.Type == TypeList && v.Set != nil { return fmt.Errorf("%s: Set can only be set for TypeSet", k) + } else if v.Type == TypeSet && v.Set == nil { + return fmt.Errorf("%s: Set must be set", k) } switch t := v.Elem.(type) { diff --git a/helper/schema/schema_test.go b/helper/schema/schema_test.go index 36ca3bb54..ee06514fe 100644 --- a/helper/schema/schema_test.go +++ b/helper/schema/schema_test.go @@ -784,6 +784,29 @@ func TestSchemaMap_InternalValidate(t *testing.T) { true, }, + // List element with Set set + { + map[string]*Schema{ + "foo": &Schema{ + Type: TypeList, + Elem: &Schema{Type: TypeInt}, + Set: func(interface{}) int { return 0 }, + }, + }, + true, + }, + + // Set element with no Set set + { + map[string]*Schema{ + "foo": &Schema{ + Type: TypeSet, + Elem: &Schema{Type: TypeInt}, + }, + }, + true, + }, + // Required but computed { map[string]*Schema{