fix(terraform): normalize lock file constraint order after provider update#44530
Open
lindeskar wants to merge 1 commit into
Open
fix(terraform): normalize lock file constraint order after provider update#44530lindeskar wants to merge 1 commit into
lindeskar wants to merge 1 commit into
Conversation
…pdate Terraform and OpenTofu reject a .terraform.lock.hcl whose constraints are not in normalized form. When a provider version is updated in place, a bumped exact pin can overtake an inherited `~>` range, leaving e.g. "5.9.0, ~> 5.0" which fails "init" with "must be written in normalized form". Re-sort the sub-constraints (boundary version ascending, ties broken by operator priority) to match Terraform's canonical serialization. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
bc807fc to
abcb77c
Compare
Author
|
Hi maintainers, Sorry I had to force-push once to change the commit message. Let me know if there's anything missing to get this change through! /Alex |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
Terraform and OpenTofu require the
constraintsfield in.terraform.lock.hclto be written in normalized form. When Renovate updates a provider version,getNewConstraintreplaces the version in place but does not re-sort the sub-constraints.When a provider's constraint combines an exact pin (from
required_providers) with a~>range inherited from a module, bumping the pin can push it past the range boundary — e.g.5.0.0, ~> 5.0becomes5.9.0, ~> 5.0. That is no longer normalized, soterraform/tofu initfails:This adds
sortConstraints, which reorders the sub-constraints into Terraform's canonical order — boundary version ascending, ties broken by operator priority — mirroringgetproviders.VersionConstraintsStringin Terraform. It only reorders existing tokens (it never rewrites operators or version precision) and returns the string untouched if any token cannot be parsed, so it cannot corrupt a valid constraint. It is applied at the two in-place replacement branches ofgetNewConstraint.Context
Please select one of the following:
AI assistance disclosure
Did you use AI tools to create any part of this pull request?
This PR was written primarily by Claude Code (model: Claude Opus 4.8) — the code, tests, and this description. The approach was directed and reviewed by me, including cross-checking the sort order against Terraform's
getproviders.VersionConstraintsString.Documentation (please check one with an [x])
How I've tested my work (please select one)
I have verified these changes via:
The public repository: N/A (unit tests only; not yet run against a live repository)