Skip to content
Latchkey

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

  1. Run init first so the backend is initialized.
  2. Use tofu workspace select -or-create so the workspace is created if absent.
  3. Then run plan or apply against it.
Terminal
tofu init
tofu workspace select -or-create prod
tofu plan

Create the workspace explicitly

On older tofu without -or-create, create then select.

Terminal
tofu workspace new prod || tofu workspace select prod

How to prevent it

  • Use tofu workspace select -or-create in CI.
  • Initialize the backend before selecting a workspace.
  • Standardize workspace names across environments.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →