{"record":{"id":"96c2b89b560e0e41","repo":"hashicorp/terraform","slug":"expected-a-single-argument-name-96c2b8","errorCode":null,"errorMessage":"Expected a single argument: NAME.","messagePattern":"Expected a single argument: NAME\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/arguments/workspace_new.go","lineNumber":51,"sourceCode":"\tvar stateLock bool\n\tvar stateLockTimeout time.Duration\n\tvar statePath string\n\tcmdFlags := defaultFlagSet(\"workspace new\")\n\tcmdFlags.BoolVar(&stateLock, \"lock\", true, \"lock state\")\n\tcmdFlags.DurationVar(&stateLockTimeout, \"lock-timeout\", 0, \"lock timeout\")\n\tcmdFlags.StringVar(&statePath, \"state\", \"\", \"terraform state file\")\n\tif err := cmdFlags.Parse(args); err != nil {\n\t\tdiags = diags.Append(tfdiags.Sourceless(\n\t\t\ttfdiags.Error,\n\t\t\t\"Failed to parse command-line flags\",\n\t\t\terr.Error(),\n\t\t))\n\t}\n\n\t// `workspace new` takes only one positional argument: workspace name.\n\targs = cmdFlags.Args()\n\tif len(args) != 1 {\n\t\tdiags = diags.Append(errors.New(\"Expected a single argument: NAME.\")) // Recreating pre-existing error from command package\n\t}\n\n\t// Obtain and validate name argument, but only if there is the expected number of arguments.\n\tvar name string\n\tif len(args) == 1 {\n\t\tname = args[0]\n\t\tif !ValidWorkspaceName(name) {\n\t\t\tdiags = diags.Append(fmt.Errorf(EnvInvalidName, name))\n\t\t}\n\t}\n\n\treturn &WorkspaceNew{\n\t\tWorkspace:   Workspace{ViewType: ViewHuman},\n\t\tName:        name,\n\t\tLock:        stateLock,\n\t\tLockTimeout: stateLockTimeout,\n\t\tStatePath:   statePath,\n\t}, diags","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/arguments/workspace_new.go#L33-L69","documentation":"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.","triggerScenarios":"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.","commonSituations":"Forgetting to specify a workspace name; trying to create multiple workspaces in one command; shell scripts passing empty or multiple values.","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."],"exampleFix":"// before\nterraform workspace new\n// error: Expected a single argument: NAME.\n\n// after\nterraform workspace new my-new-workspace","handlingStrategy":"validation","validationCode":"// Validate exactly one name is provided before calling workspace new:\n// if len(names) != 1 {\n//     return fmt.Errorf(\"workspace new requires exactly one name\")\n// }\n// exec.Command(\"terraform\", \"workspace\", \"new\", names[0])","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Provide exactly one workspace name to 'terraform workspace new'.","Validate argument count in wrapper scripts.","Create workspaces individually, not in batch."],"tags":["terraform","cli","workspace","argument-validation"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}