{"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":"critical","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/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/init_run.go#L304-L340","documentation":"Thrown when back.StateMgr(workspace) returns diagnostics with errors during init. StateMgr constructs the state manager for the resolved workspace; failures typically originate from the backend (e.g., remote state store misconfiguration, auth failure, unreachable backend).","triggerScenarios":"Backend returns errors constructing the state manager: invalid remote state config (S3 bucket/DynamoDB table missing, HTTP backend auth failure, Consul/HTTP unreachable), or unsupported backend operation for the workspace.","commonSituations":"Misconfigured S3 backend (missing bucket/table/region); expired cloud credentials; remote backend endpoint down; backend type mismatch; insufficient IAM permissions on state objects.","solutions":["Inspect the wrapped sDiags for the backend-specific cause.","Verify backend config (bucket, key, region, credentials) and network reachability.","Confirm IAM/permissions on the remote state location and re-run init."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Sanity-check backend config reachability before init (S3 example).\nfunc s3BackendReachable(bucket, region string) error {\n    cfg, err := aws.NewConfig(region)\n    if err != nil { return err }\n    return cfg.HeadBucket(bucket)\n}","typeGuard":null,"tryCatchPattern":"// Inspect sDiags for backend-specific errors.\nif sDiags.HasErrors() {\n    for _, d := range sDiags { log.Printf(\"backend: %s\", d.Description().Summary) }\n}","preventionTips":["Validate backend config (bucket/key/region/credentials) before init.","Confirm credentials are unexpired and have state-object permissions.","Pre-test remote backend reachability from the runner."],"tags":["terraform-init","backend","state","remote-state"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}