hashicorp/terraform · error
Expected a single argument: NAME.
Error message
Expected a single argument: NAME.
What it means
Returned at workspace_delete.go:52 when 'terraform workspace delete' is invoked with zero positional arguments after flag parsing. The command requires exactly one positional argument: the workspace NAME. This is a CLI argument validation error appended to diagnostics.
Solutions
- Provide the workspace name: 'terraform workspace delete <workspace-name>'.
- Check shell scripts for unquoted or empty variables passed as the workspace name.
- Run 'terraform workspace list' to see available workspace names.
Example fix
// before terraform workspace delete // error: Expected a single argument: NAME. // after terraform workspace delete my-workspace
Defensive patterns
Strategy: validation
Validate before calling
// Before calling workspace delete, validate the name is provided:
// if name == "" {
// return fmt.Errorf("workspace name is required")
// }
// exec.Command("terraform", "workspace", "delete", name) Prevention
- Validate workspace name is non-empty before passing to terraform CLI.
- Use shell scripts that check for required arguments before invoking terraform.
- Provide argument help text in wrapper scripts.
When it happens
Trigger: Running 'terraform workspace delete' with no workspace name argument, or providing only flags (e.g., 'terraform workspace delete -force' with no name). workspace_delete.go:50 checks 'len(args) == 0' after cmdFlags.Args().
Common situations: Typing 'terraform workspace delete' and forgetting the name; shell scripts that pass an empty variable as the workspace name; copy-paste errors omitting the workspace argument.
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/c22d6007486dacea.
Report an issue: GitHub.
Appendix: 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 d32a084675)