{"record":{"id":"d23406d6e65a9648","repo":"hashicorp/terraform","slug":"error-loading-state-s","errorCode":null,"errorMessage":"Error loading state: %s","messagePattern":"Error loading state: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/init_run.go","lineNumber":322,"sourceCode":"\t\trootModule: rootModEarly,\n\t}\n\n\tvar state *states.State\n\n\t// If we have a functional backend (either just initialized or initialized\n\t// on a previous run) we'll use the current state as a potential source\n\t// of provider dependencies.\n\tif back != nil {\n\t\tc.ignoreRemoteVersionConflict(back)\n\t\tworkspace, err := c.Workspace()\n\t\tif err != nil {\n\t\t\tdiags = diags.Append(fmt.Errorf(\"Error selecting workspace: %s\", err))\n\t\t\tview.Diagnostics(diags)\n\t\t\treturn 1\n\t\t}\n\t\tsMgr, sDiags := back.StateMgr(workspace)\n\t\tif sDiags.HasErrors() {\n\t\t\tdiags = diags.Append(fmt.Errorf(\"Error loading state: %s\", sDiags.Err()))\n\t\t\tview.Diagnostics(diags)\n\t\t\treturn 1\n\t\t}\n\n\t\tif err := sMgr.RefreshState(); err != nil {\n\t\t\tdiags = diags.Append(fmt.Errorf(\"Error refreshing state: %s\", err))\n\t\t\tview.Diagnostics(diags)\n\t\t\treturn 1\n\t\t}\n\n\t\tstate = sMgr.State()\n\t}\n\n\tif initArgs.Get {\n\t\tmodsOutput, modsAbort, modsDiags := c.getModules(ctx, path, initArgs.TestsDirectory, rootModEarly, initArgs.Upgrade, view, policyClient)\n\t\tdiags = diags.Append(modsDiags)\n\t\tif modsAbort || modsDiags.HasErrors() {\n\t\t\tview.Diagnostics(diags)","sourceCodeStart":304,"sourceCodeEnd":340,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/init_run.go#L304-L340","documentation":"Emitted by InitCommand.run when back.StateMgr(workspace) returns error diagnostics (init_run.go:320-322). StateMgr constructs the state manager for the selected workspace from the configured backend; failures here mean Terraform could not open or initialize the state store handle, not that a read failed. The %s is the diagnostic error text.","triggerScenarios":"A backend is configured and a workspace selected, but constructing the state manager fails: invalid/missing backend configuration (e.g. S3 bucket/region/key wrong), backend type not registered, credentials rejected at handle creation, or remote endpoint unreachable when the manager is opened.","commonSituations":"Backend config referenced after a partial/failed init; backend credentials expired or rotated; S3 bucket/DynamoDB table missing; HTTP/artifactory backend URL incorrect; consul/etcd backend unreachable; workspace path conflicts.","solutions":["Run `terraform init -reconfigure` to rebuild the backend configuration cleanly.","Verify backend-specific resources exist and credentials are valid (e.g. `aws s3 ls <bucket>`, consul connectivity).","Correct the backend block's required fields (bucket, key, region, endpoints) in the configuration.","Check that the backend plugin/binary is available and the backend type is spelled correctly."],"exampleFix":"# before\nterraform {\n  backend \"s3\" {\n    bucket = \"wrong-name\"\n  }\n}\n# after\nterraform {\n  backend \"s3\" {\n    bucket = \"real-state-bucket\"\n    key    = \"prod/terraform.tfstate\"\n    region = \"us-east-1\"\n  }\n}","handlingStrategy":"try-catch","validationCode":"// Validate backend prerequisites before init (example: S3 backend).\nif err := run(\"aws\", \"s3api\", \"head-bucket\", \"--bucket\", bucket); err != nil {\n    return fmt.Errorf(\"backend bucket %q not accessible: %w\", bucket, err)\n}","typeGuard":null,"tryCatchPattern":"// Reconfigure the backend if state manager construction fails.\nif err := run(\"terraform\", \"init\"); err != nil {\n    _ = run(\"terraform\", \"init\", \"-reconfigure\")\n}","preventionTips":["Verify backend resources (bucket/table/key) and credentials exist before init.","Use `terraform init -reconfigure` after changing backend settings.","Keep backend config fields (region, endpoints) correct and complete."],"tags":["terraform-init","state","backend","configuration"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}