hashicorp/terraform · error
Expected a single argument: NAME.
Error message
Expected a single argument: NAME.
What it means
Returned by ParseWorkspaceDelete (workspace_delete.go:52) when, after flag parsing, zero positional arguments remain — i.e. the user ran 'terraform workspace delete' with no NAME. The command requires exactly one workspace name to delete. ParseWorkspaceDelete still returns a WorkspaceDelete with an empty Name and the diagnostics, so the caller can choose how to surface it.
Source
Thrown at internal/command/arguments/workspace_delete.go:52
var stateLock bool
var stateLockTimeout time.Duration
cmdFlags := defaultFlagSet("workspace delete")
cmdFlags.BoolVar(&force, "force", false, "force removal of a non-empty workspace")
cmdFlags.BoolVar(&stateLock, "lock", true, "lock state")
cmdFlags.DurationVar(&stateLockTimeout, "lock-timeout", 0, "lock timeout")
if err := cmdFlags.Parse(args); err != nil {
diags = diags.Append(tfdiags.Sourceless(
tfdiags.Error,
"Failed to parse command-line flags",
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."))
}
}View on GitHub (pinned to c9def3e214)
Solutions
- Provide the workspace name: 'terraform workspace delete NAME'.
- List workspaces first with 'terraform workspace list' to get the exact name.
- If scripting, validate the name variable is non-empty before invoking the command.
Example fix
# before $ terraform workspace delete # after $ terraform workspace delete my-old-workspace
Defensive patterns
Strategy: validation
Validate before calling
// Validate delete args before invoking the CLI/parser.
func validateDeleteName(args []string) error {
if len(args) == 0 {
return errors.New("workspace delete requires a NAME argument")
}
return nil
} Prevention
- Always pass an explicit workspace name to 'terraform workspace delete'.
- In scripts, fail fast if the name variable is empty before calling Terraform.
- Use 'terraform workspace list' to confirm names before deletion.
When it happens
Trigger: Line 49-52: cmdFlags.Args() returns len(args)==0, so errors.New("Expected a single argument: NAME.") is appended to diags.
Common situations: Typing 'terraform workspace delete' without a name; a script that interpolates a variable which expands to empty; alias confusion with 'terraform delete'.
Related errors
- Expected a single argument: NAME.
- Expected a single argument: NAME.
- Too many command line arguments. Did you mean to use -chdir?
- error deleting workspace %s: %v
- Expected a workspace name as an argument, instead got an emp
AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07).
Data as JSON: /api/errors/c22d6007486dacea.
Report an issue: GitHub.