hashicorp/terraform · error

Couldn't create initial workspace: no name provided

Error message

Couldn't create initial workspace: no name provided

What it means

Returned from `Meta.selectWorkspace` when the cloud create-workspace prompt succeeded (no `UIInput` error) but the user typed only whitespace or pressed Enter without a name. `strings.TrimSpace(name)` yields an empty string, so the workspace cannot be created or selected.

Solutions

  1. Re-run and type a valid workspace name at the prompt (letters, digits, dashes, underscores).
  2. Pre-create the workspace in HCP Terraform to avoid the prompt.
  3. Set `workspaces.name` explicitly in the `cloud` block.
  4. If scripting, pipe a real name: `echo 'prod' | terraform init`.

Example fix

# before: empty input at prompt
# 'No workspaces found.' -> [Enter]
# after
# 'No workspaces found.' -> type 'prod' [Enter]
# or pre-create in UI / set in config:
cloud { organization = "acme" workspaces { name = "prod" } }
Defensive patterns

Strategy: validation

Validate before calling

// Validate the prompted name before passing it on.
name = strings.TrimSpace(name)
if name == "" || !arguments.ValidWorkspaceName(name) {
    return errors.New("a non-empty valid workspace name is required")
}

Type guard

func nonEmptyValidWs(s string) bool {
    s = strings.TrimSpace(s)
    return s != "" && arguments.ValidWorkspaceName(s)
}

Try / catch

null

Prevention

When it happens

Trigger: User pressed Enter at the 'No workspaces found' prompt without typing a name, or typed only spaces/tabs. Distinct from error 651, which fires when the prompt itself errors.

Common situations: User unsure what to type and hits Enter to 'skip'; accidental Enter; a piped empty line (`echo '' | terraform init`) feeding the prompt.

Related errors


AI-assisted analysis of hashicorp/terraform@d32a084675 (2026-08-11). Data as JSON: /api/errors/712c0fd0ef78d768. Report an issue: GitHub.

Appendix: source

Thrown at internal/command/meta_backend.go:266

	if diags.HasWarnings() {
		log.Printf("[WARN] selectWorkspace: warning(s) returned when getting workspaces: %s", diags.ErrWithWarnings())
	}
	if len(workspaces) == 0 {
		if c, ok := b.(*cloud.Cloud); ok && m.input {
			// len is always 1 if using Name; 0 means we're using Tags and there
			// aren't any matching workspaces. Which might be normal and fine, so
			// let's just ask:
			name, err := m.UIInput().Input(context.Background(), &terraform.InputOpts{
				Id:          "create-workspace",
				Query:       "\n[reset][bold][yellow]No workspaces found.[reset]",
				Description: fmt.Sprintf(inputCloudInitCreateWorkspace, c.WorkspaceMapping.DescribeTags()),
			})
			if err != nil {
				return fmt.Errorf("Couldn't create initial workspace: %w", err)
			}
			name = strings.TrimSpace(name)
			if name == "" {
				return fmt.Errorf("Couldn't create initial workspace: no name provided")
			}
			log.Printf("[TRACE] Meta.selectWorkspace: selecting the new HCP Terraform workspace requested by the user (%s)", name)
			return m.SetWorkspace(name)
		} else {
			return &errBackendNoExistingWorkspaces{}
		}
	}

	// Get the currently selected workspace.
	workspace, err := m.Workspace()
	if err != nil {
		return err
	}

	// Check if any of the existing workspaces matches the selected
	// workspace and create a numbered list of existing workspaces.
	var list strings.Builder
	for i, w := range workspaces {

View on GitHub (pinned to d32a084675)