hashicorp/terraform · critical
invalid element type: %T
Error message
invalid element type: %T
What it means
Panics in serializeCollectionMemberForHash (serialize.go:126). When hashing a list/set member, it requires the Elem to be *Schema or *Resource; any other concrete type (nil, a ValueType, a plain struct) panics with 'invalid element type: %T'.
Source
Thrown at internal/legacy/helper/schema/serialize.go:126
}
buf.WriteString(k)
buf.WriteRune(':')
innerVal := m[k]
SerializeValueForHash(buf, innerVal, innerSchema)
}
}
func serializeCollectionMemberForHash(buf *bytes.Buffer, val interface{}, elem interface{}) {
switch tElem := elem.(type) {
case *Schema:
SerializeValueForHash(buf, val, tElem)
case *Resource:
buf.WriteRune('<')
SerializeResourceForHash(buf, val, tElem)
buf.WriteString(">;")
default:
panic(fmt.Sprintf("invalid element type: %T", tElem))
}
}
View on GitHub (pinned to c9def3e214)
Solutions
- Set Elem to &schema.Schema{...} or &schema.Resource{...} on every list/set.
- Lint schemas for collections whose Elem is not *Schema/*Resource.
Example fix
// before
"rules": { Type: schema.TypeSet, Elem: schema.TypeString },
// after
"rules": { Type: schema.TypeSet, Elem: &schema.Schema{Type: schema.TypeString} }, Defensive patterns
Strategy: type-guard
Validate before calling
func collectionElemOk(s *schema.Schema) bool {
if s.Type != schema.TypeList && s.Type != schema.TypeSet { return true }
switch s.Elem.(type) {
case *schema.Schema, *schema.Resource: return true
}
return false
} Type guard
func isSchemaOrResource(v interface{}) bool {
switch v.(type) {
case *schema.Schema, *schema.Resource: return true
}
return false
} Prevention
- Set Elem to &schema.Schema or &schema.Resource on every list/set.
- Lint collections for invalid Elem types.
When it happens
Trigger: A TypeList/TypeSet whose Elem is nil or a non-Schema/non-Resource value, used as a member of a parent TypeSet that is being hashed.
Common situations: Provider schema bugs: Elem set to a bare ValueType (schema.TypeString) or a plain struct instead of &schema.Schema/&schema.Resource.
Related errors
- unknown value type in TypeMap %T
- unknown schema type to serialize
- missing field in set: %s.%s
- set item just set doesn't exist
- invalid set element type
AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07).
Data as JSON: /api/errors/dbb32cb87e6b1450.
Report an issue: GitHub.