tfswitch doesn't interpret the pessimistic constraint operator the same way that Terraform interprets it
Closed this issue ยท 7 comments
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 of1.0.5
and1.0.10
but not1.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.
This appears fixed in the top of trunk. Unfortunately, no release yet with this fix.
See also #208
@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
yes... ~> x.y
should install the latest released major version of x
that has a minor version greater than or equal to y
.
Exactly. And a constraint of ~> 1.0.0
should download v1.0.11 (November 10, 2021).
@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.