hashicorp/terraform · error
Expected a single argument: NAME.
Error message
Expected a single argument: NAME.
What it means
Returned by ParseWorkspaceNew (workspace_new.go:51) when, after flag parsing, the number of positional arguments is not exactly one — i.e. 'terraform workspace new' was called with zero or more than one name. The command requires exactly one workspace NAME (then optionally validated by ValidWorkspaceName).
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 c9def3e214)
Solutions
- Provide exactly one workspace name: 'terraform workspace new NAME'.
- Create additional workspaces with separate invocations.
- Verify the name passes workspace naming rules (ValidWorkspaceName) to avoid a follow-on error.
Example fix
# before $ terraform workspace new # after $ terraform workspace new my-workspace
Defensive patterns
Strategy: validation
Validate before calling
// 'workspace new' requires exactly one NAME.
func validateNewArgs(args []string) error {
if len(args) != 1 {
return fmt.Errorf("workspace new takes exactly one NAME, got %d", len(args))
}
return nil
} Prevention
- Pass exactly one workspace name to 'terraform workspace new'.
- Create multiple workspaces with separate invocations.
- Validate the name against workspace naming rules beforehand.
When it happens
Trigger: Line 49-51: len(args) != 1 after cmdFlags.Parse; covers both 'too few' and 'too many' positional names.
Common situations: Running 'terraform workspace new' with no name; passing flags after the name in a way that confuses the parser; attempting to create several workspaces at once.
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
- default workspace not supported You can create a new workspa
AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07).
Data as JSON: /api/errors/96c2b89b560e0e41.
Report an issue: GitHub.