terraform state_error ai_generated true

Error: Workspace not found: the workspace does not exist

ID: terraform/tf-workspace-not-found

Also available as: JSON · Markdown
92%Fix Rate
93%Confidence
55Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1 active

Root Cause

Terraform workspace referenced in configuration or CLI does not exist in the backend.

generic

Workarounds

  1. 92% success Create the missing workspace using terraform workspace new
    terraform workspace new WORKSPACE_NAME

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

  2. 90% success Switch to an existing workspace using terraform workspace select
    terraform workspace list to see available workspaces, then terraform workspace select WORKSPACE_NAME

    Sources: https://developer.hashicorp.com/terraform/cli/commands/workspace/select

Dead Ends

Common approaches that don't work:

  1. Edit the .terraform/environment file to force-set the workspace 80% fail

    If the workspace does not exist in the backend, manually setting the file creates an invalid state

  2. Use terraform.workspace in conditions without creating the workspace first 75% fail

    References to terraform.workspace assume the workspace exists; plan fails if it does not

Error Chain

Preceded by: