The lock file records which provider version was installed last. If someone changes the version constraint so that it no longer fits, even init fails. The advice in the message – init -upgrade – only helps if a matching version exists at all.
Symptom
tofu init -no-color 2>&1 | grep -E '^Error|constraint' Error: Failed to resolve provider packages version constraint ~> 4.6, ~> 5.0; must use tofu init -upgrade to allow
“I bumped the Docker provider to version 5, it is supposed to be faster. Now not even init works.”
Diagnosis
Try the advice from the message – it shows whether the version exists.
tofu init -upgrade -no-color 2>&1 | grep -E '^Error|no available' Error: Failed to resolve provider packages Could not resolve provider kreuzwerker/docker: no available releases match
Causes
~> 4.6, ~> 5.0Lock file and constraint contradict each other
The lock file says 4.6, versions.tf requires 5.0. Without -upgrade OpenTofu sticks to the locked version and stops.
no available releasesThe required version does not exist
There is no version 5 of kreuzwerker/docker. Even init -upgrade finds nothing then.
Fix
git checkout versions.tf tofu init -no-color >/dev/null && tofu plan -no-color | tail -1 Updated 1 path from the index No changes. Your infrastructure matches the configuration.
Don't: Delete the lock file so init passes – OpenTofu then installs the newest matching version unchecked, and the checksums are gone.
OpenTofu hands-on, Day 15: fix eight faults in state, providers, modules and encryption against the clock.
Go to day 15 →
FAQ
How do I update a provider properly?
In its own PR with init -upgrade, a new .terraform.lock.hcl and a plan. Renovate proposes such updates automatically – only for versions that exist.
What does ~> 4.6 mean?
Any version from 4.6 up to, but not including, 5.0.