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 treats version constraint differently than terraform #207

Closed
atheri opened this issue Jan 18, 2022 · 4 comments · Fixed by #208
Closed

tfswitch treats version constraint differently than terraform #207

atheri opened this issue Jan 18, 2022 · 4 comments · Fixed by #208
Assignees
Labels
bug Something isn't working

Comments

@atheri
Copy link

atheri commented Jan 18, 2022

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.

@warrensbox warrensbox self-assigned this Jan 24, 2022
@warrensbox warrensbox added the bug Something isn't working label Jan 24, 2022
@warrensbox warrensbox linked a pull request Jan 24, 2022 that will close this issue
@warrensbox
Copy link
Owner

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

@yermulnik
Copy link
Collaborator

yermulnik commented Jan 24, 2022

@warrensbox Last code example should probably have been written as required_version = "~> 1"?

@warrensbox
Copy link
Owner

@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"
}

@atheri
Copy link
Author

atheri commented Jan 24, 2022

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants