tfswitch treats version constraint differently than terraform
Closed this issue · 4 comments
If I use the pessimistic constraint like so
terraform {
required_version = "~> 1.0"
}
terraform will allow me to use terraform version 1.1, but tfswitch will only switch to 1.0.x
╰─ tfswitch
Reading required version from terraform file
Reading required version from constraint: ~> 1.0
Matched version: 1.0.11
Switched terraform to version "1.0.11"
terraform allowing 1.x version seems consistent with how they documented it here. I would expect tfswitch to follow the same pattern.
terraform {
required_version = "~> 1.0"
}
Should get the latest stable version of 1.0.0 which is 1.0.11
If you want the latest of V1 terraform:
Simply use:
terraform {
required_version = "~> 1.0"
}
**Should get the latest stable version of 1 ** which is 1.1.4.
I will fix the documentation to reflect this
@warrensbox Last code example should probably have been written as required_version = "~> 1"
?
@warrensbox Last code example should probably have been written as
required_version = "~> 1"
?
Correct, I had a typo. It should be:
terraform {
required_version = "~> 1"
}
@warrensbox Just for clarity, I don't think it works quite like the comment.
Testing your fix out locally I get the following results (which is in line with what I expected, but not quite the same as your comment)
terraform {
required_version = "~> 1.0.0"
}
╰─ ~/go/bin/terraform-switcher
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"
^ Get latest stable of 1.0.x
terraform {
required_version = "~> 1.0"
}
╰─ ~/go/bin/terraform-switcher
Reading required version from terraform file
Reading required version from constraint: ~> 1.0
Matched version: 1.1.4
Switched terraform to version "1.1.4"
^ Get latest stable of 1.x.x
. This is new, it used to get 1.0.x
per the original issue.
terraform {
required_version = "~> 1"
}
╰─ ~/go/bin/terraform-switcher
Reading required version from terraform file
Reading required version from constraint: ~> 1
Matched version: 1.1.4
Switched terraform to version "1.1.4"
^ Get latest stable of x.x.x
. Coincidentally the same as the last one, but if a 2.0.0 release existed it should return that.