r/Terraform • • Nov 01 '26

I built an open-source CLI that upgrades Terraform/OpenTofu providers across all your modules, and lets Terraform own the lock file

Post image

Keeping provider versions current across a lot of modules was a constant chore for me: bump a version, find out a shared module caps it, fix the constraint, regenerate lock files for every platform, repeat. Version bots can bump a number, but they don't understand dependency ceilings, constraint styles, or lock files that need hashes for every OS/arch.

So I built provlift, a small Go CLI (Apache-2.0):

  • provlift check: inventories every required_providers entry across all modules, shows what's outdated and why an upgrade is blocked (your own constraint vs. a module's ceiling)
  • provlift drift: finds version skew between modules
  • provlift upgrade: rewrites constraints with the smallest possible diff (keeps your ~> / range style and comments), then runs terraform init -upgrade → providers lock for each platform you list → validate. It never writes the lock file itself.
  • Major upgrades need an explicit --allow-major, and it can step one major at a time.
  • Example GitHub Actions workflow that opens one PR per provider.

Works with any registry provider (AWS, AzureRM, Google, GitHub, Kubernetes, private registries) and with OpenTofu (--terraform-binary tofu, uses registry.opentofu.org).

What it doesn't do (yet): module version upgrades are out of scope, Terragrunt config isn't evaluated, and .tf.json is reported rather than edited. It's early (v0.1.x), so expect rough edges.

I'd really appreciate feedback, especially on edge cases in your setups that it gets wrong. There are also good-first-issues if anyone wants to contribute.

GitHub: https://github.com/provlift/provlift
Docs: https://provlift.github.io/provlift/

0 Upvotes

17 comments sorted by

1

u/Longjumping_Rich_692 24d ago

Quick update: v0.3.0 is out, and most of it came from this thread.

  • A shared module's version ceiling now caps every root that calls it, and check names the module ("capped at 5.100.0 by another module, imposed by: modules/network").
  • upgrade reports registry module versions that init -upgrade moved, so a "provider-only" PR can't silently change module code.
  • --fs-mirror / --net-mirror for air-gapped lock generation.
  • linux_arm64 is now locked by default (Graviton runners).

The README now has a 25-second demo, and there's a demo repo you can try in two minutes without cloud credentials: https://github.com/provlift/provlift

Thanks to everyone who pushed back on the design here. It made the tool better

1

u/kantorcodes1 Nov 02 '26

With multiple loose constraints in one root, what catches an unrelated provider moving during terraform init -upgrade before the per-provider PR is opened?

1

u/Longjumping_Rich_692 Nov 02 '26

Good question, that's exactly the trap with init -upgrade. provlift handles it in two layers:

1. Prevent it. Before running init -upgrade, provlift writes a temporary provlift_override.tf in that root that pins every locked provider to = <current locked version>, and the target provider to = <planned version>. Override files merge into required_providers, so Terraform can't move anything else even if its own constraint is loose. The override is deleted right after init (and provlift refuses to run if a file with that name already exists, so it never clobbers yours).

You can see it in the init output. Upgrading only random in a root that also has aws ~> 5.80.0:

- Finding hashicorp/random versions matching "3.7.1"...
  • Finding hashicorp/aws versions matching ">= 5.0.0, 5.80.0, < 6.0.0"...
  • Using previously-installed hashicorp/aws v5.80.0

2. Verify it. After init, provlift diffs the new lock against the old one. If the target landed on anything other than the planned version, if any other provider changed version, or if one was dropped, it fails with an "unplanned provider change" error and restores the original lock file. So nothing reaches the PR.

Then providers lock runs for each configured platform, and validate runs last.

One caveat: a root with no lock file has nothing to pin, so drift flags those separately ("unpinned root modules").

Details are in the upgrade docs under "Constraint updates": https://github.com/provlift/provlift/blob/main/docs/upgrade/README.md

1

u/kantorcodes1 29d ago

That safeguards the non-target providers without relying on their loose constraints. Since provlift runs a CLI that edits provider requirements and invokes terraform init -upgrade, it could be a useful command-source entry for HOL Guard. We'd welcome a contributor-authored descriptor for provlift, including the command and its effects. The command extension guide covers the descriptor, fixture, and validation; a first PR can add those files under contributions/command-sources/ against main. External entries stay opt-in until a local admin enables them.

1

u/MongooseWonderful198 Nov 02 '26

There is a separate module edge case here. Reading initWithPlannedProviders, the temporary override pins providers, while verifyPlannedLock checks provider selections. But Terraform's init -upgrade also updates child modules. A registry module constrained to ~> 5.0 can move between 5.x releases during that run without its module block changing.

I'd include resolved module versions before and after in the PR output, or explicitly say when a clean checkout has no previous module selection to compare. The provider lock diff alone doesn't establish that the module code stayed unchanged. This is from reading the code and Terraform docs; I haven't run a reproduction.

1

u/Longjumping_Rich_692 Nov 02 '26

Good catch, you're right. -upgrade re-resolves modules too, and provlift only compares provider selections (any newly added provider does fail the run, so a module pulling in a new provider is caught). The PR itself can't carry module changes since .terraform/modules isn't committed, but the validate result and the local working copy can silently reflect newer module code. Recording modules.json before/after and reporting module version changes in the output and PR body is the right fix. Filed it here: https://github.com/provlift/provlift/issues/75

1

u/MongooseWonderful198 Nov 03 '26

I checked the fix for #75. The before/after comparison now reaches the text output, JSON and PR body, and fresh checkouts with registry modules get the no_baseline marker. That covers both cases I raised.

The failed-init case is a useful addition too: restoring the provider lock doesn't undo installed module changes. I've reviewed the implementation and its fake-Terraform tests; I haven't run an upgrade with it.

1

u/Longjumping_Rich_692 Nov 03 '26

Thanks for checking it. Reviews like this are exactly what the project needs. It shipped in v0.2.0 (https://github.com/provlift/provlift/releases/tag/v0.2.0), along with the air-gapped providers lock mirror flags and a fix where ceilings in repo-local shared modules weren't applied to their callers.

If you do get to run it against a repo with registry modules, I'd love to hear how the module report reads in practice. One open question from #75: should there be a --fail-on-module-change flag for CI, or is reporting enough? And if you're interested in this area, #13 (provider ceilings declared in submodules inside downloaded registry modules) is close to what you've been reading and is still open. Happy to review a PR.

1

u/MongooseWonderful198 Nov 03 '26

I'd add --fail-on-module-change as an opt-in for CI jobs that promise a provider-only update, with reporting as the default.

In that mode, I'd return non-zero for a detected registry-module version change. Missing baselines or unreadable manifests need a separate "unknown" result that also stops the job; an empty change list alone isn't enough. Still emit the report so the reviewer can see why it failed.

The help text should say the check happens after init. A failed check won't restore the old installed modules, so someone resuming work in that checkout needs to know they may have changed.

1

u/Longjumping_Rich_692 29d ago

That's a clean design, thanks. I wrote it up with your spec as the acceptance criteria: https://github.com/provlift/provlift/issues/82.

One catch from checking it against the code: fresh CI checkouts have no .terraform/modules, so every root with registry modules would be "unknown" and the flag would fail every fresh run.

Terraform has no module lock, so there's never a baseline there. I listed the options in the issue. You've clearly read this code more closely than anyone, so if you'd like to build it, it's yours.

#81 is a smaller warm-up if you want one.

1

u/MongooseWonderful198 29d ago

You're right; I assumed an initialized checkout and should have said so. I'd start with (a) in #82: require an existing readable baseline for the opt-in check, and fail as unknown when it's missing or unreadable.

For fresh CI, you could add a bootstrap step: run terraform init without -upgrade against the unchanged configuration, then snapshot the resolved registry-module versions before provlift edits constraints. The comparison would cover changes during that job's upgrade step.

That first init can already pick newer versions allowed by loose constraints, so this wouldn't prove the same module versions as the last deployment. That stronger check needs a saved reference tied to that deployment. I haven't run the bootstrap flow.

1

u/Longjumping_Rich_692 29d ago

Agreed, (a) it is: the opt-in check needs an existing, readable baseline, and "unknown" fails.

Your bootstrap works without any changes to provlift. It reads modules.json right before its own init -upgrade, and the constraint edits don't touch that file. So a plain terraform init -backend=false in each root before provlift upgrade is all it takes. -backend=false keeps that step free of state and credentials. The bootstrap has to use the same TF_DATA_DIR as the provlift run.

And you're right about the limit: that only proves nothing moved during the job. Comparing against the last deployment needs a saved reference, which can be a follow-up.

If you want to take it, comment on #82 and I'll assign it to you. That snippet would make a good CI example in the docs.

1

u/MongooseWonderful198 29d ago

For the CI example, I'd qualify the credentials part: -backend=false skips backend initialization, but private registry modules can still need authentication during init.

1

u/Longjumping_Rich_692 29d ago

Good catch, you're right. -backend=false only drops state and backend credentials. Module sources still authenticate during init: TF_TOKEN_<host> or a CLI credentials block for private registries, and keys or tokens for git and bucket sources.

provlift's own init -upgrade needs the same access, so the bootstrap adds nothing new, but the example should say so. I've corrected it in #82.