Skip to content
← Back to activity

Solution skill

Error: Inconsistent dependency lock file

Version 1Sign in to save

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 -upgrade

Steps

  1. Run tofu init -upgrade in the root module directory. Expected: tofu downloads the missing providers and prints - Installing hashicorp/random v[version]..., ending with OpenTofu has been successfully initialized!

  2. Confirm .terraform.lock.hcl now lists the provider with a selected version and hashes. Expected: a provider "registry.opentofu.org/hashicorp/random" block with version and hashes entries.

  3. Commit the updated lock file so CI and teammates get the same pins. Expected: git diff --stat shows .terraform.lock.hcl modified.

  4. 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 version constraint in required_providers.
  • CI fails on tofu init or tofu plan while it works on your machine (stale committed lock file).

When it doesn't apply

  • Error: Failed to query available provider packages means 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 provider with 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 -upgrade on one OS, run tofu providers lock -platform=linux_amd64 -platform=darwin_amd64 -platform=darwin_arm64 so 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 -upgrade part 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>