Skip to content
Latchkey

Terraform "Backend initialization required, please run terraform init"

Terraform stores backend setup under .terraform/, which is not committed. A CI job that runs plan/apply without an earlier init in the same workspace has no backend configured.

What this error means

terraform plan or terraform apply refuses to run and says backend initialization is required, often after a terraform init step was skipped, cached incorrectly, or run in a different directory.

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

Reason: Initial configuration of the requested backend "s3"

The "backend" is the interface that Terraform uses to store state and
perform operations.

Common causes

init never ran in this job

The pipeline jumped straight to plan/apply, or ran init in a different working directory than the one plan uses.

.terraform was not persisted

init ran in an earlier job whose .terraform/ directory was not cached or passed to the plan job.

Backend block was added or changed

A new or modified backend block requires a fresh init before any operation.

How to fix it

Run init in the same directory before plan

Terminal
terraform -chdir=infra init -input=false
terraform -chdir=infra plan -input=false

Persist .terraform across jobs

  1. If init and plan are separate jobs, cache or upload the .terraform/ directory and the lock file.
  2. Restore them in the plan/apply job before running.
  3. Prefer running init+plan in one job to avoid the handoff entirely.

How to prevent it

  • Make terraform init the first step of every Terraform job.
  • Use -chdir consistently so all steps target the same module directory.
  • Re-init whenever the backend block changes.

Related guides

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