Terraform: Inconsistent Dependency Lock File

Terraform stops with 'Error: Inconsistent dependency lock file'. Your .terraform.lock.hcl doesn't match the providers your config now needs — often after adding a provider or running in CI. Here's the fix.

BytExplorer 4 min read July 19, 2026

Terraform refuses to run 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: required by this
    configuration but no version is selected

Terraform records the exact provider versions it resolved in a file called .terraform.lock.hcl, so every run and every teammate gets the same versions. This error means that lock file no longer matches what your configuration requires — the config and the lock have drifted apart.

Cause 1: You added or changed a provider

You added a new required_providers entry (or changed a version constraint) but didn't re-run init, so the lock file doesn't know about it yet. This is the most common cause.

terraform init      # re-resolves providers and updates the lock file

If a version constraint changed and init alone won't budge it, allow an upgrade:

terraform init -upgrade

Cause 2: CI runs on a different OS/architecture

The lock file records a provider's hash per platform. If you generated it on macOS (darwin_arm64) and CI runs on Linux (linux_amd64), the hash for CI's platform may be missing — so CI fails even though it works on your laptop.

Record hashes for every platform you run on, then commit the updated lock:

terraform providers lock \
  -platform=linux_amd64 \
  -platform=darwin_arm64

Cause 3: The lock file wasn't committed

If .terraform.lock.hcl isn't in Git, teammates and CI resolve their own versions and drift. Commit the lock file — it's meant to be version-controlled, exactly like package-lock.json.

The checklist

  1. The lock file and your required_providers have drifted apart.
  2. Added/changed a provider? terraform init (or init -upgrade).
  3. CI on a different platform? terraform providers lock -platform=... for each.
  4. Commit .terraform.lock.hcl so everyone resolves the same versions.

Frequently Asked Questions

What causes "Inconsistent dependency lock file" in Terraform? Your .terraform.lock.hcl no longer matches the providers your configuration requires — usually because you added or changed a provider without re-running init, or because CI runs on a platform whose provider hash isn't recorded in the lock.

How do I fix the inconsistent dependency lock file error? Run terraform init (or terraform init -upgrade if a version constraint changed) to re-resolve providers and update the lock file, then commit .terraform.lock.hcl.

Should I commit .terraform.lock.hcl to Git? Yes. It pins exact provider versions so every teammate and CI run resolves the same ones — just like a package-lock.json. Not committing it is a common source of this error.

Put it into practice

Stop reading, start building

This pairs with a hands-on BytExplorer course — do it on your own machine and actually keep the skill.

More in Troubleshooting