{"record":{"id":"0aa89e6419895ba8","repo":"hashicorp/terraform","slug":"the-workspace-name-q-is-not-allowed-the-name-mu","errorCode":null,"errorMessage":"\nThe workspace name %q is not allowed. The name must contain only URL safe\ncharacters, contain no path separators, and not be an empty string.\n","messagePattern":"\nThe workspace name %q is not allowed\\. The name must contain only URL safe\ncharacters, contain no path separators, and not be an empty string\\.\n","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/arguments/workspace_new.go","lineNumber":59,"sourceCode":"\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\n}\n","sourceCodeStart":41,"sourceCodeEnd":71,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/arguments/workspace_new.go#L41-L71","documentation":"Thrown by terraform workspace new when the provided workspace name fails the ValidWorkspaceName check. ValidWorkspaceName returns true only if the name is non-empty and equals its own url.PathEscape output, meaning it must contain only URL-safe characters with no path separators. The error message is defined by the EnvInvalidName constant.","triggerScenarios":"Running terraform workspace new <name> where name contains slashes, backslashes, spaces, special characters, or is empty. ValidWorkspaceName returns false because name != url.PathEscape(name), triggering fmt.Errorf(EnvInvalidName, name).","commonSituations":"Using names with slashes (e.g., team/workspace); including spaces or special characters (@, :, etc.); using path-like names that resemble directories; empty string from environment variable expansion.","solutions":["Use only alphanumeric characters, hyphens, and underscores in workspace names","Remove any path separators (/ or \\) from the name","Replace spaces and special characters with hyphens","Ensure the name variable is non-empty"],"exampleFix":"# before\nterraform workspace new \"team/dev-env\"\n\n# after\nterraform workspace new \"team-dev-env\"","handlingStrategy":"validation","validationCode":"// Mirror Terraform's ValidWorkspaceName before invoking terraform workspace new\nfunc validWorkspaceName(name string) bool {\n    if name == \"\" {\n        return false\n    }\n    return name == url.PathEscape(name)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Restrict workspace names to alphanumeric characters, hyphens, and underscores","Avoid path separators (/ and \\) in workspace names","Validate names in automation before running terraform workspace new","Use url.PathEscape equivalence as the validation rule to match Terraform exactly"],"tags":["workspace","validation","url-safe","naming"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}