hashicorp/terraform · critical

invalid Schema.Type %s

Error message

invalid Schema.Type %s

What it means

A panic in `Schema.coreConfigSchemaType` (internal/legacy/helper/schema/core_schema.go:227), the default of the OUTER switch over `s.Type`. If a schema's `Type` is not one of TypeString, TypeBool, TypeInt, TypeFloat, TypeList, TypeSet, or TypeMap, it panics with 'invalid Schema.Type %s'. This is a provider-author bug: the schema declared a Type value outside the valid ValueType enumeration (e.g. the zero value `TypeInvalid`, or an undefined constant).

Source

Thrown at internal/legacy/helper/schema/core_schema.go:227

			}
			// Some pre-existing schemas assume string as default, so we need
			// to be compatible with them.
			elemType = cty.String
		}
		switch s.Type {
		case TypeList:
			return cty.List(elemType)
		case TypeSet:
			return cty.Set(elemType)
		case TypeMap:
			return cty.Map(elemType)
		default:
			// can never get here in practice, due to the case we're inside
			panic("invalid collection type")
		}
	default:
		// should never happen for a valid schema
		panic(fmt.Errorf("invalid Schema.Type %s", s.Type))
	}
}

// CoreConfigSchema is a convenient shortcut for calling CoreConfigSchema on
// the resource's schema. CoreConfigSchema adds the implicitly required "id"
// attribute for top level resources if it doesn't exist.
func (r *Resource) CoreConfigSchema() *configschema.Block {
	block := r.coreConfigSchema()

	if block.Attributes == nil {
		block.Attributes = map[string]*configschema.Attribute{}
	}

	// Add the implicitly required "id" field if it doesn't exist
	if block.Attributes["id"] == nil {
		block.Attributes["id"] = &configschema.Attribute{
			Type:     cty.String,
			Optional: true,

View on GitHub (pinned to c9def3e214)

Solutions

  1. Inspect the provider's schema map for any entry missing an explicit, valid `Type` (TypeString/TypeBool/TypeInt/TypeFloat/TypeList/TypeSet/TypeMap).
  2. Set the `Type` field on the offending schema attribute.
  3. Add a unit test in the provider that builds the schema and asserts no TypeInvalid entries.
  4. Upgrade the provider SDK to a version whose ValueType set matches the code.

Example fix

// before: Type left unset (zero value)
"tags": &schema.Schema{
    Optional: true,
}

// after: explicit Type
"tags": &schema.Schema{
    Type:     schema.TypeMap,
    Optional: true,
    Elem:     &schema.Schema{Type: schema.TypeString},
}
Defensive patterns

Strategy: validation

Validate before calling

// Go (provider): fail fast if any schema attribute has an invalid Type
for name, s := range resource.Schema {
    switch s.Type {
    case schema.TypeString, schema.TypeBool, schema.TypeInt, schema.TypeFloat,
         schema.TypeList, schema.TypeSet, schema.TypeMap:
    default:
        return fmt.Errorf("schema %q has invalid Type %d", name, s.Type)
    }
}

Type guard

// Go: type guard for a valid ValueType
func validSchemaType(s *schema.Schema) bool {
    switch s.Type {
    case schema.TypeString, schema.TypeBool, schema.TypeInt, schema.TypeFloat,
         schema.TypeList, schema.TypeSet, schema.TypeMap:
        return true
    }
    return false
}

Prevention

When it happens

Trigger: A provider resource or data source schema has a field whose `Type` is left unset (defaults to zero value / TypeInvalid) or set to an invalid constant. Terraform panics the first time it converts that schema to a core configschema type (during plan/apply/schema rendering).

Common situations: Provider author forgot to set `Type` on a `*Schema` entry; copy-paste error; a field with only `Computed`/`Optional` but no `Type`; upgrading an SDK where a ValueType constant was removed or renamed.

Related errors


AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07). Data as JSON: /api/errors/996e9567ab48cf3a. Report an issue: GitHub.