{"record":{"id":"d7d4337bc8ee6352","repo":"hashicorp/terraform","slug":"failed-to-refresh-state-s","errorCode":null,"errorMessage":"Failed to refresh state: %s\n","messagePattern":"Failed to refresh state: (.+?)\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/state_show.go","lineNumber":118,"sourceCode":"\tschemas, diags := lr.Core.Schemas(lr.Config, lr.InputState)\n\tif diags.HasErrors() {\n\t\treturn view.DisplayResourceInstanceState(jsonformat.State{}, diags)\n\t}\n\n\t// Get the state\n\tenv, err := c.Workspace()\n\tif err != nil {\n\t\tdiags = diags.Append(fmt.Sprintf(\"Error selecting workspace: %s\\n\", err))\n\t\tview.Diagnostics(diags)\n\t\treturn 1\n\t}\n\tstateMgr, sDiags := b.StateMgr(env)\n\tif sDiags.HasErrors() {\n\t\tdiags = diags.Append(fmt.Errorf(errStateLoadingState, sDiags.Err()))\n\t\treturn view.DisplayResourceInstanceState(jsonformat.State{}, diags)\n\t}\n\tif err := stateMgr.RefreshState(); err != nil {\n\t\tdiags = diags.Append(fmt.Errorf(\"Failed to refresh state: %s\\n\", err))\n\t\treturn view.DisplayResourceInstanceState(jsonformat.State{}, diags)\n\t}\n\n\tstate := stateMgr.State()\n\tif state == nil {\n\t\tdiags = diags.Append(errors.New(errStateNotFound))\n\t\treturn view.DisplayResourceInstanceState(jsonformat.State{}, diags)\n\t}\n\n\tis := state.ResourceInstance(addr)\n\tif !is.HasCurrent() {\n\t\tdiags = diags.Append(errors.New(errNoInstanceFound))\n\t\treturn view.DisplayResourceInstanceState(jsonformat.State{}, diags)\n\t}\n\n\t// check if the resource has a configured provider, otherwise this will use the default provider\n\trs := state.Resource(addr.ContainingResource())\n\tabsPc := addrs.AbsProviderConfig{","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/state_show.go#L100-L136","documentation":"Thrown by `terraform state show` when stateMgr.RefreshState() fails after the state manager was obtained. RefreshState reads/locks the state from its backing store (local file, S3, cloud, etc.); failure means the state could not be read or locked. The %s is the underlying error (lock contention, IO error, network/auth failure).","triggerScenarios":"Running `terraform state show` when the state manager exists but RefreshState errors: state lock held by another run, S3/cloud network or auth error mid-read, local terraform.tfstate unreadable, or HTTP backend returning an error.","commonSituations":"Another terraform apply/plan holding the state lock; expired cloud credentials; S3 bucket deleted or region mismatch; concurrent CI jobs on one workspace; local state file deleted between StateMgr() and RefreshState().","solutions":["Read the %s to identify lock vs IO vs auth.","If locked by a dead process, `terraform force-unlock <LOCK_ID>` then retry.","Verify backend connectivity/credentials (aws sts get-caller-identity, tf login) and re-run.","Ensure only one Terraform process touches the workspace at a time."],"exampleFix":"# before - state locked by a crashed run\nterraform state show aws_instance.web\n# Failed to refresh state: Failed to lock state: Lock Info...\n\n# after\nterraform force-unlock <LOCK_ID>\nterraform state show aws_instance.web","handlingStrategy":"retry","validationCode":"// pre-flight: confirm backend reachable and not obviously locked\n// (backend-specific; verify credentials/endpoint before refresh)","typeGuard":null,"tryCatchPattern":"// retry refresh on transient lock/network errors\nfor i := 0; i < 3; i++ {\n    if err := stateMgr.RefreshState(); err != nil {\n        if isLockBusy(err) || isTransient(err) {\n            time.Sleep(backoff(i)); continue\n        }\n        return err\n    }\n    break\n}","preventionTips":["Run only one Terraform process per workspace to avoid lock contention.","Keep cloud/S3 credentials fresh.","Force-unlock only locks from known-dead processes.","Verify bucket region/endpoint before refreshing state."],"tags":["state-show","state-refresh","state-lock","backend"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T20:17:04.800Z"}