Error: Inconsistent dependency lock file: "no version is selected" after adding a provider
Fixes Terraform's "Error: Inconsistent dependency lock file ... no version is selected", which appears after adding a provider or module without re-running init. Use when terraform init fails on lock selections. Not for registry constraint errors ("Failed to query available provider packages").
TL;DR
Your .terraform.lock.hcl does not cover a provider your configuration now requires. That happens when you add a provider (or a module that needs one) after the last terraform init. Run terraform init -upgrade to record the new selection, commit the lock file, and move on.
The error
Error: Inconsistent dependency lock file
- provider registry.terraform.io/hashicorp/random: required by this
configuration but no version is selectedAnother common shape:
Error: Inconsistent dependency lock file. The following dependency selections recorded in the lock file are inconsistent...Steps to fix
- Confirm the cause: you (or a merged PR) added a provider to
required_providersor added a module that pulls one in, without re-running init.
- Expected:
git log --oneline -3 -- .terraform.lock.hclshows the lock file is older than the config change.
- Run
terraform init -upgrade.
- Expected: Terraform selects versions for the new providers and rewrites
.terraform.lock.hcl.initsucceeds.
- Commit the updated
.terraform.lock.hcl.
- Expected:
git statusshows the lock file modified; CI will now use the same selections.
- Run
terraform planto confirm everything resolves.
- Expected: plan starts without lock errors.
When to use this
terraform initfails withInconsistent dependency lock fileafter adding a provider, adding a module, or pulling a branch that did either.
When NOT to use this
Failed to query available provider packagesmeans the registry cannot satisfy your version constraints (a constraint problem, not a lock problem). If the lock file is committed and CI still fails, the committed file is stale: regenerate it locally and commit.
Compatibility
- Terraform 0.14+ (lock file introduced).
-upgradebehavior is stable across 1.x.
Root cause
The lock file pins the exact provider versions and hashes your configuration resolved to. Adding a new provider requirement makes the recorded selections incomplete, and Terraform refuses to guess: it errors rather than silently picking a version that might differ from what a teammate gets.
Edge cases
- If your repo gitignores
.terraform.lock.hcl, every fresh clone re-resolves and you lose reproducibility; commit the lock file instead. terraform init -upgradeupgrades everything; to add one provider without moving others, temporarily narrow with-upgrade=falseis not possible, so review the plan diff after upgrading.- With
dev_overridesin the CLI config, Terraform skips lock entries for those providers (1.16+ warns about it).