Terraform .terraform.lock.hcl Conflicts and Provider Version Errors: Fix Guide
Getting Terraform lock file conflicts, provider version mismatches, or 'required provider not installed' errors? Here's every cause and how to fix it.
You run terraform init and get errors like:
Error: Failed to install provider
To install aws provider version >= 5.0.0, < 6.0.0, run:
terraform init -upgrade
Or your team pushes a lock file change and CI breaks with:
Error: Inconsistent dependency lock file
The following dependency selections recorded in the lock file are inconsistent
with the current configuration: provider registry.terraform.io/hashicorp/aws
Lock file issues are one of the most confusing Terraform problems. Here's what's happening and how to fix each case.
What is .terraform.lock.hcl?
The lock file records the exact provider versions and checksums that were resolved during the last terraform init. It ensures everyone on the team (and CI) uses the same provider versions.
# .terraform.lock.hcl
provider "registry.terraform.io/hashicorp/aws" {
version = "5.42.0"
constraints = ">= 5.0.0, < 6.0.0"
hashes = [
"h1:abc123...",
"zh:def456...",
]
}The lock file should be committed to git. This is different from terraform.tfstate — the lock file is safe (and important) to commit.
Error 1 — "Inconsistent dependency lock file"
Error: Inconsistent dependency lock file
The following dependency selections recorded in the lock file are inconsistent
with the current configuration:
- provider registry.terraform.io/hashicorp/aws: locked version selection 5.31.0
doesn't match the updated version requirements (~> 5.42)
Cause: Someone updated the provider version constraint in required_providers but didn't update the lock file.
Fix:
# Re-initialize and update the lock file
terraform init -upgrade
# Commit the updated lock file
git add .terraform.lock.hcl
git commit -m "Update terraform provider lock file"Error 2 — "Required provider not installed"
Error: Required plugins are not installed
The working directory for your current root module does not contain the
required provider plugins. To install these plugins, run:
terraform init
Cause: .terraform/ directory is missing (fresh clone, CI environment, or gitignored .terraform/).
Fix: Run terraform init. This downloads providers listed in the lock file:
terraform initIn CI, always run terraform init before terraform plan or terraform apply. The lock file tells Terraform exactly which versions to download.
Error 3 — Lock File Checksum Mismatch
Error: Failed to install provider
...
the current package for registry.terraform.io/hashicorp/aws 5.42.0 does not
match any of the checksums previously recorded in the dependency lock file
Cause: The lock file has checksums for specific platforms (e.g., linux_amd64) but the current machine is a different platform (e.g., darwin_arm64 / Apple Silicon Mac).
By default, terraform init only adds checksums for the current platform. When your Mac generates the lock file and CI runs on Linux, the checksums don't match.
Fix — Add checksums for multiple platforms:
# Add checksums for all platforms you use
terraform providers lock \
-platform=linux_amd64 \
-platform=linux_arm64 \
-platform=darwin_amd64 \
-platform=darwin_arm64 \
-platform=windows_amd64This updates .terraform.lock.hcl with hashes for all platforms. Commit the result.
Error 4 — Provider Version Constraint Conflict
Error: Incompatible provider version
Provider "registry.terraform.io/hashicorp/aws" v5.31.0 does not match
configured version constraint "~> 4.0"; must be between 4.0.0 and 5.0.0.
Cause: Two modules require conflicting versions of the same provider.
Diagnose:
# Show all provider requirements and where they come from
terraform providersExample output:
Providers required by configuration:
├── provider[registry.terraform.io/hashicorp/aws] >= 5.0.0
├── module.vpc
│ └── provider[registry.terraform.io/hashicorp/aws] ~> 4.0 # Conflict!
Fix Option 1 — Update the conflicting module to a newer version:
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 5.0" # Newer version supports AWS provider v5
}Fix Option 2 — Pin the provider version at the root level:
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 4.0, < 6.0" # Range that satisfies both constraints
}
}
}Fix Option 3 — Use provider meta-argument to pass provider to module:
provider "aws" {
version = "~> 5.42"
region = "ap-south-1"
}
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 4.0" # Old module
providers = {
aws = aws # Pass your v5 provider explicitly
}
}Error 5 — Lock File Merge Conflicts in Git
When two developers both run terraform init -upgrade on different branches, the lock file gets git merge conflicts:
<<<<<<< HEAD
version = "5.42.0"
=======
version = "5.44.0"
>>>>>>> feature/update-provider
Fix:
- Accept one version (usually the newer one)
- Delete the conflict markers manually
- Run
terraform initto verify the lock file is valid - Commit
Or use -upgrade to regenerate cleanly:
git checkout main -- .terraform.lock.hcl
terraform init -upgradeError 6 — Provider Not Found in Registry
Error: Failed to query available provider packages
Could not retrieve the list of available versions for provider hashicorp/foo:
provider registry.terraform.io/hashicorp/foo was not found in any of the
search paths
Cause: Provider name is wrong, or it's a community provider with a different namespace.
Fix — Check the correct provider source:
terraform {
required_providers {
# Wrong:
datadog = {
source = "hashicorp/datadog" # Doesn't exist
}
# Correct:
datadog = {
source = "DataDog/datadog" # Community provider, different namespace
}
}
}Find the correct source at registry.terraform.io.
Best Practices to Avoid Lock File Issues
1. Always commit the lock file
# .gitignore — what to ignore
.terraform/
*.tfstate
*.tfstate.backup
*.tfvars # if sensitive
# Do NOT ignore:
# .terraform.lock.hcl2. Use terraform init -upgrade when updating provider versions
# After changing version constraints
terraform init -upgrade
git add .terraform.lock.hcl
git commit -m "chore: upgrade terraform providers"3. Add multi-platform hashes in mixed teams
If your team uses Macs and CI runs Linux:
terraform providers lock \
-platform=linux_amd64 \
-platform=darwin_arm644. Pin provider versions explicitly
Avoid loose constraints like >= 3.0. Pin to minor versions:
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.42" # Allow 5.42.x patches but not 5.43+
}
}
required_version = "~> 1.7"
}Quick Reference
| Error | Cause | Fix |
|---|---|---|
| Inconsistent lock file | Version constraint changed without updating lock | terraform init -upgrade |
| Required provider not installed | .terraform/ missing | terraform init |
| Checksum mismatch | Different platform generated lock file | terraform providers lock -platform=... |
| Version constraint conflict | Modules need incompatible versions | Update module or use version range |
| Git merge conflict in lock file | Two branches both updated lock | Accept one version, re-init |
| Provider not found | Wrong namespace in source | Check registry.terraform.io |
Lock file errors are almost always fixable with terraform init -upgrade plus a lock file commit. The multi-platform checksum issue is the sneaky one — add it to your team's setup if you have mixed Mac/Linux environments.
Practice Terraform on real AWS infrastructure — DigitalOcean gives $200 free credit. Also, KodeKloud has Terraform hands-on labs that cover provider versioning and state management in depth.
Stay ahead of the curve
Get the latest DevOps, Kubernetes, AWS, and AI/ML guides delivered straight to your inbox. No spam — just practical engineering content.
Related Articles
Terraform Plan Succeeds But Apply Fails: How to Fix State Drift and Provider Errors
Your terraform plan looks clean but apply blows up? Here's how to fix provider conflicts, state drift, and dependency errors step by step.
Terraform Plan Shows Unexpected Destroy — How to Fix It
Fix Terraform plan showing unexpected resource destruction. Covers state drift, provider upgrades, import mismatches, lifecycle rules, and safe recovery strategies.
Terraform S3 Access Denied — How to Fix It (2026)
Getting AccessDenied when Terraform tries to read or write your S3 backend? Here's every cause and the exact fix.