Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal: Fix lockfile constraint output for 1.2.* #26637

Merged
merged 1 commit into from
Oct 21, 2020

Conversation

alisdair
Copy link
Contributor

@alisdair alisdair commented Oct 19, 2020

If a configuration requires a partial provider version (with some parts unspecified), Terraform considers this as a constrained-to-zero version. For example, a version constraint of 1.2 will result in an attempt to install version 1.2.0, even if 1.2.1 is available.

When writing the dependency locks file, we previously would write 1.2.*, as this is the in-memory representation of 1.2. This would then cause an error on re-reading the locks file, as this is not a valid constraint format.

Instead, we now explicitly convert the constraint to its zero-filled representation before writing the locks file. This ensures that it correctly round-trips.

Because this change is made in getproviders.VersionConstraintsString, it also affects the output of the providers sub-command.

Fixes #26631.

@alisdair alisdair added this to the v0.14.0 milestone Oct 19, 2020
@alisdair alisdair requested review from apparentlymart and a team October 19, 2020 20:55
@alisdair alisdair self-assigned this Oct 19, 2020
@codecov
Copy link

codecov bot commented Oct 19, 2020

Codecov Report

Merging #26637 into master will increase coverage by 0.01%.
The diff coverage is 0.00%.

Impacted Files Coverage Δ
internal/getproviders/types.go 37.00% <0.00%> (+0.72%) ⬆️
command/meta.go 68.59% <0.00%> (-0.97%) ⬇️
dag/walk.go 91.60% <0.00%> (-0.70%) ⬇️
terraform/evaluate.go 52.50% <0.00%> (-0.42%) ⬇️
terraform/eval_apply.go 74.62% <0.00%> (+0.60%) ⬆️
terraform/node_resource_plan.go 97.19% <0.00%> (+1.86%) ⬆️
command/meta_providers.go 33.10% <0.00%> (+2.06%) ⬆️
internal/providercache/dir.go 71.42% <0.00%> (+6.12%) ⬆️

Copy link
Contributor

@mildwonkey mildwonkey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me!

The reporter asked a good question in the attached issue (not a question that would hold up this PR): should terraform require full major.minor.patch version constraints when specifying an exact match w/ =?

I'm ok with not requiring that as long as it's clearly documented that = 2.0 is equivalent to = 2.0.0, especially if = 2.0.0 is what terraform displays in the UI, but it's worth thinking about.

@@ -422,27 +422,24 @@ func VersionConstraintsString(spec VersionConstraints) string {
b.WriteString("??? ")
}

// The parser allows writing abbreviated versions (such as ~> 2) which
// end up being represented in memory with trailing unconstrained parts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(dang it gh this is the 4th time I've written this comment PLEASE STICK THIS TIME)

I know this isn't a new comment, but I have a nitpicky request while you're in the area: reading this briefly (before my brain kicked in) lead me to expect that a constraint written as ~> 2.0 would be recorded as 2.0.0 (exact). It's silly, but can you clarify that comment? I don't know if my suggestion (below) is the right idea but something like it would have saved me a lot of time this morning 🙃

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think your suggestion below is correct, but in rereading the comment I also spent 10 minutes confused, so I think it's probably structurally unclear. I'll take another shot at it. Thanks for pointing this out!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's another attempt. Is this any clearer to you?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YES thank you!! That's fantastic!

If a configuration requires a partial provider version (with some parts
unspecified), Terraform considers this as a constrained-to-zero version.
For example, a version constraint of 1.2 will result in an attempt to
install version 1.2.0, even if 1.2.1 is available.

When writing the dependency locks file, we previously would write 1.2.*,
as this is the in-memory representation of 1.2. This would then cause an
error on re-reading the locks file, as this is not a valid constraint
format.

Instead, we now explicitly convert the constraint to its zero-filled
representation before writing the locks file. This ensures that it
correctly round-trips.

Because this change is made in getproviders.VersionConstraintsString, it
also affects the output of the providers sub-command.
@alisdair alisdair force-pushed the alisdair/fix-locksfile-unconstrained-versions branch from 391987b to 9576a5b Compare October 20, 2020 14:14
@alisdair alisdair merged commit 7a31e56 into master Oct 21, 2020
@alisdair alisdair deleted the alisdair/fix-locksfile-unconstrained-versions branch October 21, 2020 16:05
@ghost
Copy link

ghost commented Nov 21, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked as resolved and limited conversation to collaborators Nov 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error: Invalid provider version constraints
2 participants