How to Fix Terraform Provider Checksum Mismatch Errors
When you run terraform init, you might encounter an error message that says a provider "doesn't match checksums from dependency lock file". This happens when Terraform detects that the provider binary you're trying to download has a different checksum than what's recorded in your .terraform.lock.hcl file.
This error is actually a security feature. Terraform uses the lock file to make sure you're always downloading the exact same provider versions across different systems and runs, which prevents supply chain attacks and ensures consistency.
TLDR: The checksum mismatch error occurs when Terraform's lock file expects specific provider checksums but finds different ones during installation. You can fix it by updating the lock file with terraform init -upgrade, verifying the provider version you need, or regenerating platform-specific checksums. Never ignore this error without understanding why it happened, as it could indicate a security issue.
Why This Error Happens
The .terraform.lock.hcl file stores cryptographic checksums for each provider version you use. Terraform checks these checksums every time you run terraform init to verify the downloaded provider matches what you previously used.
Here are the common scenarios that trigger this error:
You switched platforms (like moving from macOS to Linux) and the lock file only contains checksums for your original platform. Terraform providers are compiled binaries, so each operating system and architecture needs its own checksum entry.
Someone updated the provider version in your Terraform configuration but didn't update the lock file. The lock file still references the old version's checksums while Terraform tries to download the new version.
The lock file was manually edited or partially committed to version control, causing inconsistencies between what's in the file and what Terraform expects.
In rare cases, the provider was actually compromised or corrupted during download, which is why you should never automatically bypass this error without investigating.
Checking Your Current Provider Version
Before fixing the error, you should verify which provider version your configuration requires and what's in your lock file.
# View the required provider version in your configuration
cat main.tf | grep -A 5 "required_providers"
This shows your provider version constraints. You might see something like:
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}
Now check what version is locked:
# View the currently locked provider version
cat .terraform.lock.hcl | grep -A 10 "provider.*aws"
The lock file contains the exact version currently pinned, along with its checksums for different platforms.
Solution 1: Update the Lock File for Your Platform
If you're working on a different platform than your teammates (for example, they use Linux and you use macOS), you need to add checksums for your platform to the existing lock file.
# Add checksums for your current platform without changing versions
terraform providers lock \
-platform=linux_amd64 \
-platform=darwin_amd64 \
-platform=darwin_arm64 \
-platform=windows_amd64
This command downloads the provider for each specified platform and adds their checksums to the lock file. It's particularly useful in teams where developers use different operating systems.
The -platform flag uses the format {OS}_{ARCH}. Common combinations:
linux_amd64for standard Linux servers and most CI/CD systemsdarwin_amd64for Intel-based Macsdarwin_arm64for Apple Silicon Macs (M1, M2, etc.)windows_amd64for Windows systems
After running this, commit the updated lock file so your entire team has all necessary checksums.
Solution 2: Upgrade to the Latest Provider Version
If you want to upgrade to a newer provider version that satisfies your version constraints, use the upgrade flag:
# Upgrade providers to the latest version matching your constraints
terraform init -upgrade
This tells Terraform to:
- Resolve the newest provider version that matches your
versionconstraint in the configuration - Download that provider
- Update the lock file with new checksums
For example, if your constraint is ~> 5.0 and you currently have 5.23.0 locked, this might upgrade you to 5.47.0 (or whatever the latest 5.x version is).
After upgrading, review the provider's changelog to understand what changed between versions. Major version upgrades especially can introduce breaking changes:
# See what changed after the upgrade
git diff .terraform.lock.hcl
Solution 3: Regenerate the Lock File Completely
If your lock file is corrupted or you want to start fresh, you can delete it and let Terraform recreate it:
# Remove the existing lock file
rm .terraform.lock.hcl
# Remove cached providers
rm -rf .terraform/providers
# Initialize and create a fresh lock file
terraform init
This approach downloads the providers fresh and generates a new lock file from scratch. It's useful when the lock file has been manually edited incorrectly or has corruption.
Be careful with this approach in production environments. Make sure you know which provider versions you're pinning to, or you might accidentally upgrade to versions that break your infrastructure code.
Working With CI/CD Systems
CI/CD pipelines often run into checksum issues because they typically run on Linux, but developers might use macOS or Windows locally.
Development Flow:
Developer (macOS) -----> Git Repository -----> CI System (Linux)
| | |
Runs terraform Lock file Checksum error!
on darwin_arm64 only contains (needs linux_amd64)
darwin checksums
To prevent this, make sure your lock file includes checksums for all platforms before committing:
# Run this before committing your Terraform code
terraform providers lock \
-platform=linux_amd64 \
-platform=darwin_amd64 \
-platform=darwin_arm64
You can also add this as a pre-commit hook or as part of your CI/CD pipeline validation:
# In your CI/CD pipeline, verify the lock file is valid
terraform init -backend=false
The -backend=false flag skips backend initialization, making the check faster. If the lock file has the right checksums for your CI platform, this will succeed.
Understanding the Lock File Structure
The lock file uses HCL format and looks like this:
provider "registry.terraform.io/hashicorp/aws" {
version = "5.23.0"
constraints = "~> 5.0"
hashes = [
"h1:KxXxvCfXlATIkGRTI1q2NkXy5BmJgB8I8Y/DiLFBLiE=",
"zh:1a2b3c4d5e6f...",
"zh:6f5e4d3c2b1a...",
]
}
The version field shows the exact version currently locked. The constraints field shows what was specified in your Terraform configuration. The hashes array contains checksums for each platform this provider has been downloaded for.
Each hash starting with zh: is a SHA-256 checksum for a specific platform's provider binary. The more platforms your team uses, the more hashes you'll have.
When to Be Concerned
While most checksum mismatches are benign (caused by platform differences or version updates), you should investigate carefully if:
- The error appears suddenly on the same machine where it worked before without any configuration changes
- You're downloading from an unofficial mirror or proxy
- The provider version in the error message doesn't match what you expect
- Other team members aren't experiencing the same issue
In these cases, verify you're downloading from the official Terraform Registry:
# Check where Terraform is downloading providers from
terraform version -json | grep -i provider
Make sure the source in your configuration uses the official registry:
terraform {
required_providers {
aws = {
source = "hashicorp/aws" # Should be from HashiCorp's official namespace
version = "~> 5.0"
}
}
}
Preventing Future Checksum Issues
Keep your lock file in version control. It's meant to be committed alongside your Terraform configuration files. This ensures everyone on your team uses identical provider versions.
When reviewing pull requests that modify Terraform code, check if the lock file was updated appropriately:
# See if the lock file changed in a branch
git diff main -- .terraform.lock.hcl
Use version constraints that give you control over when providers upgrade. Instead of version = ">= 5.0" which allows any version 5.0 or higher, use version = "~> 5.23" which only allows patch releases of 5.23.x:
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.23" # Only allows 5.23.x versions
}
}
}
This prevents unexpected provider upgrades that might introduce breaking changes.
The checksum verification is working as intended when you see these errors. It's protecting your infrastructure from potentially compromised or incorrect providers. Taking a moment to understand why the checksums don't match is always worth it.
Found an issue?