{"record":{"id":"3f3ae4087e79f4fc","repo":"hashicorp/terraform","slug":"failed-to-get-existing-workspaces-s","errorCode":null,"errorMessage":"Failed to get existing workspaces: %s","messagePattern":"Failed to get existing workspaces: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/meta_backend.go","lineNumber":246,"sourceCode":"\t\tm.backendConfigState = &workdir.BackendConfigState{\n\t\t\tType:      \"local\",\n\t\t\tConfigRaw: json.RawMessage(\"{}\"),\n\t\t}\n\t}\n\n\treturn local, diags\n}\n\n// selectWorkspace gets a list of existing workspaces and then checks\n// if the currently selected workspace is valid. If not, it will ask\n// the user to select a workspace from the list.\nfunc (m *Meta) selectWorkspace(b backend.Backend) error {\n\tworkspaces, diags := b.Workspaces()\n\tif diags.HasErrors() && diags.Err().Error() == backend.ErrWorkspacesNotSupported.Error() {\n\t\treturn nil\n\t}\n\tif diags.HasErrors() {\n\t\treturn fmt.Errorf(\"Failed to get existing workspaces: %s\", diags.Err())\n\t}\n\tif diags.HasWarnings() {\n\t\tlog.Printf(\"[WARN] selectWorkspace: warning(s) returned when getting workspaces: %s\", diags.ErrWithWarnings())\n\t}\n\tif len(workspaces) == 0 {\n\t\tif c, ok := b.(*cloud.Cloud); ok && m.input {\n\t\t\t// len is always 1 if using Name; 0 means we're using Tags and there\n\t\t\t// aren't any matching workspaces. Which might be normal and fine, so\n\t\t\t// let's just ask:\n\t\t\tname, err := m.UIInput().Input(context.Background(), &terraform.InputOpts{\n\t\t\t\tId:          \"create-workspace\",\n\t\t\t\tQuery:       \"\\n[reset][bold][yellow]No workspaces found.[reset]\",\n\t\t\t\tDescription: fmt.Sprintf(inputCloudInitCreateWorkspace, c.WorkspaceMapping.DescribeTags()),\n\t\t\t})\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"Couldn't create initial workspace: %w\", err)\n\t\t\t}\n\t\t\tname = strings.TrimSpace(name)","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/meta_backend.go#L228-L264","documentation":"Returned by selectWorkspace() when b.Workspaces() returns diagnostics containing errors other than the well-known ErrWorkspacesNotSupported sentinel. selectWorkspace needs the workspace list to validate the current selection or prompt the user, so any other backend error is fatal. The %s is the diagnostics error text.","triggerScenarios":"A backend that supports workspaces returns an error from its Workspaces() method during the workspace selection phase of backend init — e.g. a cloud/remote backend whose API call to list workspaces failed (auth, 5xx, network), or a state backend with a corrupted workspace index.","commonSituations":"HCP Terraform / cloud backend with an expired or revoked API token; a remote HTTP backend whose endpoint is down; S3 backend with insufficient IAM permissions to list workspaces (ListObjectsV2); transient network failure reaching the state storage API.","solutions":["Check the wrapped error text — for cloud backends it usually indicates auth (401/403) or connectivity.","Verify credentials: `terraform login` or set the correct TF_TOKEN_* / AWS_* / GOOGLE_* env vars for your backend.","Ensure the principal has list/read permissions on the state workspace prefix/path.","Retry transient API failures; for persistent failures inspect backend-specific logs."],"exampleFix":"# before: missing cloud token\nterraform init\n# Failed to get existing workspaces: ...\n# after\nterraform login\nterraform init","handlingStrategy":"retry","validationCode":"// Pre-flight: ensure backend can list workspaces\nif ws, d := b.Workspaces(); d.HasErrors() && d.Err().Error() != backend.ErrWorkspacesNotSupported.Error() {\n    return fmt.Errorf(\"fix backend workspace access first: %s\", d.Err())\n} else {\n    _ = ws\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify backend credentials and permissions before init.","Grant the backend principal list/read on the state workspace path/prefix.","Retry transient remote API errors; treat persistent ones as config/auth issues."],"tags":["backend","workspace","cloud","auth","network"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}