hashicorp/terraform · warning

Couldn't create initial workspace: no name provided

Error message

Couldn't create initial workspace: no name provided

What it means

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.

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 c9def3e214)

Solutions

  1. Re-run and type a non-empty valid workspace name at the prompt.
  2. Pre-create the workspace via `terraform workspace new <name>` or in the HCP Terraform UI.
  3. Set the workspace name explicitly via TF_WORKSPACE or cloud workspace_mapping.name to skip the prompt.

Example fix

// before: empty input at prompt
> [No workspaces found] (press Enter)
// after
> my-prod-workspace
Defensive patterns

Strategy: validation

Validate before calling

// Ensure a non-empty workspace name is configured for cloud init
name := strings.TrimSpace(os.Getenv("TF_WORKSPACE"))
if name == "" {
    return errors.New("provide a non-empty workspace name via TF_WORKSPACE before non-interactive cloud init")
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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