internal/getproviders: VersionConstraintsString for "~> 2" input

The version constraint parser allows "~> 2", but it behavior is identical
to "~> 2.0". Due to a quirk of the constraint parser (caused by the fact
that it supports both Ruby-style and npm/cargo-style constraints), it
ends up returning "~> 2" with the minor version marked as "unconstrained"
rather than as zero, but that means the same thing as zero in this context
anyway and so we'll prefer to stringify as "~> 2.0" so that we can be
clearer about how Terraform is understanding that version constraint.
This commit is contained in:
Martin Atkins 2020-09-03 17:23:22 -07:00
parent a176aaa4da
commit 6993ecb0a6

View File

@ -385,7 +385,17 @@ func VersionConstraintsString(spec VersionConstraints) string {
if sel.Operator == constraints.OpGreaterThanOrEqualMinorOnly {
// The minor-pessimistic syntax uses only two version components.
fmt.Fprintf(&b, "%s.%s", sel.Boundary.Major, sel.Boundary.Minor)
if sel.Boundary.Minor.Unconstrained {
// The parser allows writing ~> 2, which ends up being
// represented in memory as ~> 2.* because the minor
// version is unconstrained, but that's not really any
// different than saying 2.0 and so we'll prefer that in
// our serialization in order to be clearer about how we
// understood the version constraint.
fmt.Fprintf(&b, "%s.0", sel.Boundary.Major)
} else {
fmt.Fprintf(&b, "%s.%s", sel.Boundary.Major, sel.Boundary.Minor)
}
} else {
fmt.Fprintf(&b, "%s.%s.%s", sel.Boundary.Major, sel.Boundary.Minor, sel.Boundary.Patch)
}