Error: Invalid workspace selection: "failed to find workspace" in the backend
Fixes Terraform's "Error: Invalid workspace selection ... failed to find workspace" when the configured workspace does not exist in the backend. Use when init fails after a backend migration or on a fresh checkout. Create the workspace or fix the cloud/backend block; not for local workspace name typos.
TL;DR
Terraform is pointed at a workspace that does not exist in your backend (Terraform Cloud/Enterprise, or a local name you never created). Create the workspace where the backend expects it, or fix the workspace name in your cloud/backend block.
The error
Error: Invalid workspace selection
Terraform failed to find workspace "grafana" in organization wifihaven.Steps to fix
- Identify where the name comes from: the
cloud { workspaces { name = "..." } }block, backend config, orterraform workspace select.
- Expected: you find the exact expected name.
- Check what exists: in Terraform Cloud, open the organization and list workspaces; locally, run
terraform workspace list.
- Expected: the expected name is absent, confirming the diagnosis.
- Either create the workspace (matching execution mode and VCS settings), or correct the name in config and run
terraform init -reconfigure.
- Expected: init selects the workspace successfully.
- Re-run the failed command.
- Expected: plan/apply proceeds.
When to use this
terraform initfails withInvalid workspace selectionafter a backend migration, a fresh checkout, or a renamed workspace.
When NOT to use this
- A typo in
terraform workspace select [name]on a local backend is fixed byterraform workspace new [name]or selecting the right one. Do not create production workspaces casually to silence this.
Compatibility
- All Terraform versions; Terraform 1.16+ additionally errors if the selected workspace becomes invalid out-of-band.
Root cause
The backend resolves the workspace name at init. If the workspace was never created, was deleted, or the config points at the wrong org/name after a migration, resolution fails before any state is touched.
Edge cases
cloudblock withtagsselects workspaces by tag; a missing tag match fails the same way.- Local backend:
terraform workspace selectwithTF_WORKSPACEenv var set can surprise you; check the env. - After creating the workspace, the first apply starts from empty state; confirm that is what you want before applying.
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.