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,
	}, diags

View on GitHub (pinned to c9def3e214)

Solutions

  1. Provide exactly one workspace name: 'terraform workspace new NAME'.
  2. Create additional workspaces with separate invocations.
  3. 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

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


AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07). Data as JSON: /api/errors/96c2b89b560e0e41. Report an issue: GitHub.