# Terraform: "Backend initialization required, please run terraform init"

## What you are seeing

```
Error: Backend initialization required, please run "terraform init"

Reason: Unset backend "s3"
...
```

The `.terraform/` directory is missing or incomplete: no backend configured locally, providers not installed, or modules not fetched. Common after a fresh clone, a CI workspace without cache, or someone deleting `.terraform`.

## First response

1. Run `terraform init`. That is the fix in the common case.
2. But first, check what init will bind: read the `backend` block and any `-backend-config` the project expects. Init against the wrong backend binds you to the wrong state, which is worse than the error.
3. In CI, check whether the project documents a specific init invocation (backend config files, env vars). Repos that need `init -backend-config=backends/prod.hcl` will fail or misbehave with bare `init`.

## Rules for agents

1. `.terraform/` is disposable; the state file is not. Deleting `.terraform` and re-running init is safe. Touching the state file is not.
2. If init now asks to migrate state (`-migrate-state`), stop. The backend config differs from what was initialized before. Back up state first (`terraform state pull > backup.json`) and understand the change before answering yes.
3. Never commit `.terraform/` to git. It is local installation cache. The lock file is committed; the installation directory is not.
4. If init fails on provider installation (network, registry), that is a separate problem from backend init. Fix them in order: backend first, then providers.
