{"record":{"id":"d29c5a5fea23e4eb","repo":"hashicorp/terraform","slug":"http-error-d","errorCode":null,"errorMessage":"HTTP error: %d","messagePattern":"HTTP error: (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/backend/remote-state/http/client.go","lineNumber":241,"sourceCode":"\t\t}\n\t*/\n\n\tvar method string = \"POST\"\n\tif c.UpdateMethod != \"\" {\n\t\tmethod = c.UpdateMethod\n\t}\n\tresp, err := c.httpRequest(method, &base, &data, \"upload state\")\n\tif err != nil {\n\t\treturn diags.Append(err)\n\t}\n\tdefer resp.Body.Close()\n\n\t// Handle the error codes\n\tswitch resp.StatusCode {\n\tcase http.StatusOK, http.StatusCreated, http.StatusNoContent:\n\t\treturn diags\n\tdefault:\n\t\treturn diags.Append(fmt.Errorf(\"HTTP error: %d\", resp.StatusCode))\n\t}\n}\n\nfunc (c *httpClient) Delete() tfdiags.Diagnostics {\n\tvar diags tfdiags.Diagnostics\n\n\t// Make the request\n\tresp, err := c.httpRequest(\"DELETE\", c.URL, nil, \"delete state\")\n\tif err != nil {\n\t\treturn diags.Append(err)\n\t}\n\tdefer resp.Body.Close()\n\n\t// Handle the error codes\n\tswitch resp.StatusCode {\n\tcase http.StatusOK:\n\t\treturn diags\n\tdefault:","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/backend/remote-state/http/client.go#L223-L259","documentation":"The HTTP backend's Put() (state upload) received a status code other than 200, 201, or 204. These are the only success codes accepted for a POST/PUT state write; anything else (including redirects or 4xx/5xx) is reported as a generic HTTP error with the numeric code.","triggerScenarios":"Calling Put() during `terraform apply`/`terraform destroy` to persist state, where the server responds with a non-success code such as 401, 403, 405 (method not allowed), 409 (conflict/lock), 413 (payload too large), or 500.","commonSituations":"The state endpoint does not allow POST/PUT (returns 405) when UpdateMethod is misconfigured; the server rejects large state bodies (413); authentication expired between read and write (401/403); a concurrent lock returns 409; a server error during write (500).","solutions":["Use TF_LOG=DEBUG to capture the exact status code, then address the server-side cause for that code.","If 405, set the correct `update_method` (\"POST\" or \"PUT\") matching what the state endpoint accepts.","If 401/403, refresh or correct the username/password (or token) credentials for the state endpoint.","If 413, raise the server's max body size limit to accommodate the state payload.","If 409, the state is locked elsewhere; run `terraform force-unlock` or wait for the other run to finish."],"exampleFix":"# before - server only accepts PUT but default POST is used\nbackend \"http\" {\n  address = \"https://state.example.com/tf\"\n}\n\n# after - specify the method the endpoint accepts\nbackend \"http\" {\n  address       = \"https://state.example.com/tf\"\n  update_method = \"PUT\"\n}","handlingStrategy":"validation","validationCode":"# Probe the write endpoint with the method Terraform will use before running apply\ncurl -sS -o /dev/null -w \"%{http_code}\" -X \"$METHOD\" \\\n  -H \"Content-Type: application/json\" \\\n  -u \"$USER:$PASS\" --data-binary @small.json \"$STATE_URL\"\n# expect 200, 201, or 204","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set update_method to match what the endpoint accepts (POST vs PUT).","Ensure the configured credentials have write permission and have not expired.","Confirm the server's max body size exceeds your state size to avoid 413."],"tags":["http","remote-state","network","terraform-backend","write"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}