Terragrunt remote_state backend generation errors in CI
A remote_state block tells Terragrunt to generate the backend configuration for each module. It fails when a module already declares its own backend block, or when the generated file collides with a committed one, producing a duplicate or overwrite error.
What this error means
terragrunt init fails with "Backend configuration changed" or Terraform reports two backend blocks, because remote_state generated a backend.tf that conflicts with a committed one.
Error: Duplicate backend configuration
on backend.tf line 1:
1: terraform { backend "s3" { ... } }
A module may have only one backend configuration block, but remote_state also generated one.Common causes
The module already has a hand-written backend block
remote_state generates backend.tf, but the module source also declares a backend block, so Terraform sees two.
The generate settings do not allow safe overwrite
A stale committed backend file blocks the generated one because if_exists is not set to overwrite Terragrunt-owned files.
How to fix it
Let remote_state own the backend
Remove the hand-written backend block from the module and let remote_state generate it with overwrite_terragrunt.
remote_state {
backend = "s3"
generate = { path = "backend.tf", if_exists = "overwrite_terragrunt" }
config = {
bucket = "acme-tfstate"
key = "${path_relative_to_include()}/terraform.tfstate"
region = "us-east-1"
}
}Remove the committed backend block
- Delete any
backend "..." {}block inside the module source. - Keep the single generated backend from remote_state.
- Re-run init so only one backend exists.
How to prevent it
- Keep backend configuration exclusively in remote_state.
- Do not commit a backend block in modules Terragrunt drives.
- Use
if_exists = "overwrite_terragrunt"for the generated file.