hashicorp/terraform · critical
Unknown type: %s
Error message
Unknown type: %s
What it means
A panic in `MapFieldReader.ReadField` (internal/legacy/helper/schema/field_reader_map.go:38), default branch of the switch over `schema.Type`. The flat-map-backed reader dispatches TypeBool/TypeInt/TypeFloat/TypeString/TypeList/TypeMap/TypeSet/typeObject; any other Type panics with 'Unknown type: %s'. This reader is used when a schema is read from a flat key/value map source (e.g. raw state attributes), so the panic reflects a malformed provider schema Type encountered during map-source reads.
Source
Thrown at internal/legacy/helper/schema/field_reader_map.go:38
schemaList := addrToSchema(address, r.Schema)
if len(schemaList) == 0 {
return FieldReadResult{}, nil
}
schema := schemaList[len(schemaList)-1]
switch schema.Type {
case TypeBool, TypeInt, TypeFloat, TypeString:
return r.readPrimitive(address, schema)
case TypeList:
return readListField(r, address, schema)
case TypeMap:
return r.readMap(k, schema)
case TypeSet:
return r.readSet(address, schema)
case typeObject:
return readObjectField(r, address, schema.Elem.(map[string]*Schema))
default:
panic(fmt.Sprintf("Unknown type: %s", schema.Type))
}
}
func (r *MapFieldReader) readMap(k string, schema *Schema) (FieldReadResult, error) {
result := make(map[string]interface{})
resultSet := false
// If the name of the map field is directly in the map with an
// empty string, it means that the map is being deleted, so mark
// that is is set.
if v, ok := r.Map.Access(k); ok && v == "" {
resultSet = true
}
prefix := k + "."
r.Map.Range(func(k, v string) bool {
if strings.HasPrefix(k, prefix) {
resultSet = trueView on GitHub (pinned to c9def3e214)
Solutions
- Audit the provider schema and set a valid Type on every attribute.
- Add provider schema-construction tests asserting no TypeInvalid entries.
- Keep SDK and provider versions in sync.
- If migrating schemas, ensure old flat-map state fields map to attributes with valid Types.
Example fix
null
Defensive patterns
Strategy: validation
Validate before calling
// Go (provider): validate schema Types the map reader will encounter
for name, s := range resource.Schema {
switch s.Type {
case schema.TypeString, schema.TypeBool, schema.TypeInt, schema.TypeFloat,
schema.TypeList, schema.TypeMap, schema.TypeSet:
default:
return fmt.Errorf("map reader cannot handle schema %q Type %d", name, s.Type)
}
} Type guard
// Go: confirm a Type is map-reader-compatible
func mapReadableType(t schema.ValueType) bool {
switch t {
case schema.TypeString, schema.TypeBool, schema.TypeInt, schema.TypeFloat,
schema.TypeList, schema.TypeMap, schema.TypeSet:
return true
}
return false
} Prevention
- Set a valid Type on every schema attribute read from flat-map state.
- Add schema self-tests rejecting TypeInvalid entries.
- Keep SDK and provider versions consistent.
- Ensure legacy flat-map state fields map to attributes with valid Types after migrations.
When it happens
Trigger: Reading a field from a flat map source (KV state attributes) when the schema attribute's Type is outside the recognized ValueType set — unset (TypeInvalid) or an unknown constant.
Common situations: Provider schema with an unset/invalid Type; SDK version drift; reading legacy flat-map state for a field whose schema Type is not a known scalar/collection/object constant.
Related errors
AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07).
Data as JSON: /api/errors/3f7fe502f665b35c.
Report an issue: GitHub.