diff --git a/helper/schema/core_schema.go b/helper/schema/core_schema.go index 00e847a2c9..d6f81027fb 100644 --- a/helper/schema/core_schema.go +++ b/helper/schema/core_schema.go @@ -40,7 +40,7 @@ func (m schemaMap) CoreConfigSchema() *configschema.Block { continue } switch schema.Elem.(type) { - case *Schema: + case *Schema, ValueType: ret.Attributes[name] = schema.coreConfigSchemaAttribute() case *Resource: ret.BlockTypes[name] = schema.coreConfigSchemaBlock() @@ -118,6 +118,10 @@ func (s *Schema) coreConfigSchemaType() cty.Type { switch set := s.Elem.(type) { case *Schema: elemType = set.coreConfigSchemaType() + case ValueType: + // This represents a mistake in the provider code, but it's a + // common one so we'll just shim it. + elemType = (&Schema{Type: set}).coreConfigSchemaType() case *Resource: // In practice we don't actually use this for normal schema // construction because we construct a NestedBlock in that diff --git a/helper/schema/core_schema_test.go b/helper/schema/core_schema_test.go index 8fefc47fc2..6a198b84cb 100644 --- a/helper/schema/core_schema_test.go +++ b/helper/schema/core_schema_test.go @@ -118,6 +118,46 @@ func TestSchemaMapCoreConfigSchema(t *testing.T) { BlockTypes: map[string]*configschema.NestedBlock{}, }, }, + "incorrectly-specified collections": { + // Historically we tolerated setting a type directly as the Elem + // attribute, rather than a Schema object. This is common enough + // in existing provider code that we must support it as an alias + // for a schema object with the given type. + map[string]*Schema{ + "list": { + Type: TypeList, + Required: true, + Elem: TypeInt, + }, + "set": { + Type: TypeSet, + Optional: true, + Elem: TypeString, + }, + "map": { + Type: TypeMap, + Optional: true, + Elem: TypeBool, + }, + }, + &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "list": { + Type: cty.List(cty.Number), + Required: true, + }, + "set": { + Type: cty.Set(cty.String), + Optional: true, + }, + "map": { + Type: cty.Map(cty.Bool), + Optional: true, + }, + }, + BlockTypes: map[string]*configschema.NestedBlock{}, + }, + }, "sub-resource collections": { map[string]*Schema{ "list": {