{"record":{"id":"712c0fd0ef78d768","repo":"hashicorp/terraform","slug":"couldn-t-create-initial-workspace-no-name-provide","errorCode":null,"errorMessage":"Couldn't create initial workspace: no name provided","messagePattern":"Couldn't create initial workspace: no name provided","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/command/meta_backend.go","lineNumber":266,"sourceCode":"\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\n\t// Check if any of the existing workspaces matches the selected\n\t// workspace and create a numbered list of existing workspaces.\n\tvar list strings.Builder\n\tfor i, w := range workspaces {","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/meta_backend.go#L248-L284","documentation":"Returned by selectWorkspace() when, in the interactive cloud workspace-creation prompt, the user submits an empty string (after trimming) as the new workspace name. Terraform refuses to create a workspace with no name, as that would be an invalid state. This is a deterministic validation failure, not an I/O error.","triggerScenarios":"Cloud backend, tag-based mapping, zero existing workspaces, interactive mode enabled, and the user presses enter without typing a workspace name at the 'No workspaces found' prompt.","commonSituations":"A user accidentally hitting Enter at the create-workspace prompt; a misconfigured expect/pexpect automation that sends an empty line; confusion about whether a default workspace should be auto-created.","solutions":["Re-run and type a non-empty valid workspace name at the prompt.","Pre-create the workspace via `terraform workspace new <name>` or in the HCP Terraform UI.","Set the workspace name explicitly via TF_WORKSPACE or cloud workspace_mapping.name to skip the prompt."],"exampleFix":"// before: empty input at prompt\n> [No workspaces found] (press Enter)\n// after\n> my-prod-workspace","handlingStrategy":"validation","validationCode":"// Ensure a non-empty workspace name is configured for cloud init\nname := strings.TrimSpace(os.Getenv(\"TF_WORKSPACE\"))\nif name == \"\" {\n    return errors.New(\"provide a non-empty workspace name via TF_WORKSPACE before non-interactive cloud init\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pre-create the workspace via `terraform workspace new <name>` or the HCP Terraform UI.","Set TF_WORKSPACE to a valid non-empty name for automated runs.","Avoid sending empty lines through expect/automation at the prompt."],"tags":["cloud","workspace","interactive","validation","hcp-terraform"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T20:17:04.800Z"}