hashicorp/terraform · error
expected type of to be int
Error message
expected type of %s to be int
What it means
Thrown by the ValidateFunc for the 'session_expiration' field in the OSS backend schema when the value cannot be type-asserted to int. Since the field is declared as schema.TypeInt, the Terraform SDK should always deliver an int, making this a defensive guard against unexpected internal type mismatches.
Solutions
- Ensure you are using a compatible version of Terraform/OpenTofu that aligns with this backend's SDK version.
- If the value is coming from a variable, ensure the variable type is declared as number/integer, not string.
- Report a bug if this triggers with a well-formed HCL configuration — it indicates an SDK-level type issue.
Example fix
// Ensure session_expiration is set as an integer in HCL:
terraform {
backend "oss" {
// before (string — should never parse this way with TypeInt)
session_expiration = "3600"
// after
session_expiration = 3600
}
} Defensive patterns
Strategy: type-guard
Validate before calling
// This is a ValidateFunc guard — pre-validation happens at Terraform's schema level. // Ensure the HCL value is an integer: // session_expiration = 3600 (correct) // session_expiration = "3600" (may trigger type issues depending on SDK version)
Type guard
// Type guard for programmatic access to schema validation
func isIntSessionExpiration(v interface{}) bool {
_, ok := v.(int)
return ok
} Prevention
- Always use bare integers (not quoted strings) for integer-type backend attributes in HCL.
- Keep Terraform/OpenTofu version compatible with the backend plugin version.
- If using variables, declare them with type = number.
When it happens
Trigger: The ValidateFunc receives v interface{} where v.(int) fails. With schema.TypeInt declared, this path is essentially unreachable through normal Terraform configuration parsing — it would require a bug in the Terraform core SDK or a programmatic schema injection with a wrong type.
Common situations: Effectively unreachable through normal HCL configuration. Could theoretically surface if a third-party tool or wrapper programmatically constructs the backend schema with incorrect types, or if there's a version mismatch between the OSS backend and the Terraform SDK.
Related errors
- expected to be in the range ( - ), got
- key can not start and end with '/'
- must be a valid ACL value , expected , or , got
- workspace_key_prefix must not start with '/' or './'
- architecture portion must not contain whitespace
AI-assisted analysis of hashicorp/terraform@d32a084675 (2026-08-11).
Data as JSON: /api/errors/f864f4517e8f96c4.
Report an issue: GitHub.
Appendix: source
Thrown at internal/backend/remote-state/oss/backend.go:75
Optional: true,
Description: "The session name to use when assuming the role.",
DefaultFunc: schema.MultiEnvDefaultFunc([]string{"ALICLOUD_ASSUME_ROLE_SESSION_NAME", "ALIBABA_CLOUD_ROLE_SESSION_NAME"}, ""),
},
"policy": {
Type: schema.TypeString,
Optional: true,
Description: "The permissions applied when assuming a role. You cannot use this policy to grant permissions which exceed those of the role that is being assumed.",
},
"session_expiration": {
Type: schema.TypeInt,
Optional: true,
Description: "The time after which the established session for assuming role expires.",
ValidateFunc: func(v interface{}, k string) ([]string, []error) {
min := 900
max := 3600
value, ok := v.(int)
if !ok {
return nil, []error{fmt.Errorf("expected type of %s to be int", k)}
}
if value < min || value > max {
return nil, []error{fmt.Errorf("expected %s to be in the range (%d - %d), got %d", k, min, max, v)}
}
return nil, nil
},
},
},
},
}
}
// New creates a new backend for OSS remote state.
func New() backend.Backend {
s := &schema.Backend{
Schema: map[string]*schema.Schema{View on GitHub (pinned to d32a084675)