terraform config_error ai_generated true

Error: Invalid workspace name: Workspace names must start with a letter and may contain only letters, digits, underscores, and hyphens. Name "my workspace" is invalid.

ID: terraform/invalid-terraform-workspace-name

Also available as: JSON · Markdown · 中文
100%Fix Rate
90%Confidence
1Evidence
2023-06-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Terraform v1.5 active
Terraform v1.6 active
Terraform v1.7 active

Root Cause

The workspace name contains spaces or special characters that violate Terraform's naming rules for workspaces.

generic

中文

工作区名称包含空格或特殊字符,违反了 Terraform 对工作区的命名规则。

Official Documentation

https://developer.hashicorp.com/terraform/cli/commands/workspace/new

Workarounds

  1. 100% success Use underscore or hyphen instead of space: 'terraform workspace new my_workspace' or 'terraform workspace new my-workspace'. This is the only valid approach.
    Use underscore or hyphen instead of space: 'terraform workspace new my_workspace' or 'terraform workspace new my-workspace'. This is the only valid approach.

中文步骤

  1. Use underscore or hyphen instead of space: 'terraform workspace new my_workspace' or 'terraform workspace new my-workspace'. This is the only valid approach.

Dead Ends

Common approaches that don't work:

  1. 95% fail

    Shell escaping doesn't change the workspace name stored in Terraform; the name itself is invalid regardless of how it's passed.

  2. 90% fail

    Quotes only prevent shell splitting; Terraform still validates the name and rejects spaces.

  3. 85% fail

    The environment variable is used to select an existing workspace, not to create one. The name validation still applies.