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

tfswitch doesn't interpret the pessimistic constraint operator the same way that Terraform interprets it #215

Closed
rux616 opened this issue Feb 28, 2022 · 7 comments

Comments

@rux616
Copy link

rux616 commented Feb 28, 2022

Consider the following Terraform code:

terraform {
  required_version = "~> 1.0"
}

When evaluated by the Terraform binary, it is interpreted as "allow 1.x.*, where x is at least 0". Unfortunately, when evaluated by tfswitch, it is interpreted as "allow 1.0.x where x is at least 0", which is incorrect. According to the Terraform docs:

~>: Allows only the rightmost version component to increment. For example, to allow new patch releases within a specific minor release, use the full version number: ~> 1.0.4 will allow installation of 1.0.5 and 1.0.10 but not 1.1.0. This is usually called the pessimistic constraint operator.

The rightmost version component in the above ~> 1.0 constraint, to use SemVer terminology of major.minor.patch, is the minor version of 0, not the patch version of 0.

As it stands right now, to get version 1.x via tfswitch you need to use the version constraint of ~> 1, which the Terraform binary will interpret as allowing any major version greater than or equal to 1, e.g. 2.0, 3.14.5, etc.

tfswitch should be using the same definition of the pessimistic constraint operator that the Terraform binary does.

@rux616 rux616 changed the title tfswitch doesn't treat pessimistic version constraint the same way that Terraform treats it tfswitch doesn't interpret the pessimistic constraint operator the same way that Terraform interprets it Mar 3, 2022
@llamahunter
Copy link

This appears fixed in the top of trunk. Unfortunately, no release yet with this fix.

@llamahunter
Copy link

See also #208

@warrensbox
Copy link
Owner

warrensbox commented Mar 8, 2022

@rux616
@llamahunter I wanted to verify before releasing:

terraform {
  required_version = "~> 1.0"
}

should install "1.1.7", right (Mar 8, 2022) ?

Reading required version from terraform file
Reading required version from constraint: ~> 1.0
Matched version: 1.1.7
Downloading to: /Users/warrenveerasingam/.terraform.versions
20213394 bytes downloaded

@llamahunter
Copy link

llamahunter commented Mar 8, 2022

yes... ~> x.y should install the latest released major version of x that has a minor version greater than or equal to y.

@rux616
Copy link
Author

rux616 commented Mar 8, 2022

Exactly. And a constraint of ~> 1.0.0 should download v1.0.11 (November 10, 2021).

@warrensbox
Copy link
Owner

@rux616
ok I got that too:

Reading required version from terraform file
Reading required version from constraint: ~> 1.0.0
Matched version: 1.0.11
Switched terraform to version "1.0.11"

I will release it shortly.

@rux616
Copy link
Author

rux616 commented Mar 8, 2022

Fixed in release 0.13.1218.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants