## 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

```text
Error: Invalid workspace selection
Terraform failed to find workspace "grafana" in organization wifihaven.
```

## Steps to fix

1. Identify where the name comes from: the `cloud { workspaces { name = "..." } }` block, backend config, or `terraform workspace select`.
   - Expected: you find the exact expected name.
2. 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.
3. 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.
4. Re-run the failed command.
   - Expected: plan/apply proceeds.

## When to use this

- `terraform init` fails with `Invalid workspace selection` after 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 by `terraform 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

- `cloud` block with `tags` selects workspaces by tag; a missing tag match fails the same way.
- Local backend: `terraform workspace select` with `TF_WORKSPACE` env 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.