{"record":{"id":"b545479da835a1de","repo":"hashicorp/terraform","slug":"couldn-t-create-initial-workspace-w","errorCode":null,"errorMessage":"Couldn't create initial workspace: %w","messagePattern":"Couldn't create initial workspace: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/command/meta_backend.go","lineNumber":262,"sourceCode":"\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)\n\t\t\tif name == \"\" {\n\t\t\t\treturn fmt.Errorf(\"Couldn't create initial workspace: no name provided\")\n\t\t\t}\n\t\t\tlog.Printf(\"[TRACE] Meta.selectWorkspace: selecting the new HCP Terraform workspace requested by the user (%s)\", name)\n\t\t\treturn m.SetWorkspace(name)\n\t\t} else {\n\t\t\treturn &errBackendNoExistingWorkspaces{}\n\t\t}\n\t}\n\n\t// Get the currently selected workspace.\n\tworkspace, err := m.Workspace()\n\tif err != nil {\n\t\treturn err\n\t}\n","sourceCodeStart":244,"sourceCodeEnd":280,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/meta_backend.go#L244-L280","documentation":"Returned by selectWorkspace() in the HCP Terraform / cloud code path when, having found zero workspaces, it interactively prompts the user to name a new workspace and UIInput().Input() itself returns an error. The %w wraps the underlying input I/O error. This only triggers for cloud backends using tag-based workspace mapping (len(workspaces)==0) in interactive mode.","triggerScenarios":"The cloud backend returns no workspaces, m.input is true, the interactive 'create-workspace' prompt is issued, and the UIInput reader fails with an error (EOF, broken pipe, read error).","commonSituations":"A cloud workspace with tag-based mapping where the initial interactive prompt is issued but stdin is non-functional (CI without -input=false, closed pipe, scripted run that closes stdin early).","solutions":["Provide the workspace name non-interactively: set TF_WORKSPACE or pre-create the workspace in the HCP Terraform UI/API.","Run with -input=false to avoid the interactive prompt entirely (and pre-configure the workspace mapping).","Ensure stdin is a functional TTY when running interactively."],"exampleFix":"// before: cloud + tags, no workspace, closed stdin\nterraform init\n// after: pre-create or name the workspace\nterraform workspace new prod\nterraform init","handlingStrategy":"validation","validationCode":"// For cloud tag-based mapping, pre-create or name a workspace to avoid the prompt\nif name := os.Getenv(\"TF_WORKSPACE\"); name == \"\" && !m.Input() {\n    return errors.New(\"cloud tag mapping with no workspaces requires TF_WORKSPACE or interactive input\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pre-create the workspace in HCP Terraform when using tag-based mapping.","Set TF_WORKSPACE or cloud workspaces.name to avoid the create prompt.","Run with -input=false only after a workspace is selected."],"tags":["cloud","workspace","interactive","hcp-terraform","input"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T20:17:04.800Z"}