hashicorp/terraform · error
Expected a single argument: NAME.
Error message
Expected a single argument: NAME.
What it means
Returned by ParseWorkspaceSelect (workspace_select.go:45) when, after flag parsing, zero positional arguments are present — i.e. 'terraform workspace select' was run with no NAME. Exactly one workspace name is required to switch to it.
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 c9def3e214)
Solutions
- Provide the workspace name: 'terraform workspace select NAME'.
- Run 'terraform workspace list' to see available names.
- Use 'terraform workspace select -or-create=NAME' if you want create-if-missing semantics.
Example fix
# before $ terraform workspace select # after $ terraform workspace select prod
Defensive patterns
Strategy: validation
Validate before calling
// Ensure a name is present for 'workspace select'.
func validateSelectName(args []string) error {
if len(args) == 0 {
return errors.New("workspace select requires a NAME argument")
}
return nil
} Prevention
- Always pass a workspace name to 'terraform workspace select'.
- List workspaces first if unsure of available names.
- Use -or-create if you want create-if-missing behavior.
When it happens
Trigger: Line 43-45: cmdFlags.Args() returns len(args)==0 -> the error is appended; Name stays empty.
Common situations: Running 'terraform workspace select' bare; an empty variable expansion in a script; mistaking it for 'terraform workspace list'.
Related errors
- Expected a single argument: NAME.
- Expected a single argument: NAME.
- Too many command line arguments. Did you mean to use -chdir?
- The workspace name %q is not allowed. The name must contain
- Currently selected workspace %q does not exist
AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07).
Data as JSON: /api/errors/02c3397a0952c8b1.
Report an issue: GitHub.