hashicorp/terraform · error
Expected a single argument: NAME.
Error message
Expected a single argument: NAME.
What it means
Returned at workspace_new.go:51 when 'terraform workspace new' is invoked with a number of positional arguments that is not exactly 1. The command requires exactly one positional argument: the workspace NAME. Unlike delete/select, this uses a strict 'len(args) != 1' check, so both zero arguments and two-or-more arguments trigger it.
Solutions
- Provide exactly one workspace name: 'terraform workspace new <workspace-name>'.
- Create workspaces one at a time.
- Validate the workspace name variable is non-empty and single-valued in scripts.
Example fix
// before terraform workspace new // error: Expected a single argument: NAME. // after terraform workspace new my-new-workspace
Defensive patterns
Strategy: validation
Validate before calling
// Validate exactly one name is provided before calling workspace new:
// if len(names) != 1 {
// return fmt.Errorf("workspace new requires exactly one name")
// }
// exec.Command("terraform", "workspace", "new", names[0]) Prevention
- Provide exactly one workspace name to 'terraform workspace new'.
- Validate argument count in wrapper scripts.
- Create workspaces individually, not in batch.
When it happens
Trigger: Running 'terraform workspace new' with no name, or 'terraform workspace new name1 name2'. workspace_new.go:49-50 checks 'len(args) != 1' immediately after flag parsing.
Common situations: Forgetting to specify a workspace name; trying to create multiple workspaces in one command; shell scripts passing empty or multiple values.
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/96c2b89b560e0e41.
Report an issue: GitHub.
Appendix: source
Thrown at internal/command/arguments/workspace_new.go:51
var stateLock bool
var stateLockTimeout time.Duration
var statePath string
cmdFlags := defaultFlagSet("workspace new")
cmdFlags.BoolVar(&stateLock, "lock", true, "lock state")
cmdFlags.DurationVar(&stateLockTimeout, "lock-timeout", 0, "lock timeout")
cmdFlags.StringVar(&statePath, "state", "", "terraform state file")
if err := cmdFlags.Parse(args); err != nil {
diags = diags.Append(tfdiags.Sourceless(
tfdiags.Error,
"Failed to parse command-line flags",
err.Error(),
))
}
// `workspace new` takes only one positional argument: workspace name.
args = cmdFlags.Args()
if len(args) != 1 {
diags = diags.Append(errors.New("Expected a single argument: NAME.")) // Recreating pre-existing error from command package
}
// Obtain and validate name argument, but only if there is the expected number of arguments.
var name string
if len(args) == 1 {
name = args[0]
if !ValidWorkspaceName(name) {
diags = diags.Append(fmt.Errorf(EnvInvalidName, name))
}
}
return &WorkspaceNew{
Workspace: Workspace{ViewType: ViewHuman},
Name: name,
Lock: stateLock,
LockTimeout: stateLockTimeout,
StatePath: statePath,
}, diagsView on GitHub (pinned to d32a084675)