OpenTofu workspace does not exist in CI
OpenTofu tried to select a named workspace that does not exist in the backend. In CI, a fresh working directory only has the default workspace until one is created, so selecting a per-environment workspace fails.
What this error means
A tofu workspace select prod step fails with "workspace \"prod\" does not exist" before plan or apply runs.
tofu
Error: Workspace "prod" does not exist
Use "tofu workspace new" to create the workspace, or select an existing one.Common causes
The workspace was never created in this backend
CI selects a workspace that exists in someone's local state but was never created in the shared backend.
A fresh checkout only knows the default workspace
Before init and selection, only default exists, so a bare select of another name fails.
How to fix it
Select or create in one step
- Run init first so the backend is initialized.
- Use
tofu workspace select -or-createso the workspace is created if absent. - Then run plan or apply against it.
Terminal
tofu init
tofu workspace select -or-create prod
tofu planCreate the workspace explicitly
On older tofu without -or-create, create then select.
Terminal
tofu workspace new prod || tofu workspace select prodHow to prevent it
- Use
tofu workspace select -or-createin CI. - Initialize the backend before selecting a workspace.
- Standardize workspace names across environments.
Related guides
OpenTofu -var / tfvars not found or unassigned in CIFix OpenTofu variable errors in CI - "No value for required variable" or a missing tfvars file. Pass values w…
OpenTofu "Backend configuration changed" in CIFix OpenTofu "Error: Backend configuration changed" in CI - the backend block differs from the initialized st…
OpenTofu "Error acquiring the state lock" in CIFix OpenTofu "Error: Error acquiring the state lock" in CI - another run holds the lock, or a crashed job lef…