{"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/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/backend/backendbase/sdklike.go#L262-L288","documentation":"Thrown by SDKLikeDefaults.ApplyTo in the cty.Number case when neither strconv.ParseInt nor strconv.ParseFloat can interpret rawStr. As with error 122, the HCL value itself is already type-checked, so the offending value comes from an env var or Fallback. The integer parse uses base 0 (so 0x.. and 0.. are honored); the float parse is the fallback.","triggerScenarios":"A cty.Number attribute has EnvVars; the user sets that env var to something that is neither an integer nor a float. Examples: \"10s\", \"5mb\", \"1,024\" (comma), \"3.14.15\", \"auto\", or a value with surrounding text.","commonSituations":"Passing a duration or size with units to a numeric backend knob (e.g. a port number env var set to \"port 443\"), locale-specific number formats with a comma decimal separator, or an env var that resolved to a placeholder like '<unset>'.","solutions":["Provide a plain numeric value (e.g. 443, 86400, 2.5) in the env var or backend block.","Strip units, quotes, and thousands separators from the value before exporting it.","If the value should carry units, change the backend attribute to a string and parse it in your own Configure code instead of relying on the SDK-like number coercion.","Verify the env var is not being overwritten by a CI template with a non-numeric default."],"exampleFix":"# before\nexport GCS_REQUESTER_PAYS=\"yes\"   # numeric attr -> must be a number\n# after\nexport GCS_REQUESTER_PAYS=\"1\"","handlingStrategy":"validation","validationCode":"func numberEnvOk(name string) error {\n    if v := os.Getenv(name); v != \"\" {\n        if _, err1 := strconv.ParseInt(v, 0, 0); err1 != nil {\n            if _, err2 := strconv.ParseFloat(v, 64); err2 != nil {\n                return fmt.Errorf(\"env %s=%q is not a number\", name, v)\n            }\n        }\n    }\n    return nil\n}","typeGuard":"null","tryCatchPattern":"if _, err := defs.ApplyTo(cfg); err != nil {\n    if strings.Contains(err.Error(), \"must be a number\") {\n        return fmt.Errorf(\"a backend env var has a non-numeric value: %w\", err)\n    }\n    return err\n}","preventionTips":["Keep numeric backend env vars as plain digits (optionally a single decimal point).","Strip units, commas, and currency symbols before exporting values.","Prefer string-typed attributes plus explicit parsing in your backend when the value is naturally a duration or size."],"tags":["backend","configuration","number","env-var","type-conversion","sdklike"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}