Terraform Provider Version Conflict: How to Fix
Fix Terraform provider version conflicts between modules, lock files, and constraint mismatches. Resolve dependency lock errors, upgrade providers safely
DevOps
Fix the Terraform 'Backend configuration changed' error. Migrate state between backends (local to S3, S3 to S3), resolve lock conflicts
# Option 1: Migrate state to the new backend
terraform init -migrate-state
# Option 2: Start fresh (ignore existing state)
terraform init -reconfigure⚠️ Use -migrate-state unless you're certain you want to abandon the existing state.
Error: Backend configuration changed
A change in the backend configuration has been detected, which may require
migrating existing state.
If you wish to attempt automatic migration of the state, use
"terraform init -migrate-state".
If you wish to store the current configuration with no changes to the state,
use "terraform init -reconfigure".This appears when you change the backend block in your Terraform configuration.
# Before: local backend (default)
# No backend block — state in terraform.tfstate
# After: S3 backend
terraform {
backend "s3" {
bucket = "my-tf-state"
key = "prod/terraform.tfstate"
region = "us-east-1"
dynamodb_table = "terraform-locks"
encrypt = true
}
}terraform init -migrate-state
# Terraform will ask: "Do you want to copy existing state to the new backend?"
# Answer: yes# Changed the key path
terraform {
backend "s3" {
bucket = "my-tf-state"
key = "v2/prod/terraform.tfstate" # Changed from "prod/terraform.tfstate"
region = "us-east-1"
}
}terraform init -migrate-state
# State migrates from old key to new key# Remove the backend block entirely
terraform {
# No backend — reverts to local
}terraform init -migrate-state
# State downloaded from S3 to local terraform.tfstate# Before
terraform {
backend "s3" {
bucket = "my-tf-state"
key = "prod/terraform.tfstate"
region = "us-east-1"
}
}
# After
terraform {
backend "gcs" {
bucket = "my-tf-state-gcs"
prefix = "prod"
}
}terraform init -migrate-state
# State migrates from S3 to GCS# Always backup before migration
terraform state pull > state-backup.jsonEdit your .tf file with the new backend settings.
terraform init -migrate-stateTerraform will:
# Check state is readable from new backend
terraform state list
# Plan should show no changes
terraform plan
# No changes. Your infrastructure matches the configuration.# If migrated from local to S3, you can remove the local file
rm terraform.tfstate terraform.tfstate.backup| Flag | Effect |
|---|---|
-migrate-state | Copies existing state to the new backend |
-reconfigure | Configures new backend, ignores existing state |
# ✅ Safe — keeps your state
terraform init -migrate-state
# ⚠️ Dangerous — you lose track of existing resources
terraform init -reconfigure
# Terraform "forgets" about all managed resources
# Next plan will want to create everything from scratchUse -reconfigure only when:
Error: Error acquiring the state lock
Lock Info:
ID: abc123-def456
Path: my-tf-state/prod/terraform.tfstate
Operation: OperationTypeAnother process holds the lock. Wait for it to finish, or force-unlock:
terraform force-unlock abc123-def456
terraform init -migrate-state# The old backend is unreachable — use reconfigure with manual state copy
# 1. Get state from old backend manually (S3 console, etc.)
# 2. Configure new backend
terraform init -reconfigure
# 3. Push state to new backend
terraform state push state-backup.jsonIf you only changed backend variables (not the backend type), and the state is already where you want it:
terraform init -reconfigure# If migration fails halfway:
# 1. Check if state exists in new backend
terraform state list
# 2. If empty, restore from backup
terraform state push state-backup.json
# 3. If state is in new backend, you're fine — continue workingWhen Terraform says "backend configuration changed," use terraform init -migrate-state to safely move your state. Always backup with terraform state pull before migrating. Use -reconfigure only when you don't need to preserve existing state. The most common migration — local to S3 — takes under a minute and Terraform handles everything automatically.
Fix Terraform provider version conflicts between modules, lock files, and constraint mismatches. Resolve dependency lock errors, upgrade providers safely
Fix the Terraform 'Reference to undeclared resource' error. Causes include typos, missing resources, wrong module references, and for_each/count confusion.
Fix the Terraform 'An argument named X is not expected here' error. Common causes include wrong provider version, deprecated arguments, typos
Fix Docker provider connection refused errors in Terraform. Covers Docker daemon socket permissions, TLS configuration, and remote host setup.