Error: Backend initialization required, please run "tofu init"
Fixes OpenTofu's 'Error: Backend initialization required, please run tofu init' by initializing or reinitializing the backend. Use when plan or apply refuses in a fresh checkout or after a backend config change. Not for backend credential errors.
TL;DR: Your working directory isn't initialized for the backend in your config. Run tofu init. If you changed the backend config itself, pick tofu init -migrate-state (keep your state) or tofu init -reconfigure (point at a fresh state).
Error: Backend initialization required, please run "tofu init"
Reason: Backend configuration block has changed
The "backend" is the interface that OpenTofu uses to store state,
perform operations, etc. If this message is showing up, it means that the
OpenTofu configuration you're using is using a custom configuration for
the OpenTofu backend.
Changes to backend configurations require reinitialization. This allows
OpenTofu to set up the new configuration, copy existing state, etc. Please run
"tofu init" with either the "-reconfigure" or "-migrate-state" flags to
use the current configuration.Steps
- If this is a fresh checkout (no
.terraform/directory), just runtofu init.
Expected: Initializing the backend... then OpenTofu has been successfully initialized!
- If you CHANGED the backend block (local to S3, new bucket, new key), decide:
- Keep the existing state:
tofu init -migrate-state. tofu copies state from the old backend to the new one. - Point at a fresh/empty state:
tofu init -reconfigure. tofu forgets the old backend entirely.
Expected: init completes; tofu plan works.
- Verify with
tofu plan.
Expected: the backend error is gone.
When this applies
tofu plan/tofu applyin a fresh clone, before any init.- Right after editing the
backendblock. - The
Reason:line saysInitial configuration of the requested backendorBackend configuration block has changed.
When it doesn't apply
- Backend CREDENTIAL errors (
no valid credential sources,AccessDenied) mean init ran but auth failed. Different fix. Error: Failed to save statehappens after apply, not before init.
Tool versions
All OpenTofu versions.
Why it happens
The backend is configured per working directory, in .terraform/. A fresh checkout has no .terraform/; a changed backend block invalidates the cached one. Either way tofu refuses to guess where your state lives and tells you to re-init explicitly.
Edge cases
-migrate-stateprompts before copying; in CI add-input=falseand be sure the migration is what you want.- Deleting
.terraform/and re-running plaintofu initafter a backend change does NOT migrate state; it orphans the old state. Use the flags. - Terragrunt users: a changed
remote_stateblock has the same effect; clear.terragrunt-cacheand re-run so the regenerated backend config is picked up.
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.