hashicorp/terraform · error

Expected a single argument: NAME.

Error message

Expected a single argument: NAME.

What it means

Returned at workspace_select.go:45 when 'terraform workspace select' is invoked with zero positional arguments. The command requires exactly one positional argument: the workspace NAME. workspace_select.go:43-44 checks 'len(args) == 0' after flag parsing.

Solutions

  1. Provide the workspace name: 'terraform workspace select <workspace-name>'.
  2. Run 'terraform workspace list' to see available workspace names.
  3. Check scripts for empty or unquoted variables.

Example fix

// before
terraform workspace select
// error: Expected a single argument: NAME.

// after
terraform workspace select my-workspace
Defensive patterns

Strategy: validation

Validate before calling

// Validate workspace name is provided before calling workspace select:
// if name == "" {
//     return fmt.Errorf("workspace name is required for select")
// }
// exec.Command("terraform", "workspace", "select", name)

Prevention

When it happens

Trigger: Running 'terraform workspace select' with no workspace name, or providing only flags. workspace_select.go:43 checks 'len(args) == 0'.

Common situations: Forgetting the workspace name; shell scripts with empty variables; assuming 'select' without arguments defaults to something.

Related errors


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

Appendix: source

Thrown at internal/command/arguments/workspace_select.go:45

func ParseWorkspaceSelect(args []string) (*WorkspaceSelect, tfdiags.Diagnostics) {
	var diags tfdiags.Diagnostics

	var orCreate bool
	cmdFlags := defaultFlagSet("workspace select")
	cmdFlags.BoolVar(&orCreate, "or-create", false, "create workspace if it does not exist")
	if err := cmdFlags.Parse(args); err != nil {
		diags = diags.Append(tfdiags.Sourceless(
			tfdiags.Error,
			"Failed to parse command-line flags",
			err.Error(),
		))
	}

	// `workspace select` 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.
		name = args[0]
		if !ValidWorkspaceName(name) {
			diags = diags.Append(fmt.Errorf(EnvInvalidName, name))
		}

		// 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 &WorkspaceSelect{
		Workspace: Workspace{ViewType: ViewHuman},
		OrCreate:  orCreate,
		Name:      name,

View on GitHub (pinned to d32a084675)