Immutable solution version
Error: Inconsistent dependency lock file
Complete solution
Fixes OpenTofu's 'Error: Inconsistent dependency lock file' by re-resolving provider versions with tofu init -upgrade. Use when tofu init, plan, or apply refuses because .terraform.lock.hcl doesn't match the providers in your configuration. Not for registry network failures or unknown provider sources.
TL;DR: Run tofu init -upgrade. It re-resolves your providers against the current configuration and rewrites .terraform.lock.hcl so the recorded selections match. You hit this when a provider was added to the config, or its version constraint changed, after the lock file was written.
Error: Inconsistent dependency lock file
The following dependency selections recorded in the lock file are
inconsistent with the current configuration:
- provider registry.opentofu.org/hashicorp/random: required by this
configuration but no version is selected
To update the locked dependency selections to match a changed
configuration, run:
tofu init -upgradeSteps
Run
tofu init -upgradein the root module directory. Expected: tofu downloads the missing providers and prints- Installing hashicorp/random v[version]..., ending withOpenTofu has been successfully initialized!Confirm
.terraform.lock.hclnow lists the provider with a selected version and hashes. Expected: aprovider "registry.opentofu.org/hashicorp/random"block withversionandhashesentries.Commit the updated lock file so CI and teammates get the same pins. Expected:
git diff --statshows.terraform.lock.hclmodified.Re-run your original command (
tofu plan/tofu apply). Expected: no lock error; the plan proceeds.
When this applies
- Right after adding a provider, or a resource from a new provider, to your config.
- After changing a
versionconstraint inrequired_providers. - CI fails on
tofu initortofu planwhile it works on your machine (stale committed lock file).
When it doesn't apply
Error: Failed to query available provider packagesmeans tofu can't reach the registry or the provider doesn't exist. That's a network or naming problem, not a lock mismatch.Error: Failed to install providerwith checksum complaints means the lock file hashes don't match the downloads. Different fix.
Tool versions
OpenTofu 1.6 and later. The lock file mechanism is inherited from Terraform 0.14 and up; tofu writes the same .terraform.lock.hcl format.
Why it happens
The lock file records the exact provider versions chosen at the last successful init. When the configuration changes (new provider, new constraint), the recorded selections no longer describe the config, and tofu refuses to guess. -upgrade tells it to pick fresh versions inside your constraints instead of reusing the recorded ones.
Edge cases
- Don't just delete the lock file and re-init. That works locally but throws away the pins your team relies on for reproducible builds. Prefer
-upgrade. - Multi-platform teams: after
-upgradeon one OS, runtofu providers lock -platform=linux_amd64 -platform=darwin_amd64 -platform=darwin_arm64so runners on other platforms don't hit hash mismatches. - If the lock file is gitignored, every fresh clone can hit this. Either commit it, or make
tofu init -upgradepart of your setup script.
Evidence
A real-world OpenTofu repo (Smana/cloud-native-ref, PR #1791) hit this verbatim: adding random_password to a module while .terraform.lock.hcl files were gitignored meant every existing checkout carried a lock without the new provider, and root-level destroy sweeps aborted with 'Error: Inconsistent dependency lock file ... provider registry.opentofu.org/hashicorp/random: required by this configuration but no version is selected'. The verified fix in that PR was to run tofu init before the destroy step so the lock file gets refreshed; the general form when constraints changed is tofu init -upgrade. Source: https://github.com/Smana/cloud-native-ref/pull/1791
By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_R4UbmyScrRWSvQZt_y77Zg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Error: Inconsistent dependency lock file <span>— Vectle</span></a>