{"record":{"id":"5acf64bc6634f300","repo":"hashicorp/terraform","slug":"invalid-value-for-q-must-be-a-number","errorCode":null,"errorMessage":"invalid value for %q: must be a number","messagePattern":"invalid value for %q: must be a number","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/backend/backendbase/sdklike.go","lineNumber":280,"sourceCode":"\t\t\t\treturn cty.NilVal, fmt.Errorf(\"invalid value for %q: %s\", attrName, err)\n\t\t\t}\n\t\t\tretAttrs[attrName] = cty.BoolVal(bv)\n\t\tcase cty.Number:\n\t\t\tif rawStr == \"\" {\n\t\t\t\trawStr = \"0\"\n\t\t\t}\n\n\t\t\t// This case is a little trickier because cty.Number could be\n\t\t\t// representing either an integer or a float, which each have\n\t\t\t// different interpretations in the legacy SDK. Therefore we'll\n\t\t\t// try integer first and use its result if successful, but then\n\t\t\t// try float as a fallback if not.\n\t\t\tif iv, err := strconv.ParseInt(rawStr, 0, 0); err == nil {\n\t\t\t\tretAttrs[attrName] = cty.NumberIntVal(iv)\n\t\t\t} else if fv, err := strconv.ParseFloat(rawStr, 64); err == nil {\n\t\t\t\tretAttrs[attrName] = cty.NumberFloatVal(fv)\n\t\t\t} else {\n\t\t\t\treturn cty.NilVal, fmt.Errorf(\"invalid value for %q: must be a number\", attrName)\n\t\t\t}\n\t\tdefault:\n\t\t\tpanic(\"cannot apply environment variable defaults for \" + ty.GoString())\n\t\t}\n\t}\n\treturn cty.ObjectVal(retAttrs), nil\n}\n","sourceCodeStart":262,"sourceCodeEnd":288,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/backend/backendbase/sdklike.go#L262-L288","documentation":"Thrown by SDKLikeDefaults.ApplyTo when an attribute typed cty.Number receives a string that is neither a valid integer (strconv.ParseInt) nor a valid float (strconv.ParseFloat). The code tries integer parsing first then falls back to float; failure of both produces this error.","triggerScenarios":"A numeric backend attribute is supplied via config or environment variable with a non-numeric string (e.g. 'auto', 'unlimited', '1,024' with a comma, or '0x' with bad hex). Triggered during ApplyTo for any cty.Number attribute.","commonSituations":"Comma-separated thousands separators from locale-formatted numbers; trailing units like '5m'; copy-paste of human-readable values; env var left as a placeholder string.","solutions":["Provide a plain numeric value without separators or units (e.g. 1024 or 10.5).","If using hex/octal via ParseInt base 0, ensure the prefix (0x/0o/0b) is correct and digits are valid for that base.","Set the number directly in the backend block as a native HCL number rather than via env var."],"exampleFix":"# before\nexport SOME_BACKEND_NUM=1,024\n# after\nexport SOME_BACKEND_NUM=1024","handlingStrategy":"validation","validationCode":"func validNumberEnv(name string) bool {\n    v := os.Getenv(name)\n    if v == \"\" {\n        return true\n    }\n    if _, err := strconv.ParseInt(v, 0, 0); err == nil {\n        return true\n    }\n    _, err := strconv.ParseFloat(v, 64)\n    return err == nil\n}","typeGuard":null,"tryCatchPattern":"val, err := defaults.ApplyTo(config)\nif err != nil && strings.Contains(err.Error(), \"must be a number\") {\n    return fmt.Errorf(\"a numeric backend argument got a non-numeric value: %w\", err)\n}","preventionTips":["Never use thousands separators or units in numeric backend config.","Prefer setting numbers directly in the backend block as HCL numbers over env vars.","Add a CI lint that rejects non-numeric values for known numeric env vars."],"tags":["config","backend","environment-variables","type-conversion","terraform"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}