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
- Provide the workspace name: 'terraform workspace select <workspace-name>'.
- Run 'terraform workspace list' to see available workspace names.
- 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
- Always pass a workspace name to 'terraform workspace select'.
- List available workspaces first if unsure of the name.
- Validate variables in scripts are non-empty before use.
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
- Expected a single argument: NAME.
- Expected a single argument: NAME.
- Too many command line arguments. Did you mean to use -chdir?
- A managed resource address is required. Importing into a…
- errInitCopyNotEmpty
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)