{"record":{"id":"f864f4517e8f96c4","repo":"hashicorp/terraform","slug":"expected-type-of-s-to-be-int","errorCode":null,"errorMessage":"expected type of %s to be int","messagePattern":"expected type of (.+?) to be int","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/backend/remote-state/oss/backend.go","lineNumber":75,"sourceCode":"\t\t\t\t\tOptional:    true,\n\t\t\t\t\tDescription: \"The session name to use when assuming the role.\",\n\t\t\t\t\tDefaultFunc: schema.MultiEnvDefaultFunc([]string{\"ALICLOUD_ASSUME_ROLE_SESSION_NAME\", \"ALIBABA_CLOUD_ROLE_SESSION_NAME\"}, \"\"),\n\t\t\t\t},\n\t\t\t\t\"policy\": {\n\t\t\t\t\tType:        schema.TypeString,\n\t\t\t\t\tOptional:    true,\n\t\t\t\t\tDescription: \"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.\",\n\t\t\t\t},\n\t\t\t\t\"session_expiration\": {\n\t\t\t\t\tType:        schema.TypeInt,\n\t\t\t\t\tOptional:    true,\n\t\t\t\t\tDescription: \"The time after which the established session for assuming role expires.\",\n\t\t\t\t\tValidateFunc: func(v interface{}, k string) ([]string, []error) {\n\t\t\t\t\t\tmin := 900\n\t\t\t\t\t\tmax := 3600\n\t\t\t\t\t\tvalue, ok := v.(int)\n\t\t\t\t\t\tif !ok {\n\t\t\t\t\t\t\treturn nil, []error{fmt.Errorf(\"expected type of %s to be int\", k)}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif value < min || value > max {\n\t\t\t\t\t\t\treturn nil, []error{fmt.Errorf(\"expected %s to be in the range (%d - %d), got %d\", k, min, max, v)}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn nil, nil\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t}\n}\n\n// New creates a new backend for OSS remote state.\nfunc New() backend.Backend {\n\ts := &schema.Backend{\n\t\tSchema: map[string]*schema.Schema{","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/backend/remote-state/oss/backend.go#L57-L93","documentation":"Emitted from the ValidateFunc of session_expiration inside the deprecated assume_role schema block. It fires when the value passed cannot be asserted to int. Because the schema field is declared schema.TypeInt, Terraform normally coerces the value, so reaching this branch indicates a non-coercible type slipped through (programmatic config, raw cty, or a malformed HCL variable).","triggerScenarios":"Setting assume_role.session_expiration to a non-integer (a string like \"3600s\", a float, or null) via a variable/programmatic backend config that bypasses the schema's normal int coercion. The ValidateFunc receives the raw interface{} and the v.(int) type assertion fails.","commonSituations":"Variable interpolation producing a string instead of a number; using assume_role blocks from an older example; tooling that builds the backend config from JSON without coercing types.","solutions":["Provide session_expiration as a bare integer literal in HCL (e.g. session_expiration = 3600), not a quoted string.","If sourcing from a variable, declare it as type = number and pass an unquoted value.","Migrate off the deprecated assume_role block to the top-level assume_role_session_expiration attribute which shares the same validator.","Ensure the value is also within 900–3600 (see error 323) once the type is fixed."],"exampleFix":"# before\nassume_role {\n  session_expiration = \"3600\"   # string -> type error\n}\n\n# after\nassume_role {\n  session_expiration = 3600     # integer seconds\n}","handlingStrategy":"validation","validationCode":"// In your wrapper, coerce before passing to the schema.\nfunc asInt(v interface{}) (int, error) {\n    switch n := v.(type) {\n    case int:    return n, nil\n    case float64: return int(n), nil\n    case string: return strconv.Atoi(n)\n    }\n    return 0, fmt.Errorf(\"expected int, got %T\", v)\n}","typeGuard":"func isInt(v interface{}) bool { _, ok := v.(int); return ok }","tryCatchPattern":null,"preventionTips":["Write session_expiration as an unquoted integer in HCL.","Declare number-typed variables for interpolated values.","Migrate off the deprecated assume_role block."],"tags":["oss","assume-role","validation","config","schema","backend"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}