hashicorp/terraform · error

Expected a workspace name as an argument, instead got an emp

Error message

Expected a workspace name as an argument, instead got an empty string: %q

What it means

Emitted by `terraform workspace delete` (workspace_delete.go:62) when exactly one positional argument is supplied but it is the empty string. Note the separate path at workspace_delete.go:51-52 covers the no-argument case; this error is specifically `len(args) >= 1 && args[0] == ""`. `workspace delete` intentionally does NOT run `ValidWorkspaceName` so users can remove workspaces with unusual names, but it still rejects an empty name.

Source

Thrown at internal/command/arguments/workspace_delete.go:62

			err.Error(),
		))
	}

	// `workspace delete` takes only one positional argument: workspace name.
	args = cmdFlags.Args()
	var name string
	if len(args) == 0 {
		diags = diags.Append(errors.New("Expected a single argument: NAME.")) // Recreating pre-existing error from command package
	} else {

		// Obtain and validate name argument
		//
		// We purposefully don't use ValidWorkspaceName here; if a user
		// creates a workspace with an invalid name they should be able to
		// delete it easily.
		name = args[0]
		if name == "" {
			diags = diags.Append(fmt.Errorf("Expected a workspace name as an argument, instead got an empty string: %q\n", args[0]))
		}

		// Checking for extra arguments here, not with a len != 1 check above, allows the name to be returned
		args = args[1:]
		if len(args) != 0 {
			diags = diags.Append(errors.New("Expected a single argument: NAME."))
		}
	}

	return &WorkspaceDelete{
		Workspace:   Workspace{ViewType: ViewHuman},
		Name:        name,
		Lock:        stateLock,
		LockTimeout: stateLockTimeout,
		Force:       force,
	}, diags
}

View on GitHub (pinned to c9def3e214)

Solutions

  1. Pass a non-empty workspace name: `terraform workspace delete <name>`.
  2. In scripts, guard the variable before calling: only run when the name is non-empty.
  3. If you meant the default workspace, delete the target's resources instead — the `default` workspace cannot be deleted.

Example fix

# before
WS=""
terraform delete "$WS"   # or: terraform workspace delete ""
# Expected a workspace name as an argument, instead got an empty string: ""

# after (guard in shell)
WS="${WS:?workspace name required}"
terraform workspace delete "$WS"
Defensive patterns

Strategy: validation

Validate before calling

// Validate a workspace name before calling 'terraform workspace delete'.
func deleteWorkspaceArg(name string) error {
    if name == "" {
        return fmt.Errorf("workspace name must not be empty")
    }
    return nil
}

Prevention

When it happens

Trigger: Running `terraform workspace delete ""` (an explicitly empty argument), e.g. via a shell where a variable expanded to empty: `terraform workspace delete "$WS"` with `WS` unset/empty.

Common situations: Shell scripts that pass an unset environment variable as the workspace name; CI matrices that emit an empty name for the default branch; quoting mistakes that pass an empty token.

Related errors


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