hashicorp/terraform · critical
Unknown type: %s
Error message
Unknown type: %s
What it means
A panic in `MapFieldReader`-style `readPrimitive` (internal/legacy/helper/schema/field_reader.go:342), default branch when `schema.Type` is not TypeBool/TypeInt/TypeFloat/TypeString. The primitive reader only decodes scalar types, so any other (or invalid) Type reaches the panic with 'Unknown type: %s'. Like 973 this reflects a malformed provider schema, but specifically in the legacy map-backed field-reading path.
Source
Thrown at internal/legacy/helper/schema/field_reader.go:342
case TypeInt:
if value == "" {
returnVal = 0
break
}
if computed {
break
}
v, err := strconv.ParseInt(value, 0, 0)
if err != nil {
return nil, err
}
returnVal = int(v)
case TypeString:
returnVal = value
default:
panic(fmt.Sprintf("Unknown type: %s", schema.Type))
}
return returnVal, nil
}
View on GitHub (pinned to c9def3e214)
Solutions
- Audit the provider schema: every field the legacy reader treats as primitive must have Type in {TypeBool, TypeInt, TypeFloat, TypeString}.
- Set or correct the `Type` on the offending attribute.
- Add provider schema-construction tests to catch TypeInvalid before release.
- Reproduce with the provider in isolation to identify the specific attribute, then report/fix in the provider.
Example fix
null
Defensive patterns
Strategy: validation
Validate before calling
// Go (provider): validate scalar schema types are primitive before read
for name, s := range resource.Schema {
if isPrimitiveRead(s) {
switch s.Type {
case schema.TypeString, schema.TypeBool, schema.TypeInt, schema.TypeFloat:
default:
return fmt.Errorf("field %q routed to primitive reader has non-scalar Type %d", name, s.Type)
}
}
} Type guard
// Go: confirm a Type is a primitive scalar
func isScalarType(t schema.ValueType) bool {
switch t { case schema.TypeString, schema.TypeBool, schema.TypeInt, schema.TypeFloat: return true }
return false
} Prevention
- Ensure every field read as a primitive has a scalar Type set.
- Add provider schema tests asserting Types are valid before release.
- Avoid declaring a field as scalar in one place and collection elsewhere.
- Pin SDK versions consistently.
When it happens
Trigger: Terraform reads a primitive field value through the legacy map field reader for a schema attribute whose `Type` is a collection/invalid type rather than a scalar, or whose Type is unset. The reader dispatches scalars to readPrimitive and the bad type falls into the default panic.
Common situations: Provider schema with a field declared as a primitive in one place but a collection elsewhere; TypeInvalid from an unset Type; mismatched schema across SDK versions; reading state/config via legacy paths for a field the schema no longer describes as scalar.
Related errors
AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07).
Data as JSON: /api/errors/a60aca00835d7037.
Report an issue: GitHub.