{"record":{"id":"2f5ab22fb6b09629","repo":"hashicorp/terraform","slug":"failed-to-select-workspace-s","errorCode":null,"errorMessage":"Failed to select workspace: %s","messagePattern":"Failed to select workspace: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/command/meta_backend.go","lineNumber":312,"sourceCode":"\t\tlog.Printf(\"[TRACE] Meta.selectWorkspace: automatically selecting the single workspace provided by the backend (%s)\", workspaces[0])\n\t\treturn m.SetWorkspace(workspaces[0])\n\t}\n\n\tif !m.input {\n\t\treturn fmt.Errorf(\"Currently selected workspace %q does not exist\", workspace)\n\t}\n\n\t// Otherwise, ask the user to select a workspace from the list of existing workspaces.\n\tv, err := m.UIInput().Input(context.Background(), &terraform.InputOpts{\n\t\tId: \"select-workspace\",\n\t\tQuery: fmt.Sprintf(\n\t\t\t\"\\n[reset][bold][yellow]The currently selected workspace (%s) does not exist.[reset]\",\n\t\t\tworkspace),\n\t\tDescription: fmt.Sprintf(\n\t\t\tstrings.TrimSpace(inputBackendSelectWorkspace), list.String()),\n\t})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"Failed to select workspace: %s\", err)\n\t}\n\n\tidx, err := strconv.Atoi(v)\n\tif err != nil || (idx < 1 || idx > len(workspaces)) {\n\t\treturn fmt.Errorf(\"Failed to select workspace: input not a valid number\")\n\t}\n\n\tworkspace = workspaces[idx-1]\n\tlog.Printf(\"[TRACE] Meta.selectWorkspace: setting the current workspace according to user selection (%s)\", workspace)\n\treturn m.SetWorkspace(workspace)\n}\n\n// BackendForLocalPlan is similar to Backend, but uses settings that were\n// stored in a plan when preparing the returned operations backend.\n// The plan's data may describe `backend` or `state_store` configuration.\n//\n// The current workspace name is also stored as part of the plan, and so this\n// method will check that it matches the currently-selected workspace name","sourceCodeStart":294,"sourceCodeEnd":330,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/meta_backend.go#L294-L330","documentation":"Returned by selectWorkspace() when the interactive workspace-selection prompt's UIInput().Input() call fails with an error. This occurs after detecting that the current workspace is missing and there are multiple backend workspaces to choose from. The %s wraps the I/O error from the input reader.","triggerScenarios":"selectWorkspace issues the 'select-workspace' numbered prompt (because current workspace is missing and multiple exist) and the UIInput reader returns a non-nil error — EOF, broken pipe, or read failure on the prompt channel.","commonSituations":"Interactive selection triggered in a context where stdin is broken (piped input that closed, terminal detached mid-prompt, automation that doesn't expect the prompt); running under a wrapper that intercepts stdin incorrectly.","solutions":["Pre-select the workspace with `terraform workspace select <name>` so no interactive prompt is needed.","Run with -input=false and ensure a valid workspace is pre-selected.","Ensure stdin is a live TTY for interactive sessions, or feed the numbered choice via a properly kept-open pipe."],"exampleFix":"# before: broken stdin during selection prompt\nterraform init\n# Failed to select workspace: EOF\n# after: select non-interactively first\nterraform workspace select dev\nterraform init","handlingStrategy":"validation","validationCode":"// Avoid the selection prompt by pre-selecting a valid workspace\nname := getSelectedWorkspace()\nif name == \"\" || !workspaceExists(name) {\n    return errors.New(\"pre-select a valid workspace to avoid interactive prompt\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pre-select the workspace with `terraform workspace select` so no prompt appears.","Use -input=false with a valid pre-selected workspace in automation.","Keep stdin as a live TTY when interactive selection is intended."],"tags":["workspace","interactive","input","select","ui"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}