tofuutils / tenv

OpenTofu / Terraform / Terragrunt and Atmos version manager
https://tofuutils.github.io/tenv/
Apache License 2.0
662 stars 32 forks source link

tenv install wrong terraform version #161

Closed kvendingoldo closed 3 months ago

kvendingoldo commented 3 months ago

Describe the bug the command tenv tf install latest:^1.1 install v.1.10 instead of 1.1

Additional context Found the bug here https://github.com/tfutils/tfenv/issues/432

dvaumoron commented 3 months ago

That could seem surprising, however the regexp match. There is several way to get the last 1.1 patch : use a more selective regexp (tenv tf install latest:^1\.1\.) or use version constraint (tenv tf install "~> 1.1")

kvendingoldo commented 3 months ago

Agree, probably we have to add info about such cases to readme. Will do that

MageshSrinivasulu commented 3 months ago

@kvendingoldo Does it mean we should use something like this latest:^1.1. ( an additional dot ) instead of latest:^1.1 ?

kvendingoldo commented 3 months ago

@dvaumoron tried tenv tf install latest:^1\.1\., but this regex works a little bit strange:

Use of regexp is discouraged, try version constraint instead
Fetching all releases information from https://releases.hashicorp.com/terraform/index.json
Found compatible version remotely : 1.10.0-alpha20240606
Terraform 1.10.0-alpha20240606 already installed
kvendingoldo commented 3 months ago

Additional strange behavior: ➜ ~ tenv tf install "~> 1.1"

Fetching all releases information from https://releases.hashicorp.com/terraform/index.json
Found compatible version remotely : 1.8.5
Installing Terraform 1.8.5
Fetching release information from https://releases.hashicorp.com/terraform/1.8.5/index.json
Downloading https://releases.hashicorp.com/terraform/1.8.5/terraform_1.8.5_darwin_amd64.zip
Downloading https://releases.hashicorp.com/terraform/1.8.5/terraform_1.8.5_SHA256SUMS
Downloading https://releases.hashicorp.com/terraform/1.8.5/terraform_1.8.5_SHA256SUMS.sig
Downloading https://www.hashicorp.com/.well-known/pgp-key.txt
kvendingoldo commented 3 months ago

Sorry, it's not strange, tenv tf install "~> 1.1.0" works fine, but regex does not work.

kvendingoldo commented 3 months ago

ok, regex tenv tf install latest:^1\.1\..- works, but it install 1.1.0, not 1.1.9. @MageshSrinivasulu @flav1972 you can install the required version via the tenv: tenv tf install latest:^1\.1\..- or tenv tf install latest:^1.1.9

flav1972 commented 3 months ago

tfenv (not tested with tenv) works fine with latest:^1\.1\.

$ cat .terraform-version 
latest:^1\.1\.
$ tfenv install
Installing Terraform v1.1.9
kvendingoldo commented 3 months ago

hmm, for golang we have to find another regex, because latest:^1\.1\. does not work

dvaumoron commented 3 months ago

Sorry, it's not strange, tenv tf install "~> 1.1.0" works fine, but regex does not work.

That's my fault, my example was erroneous, with ~> the last part can be maxed.

hmm, for golang we have to find another regex, because latest:^1.1. does not work

That's weird, i will take a look on that (probably this week end)

dvaumoron commented 3 months ago

hmm, for golang we have to find another regex, because latest:^1\.1\. does not work

What have you tried ? It seem to work well (tested on Windows).

$ tenv tf install latest:^1\.1\.
Use of regexp is discouraged, try version constraint instead
Fetching all releases information from https://releases.hashicorp.com/terraform/index.json
Found compatible version remotely : 1.1.9
Installing Terraform 1.1.9
Fetching release information from https://releases.hashicorp.com/terraform/1.1.9/index.json
Downloading https://releases.hashicorp.com/terraform/1.1.9/terraform_1.1.9_windows_amd64.zip
Downloading https://releases.hashicorp.com/terraform/1.1.9/terraform_1.1.9_SHA256SUMS
Downloading https://releases.hashicorp.com/terraform/1.1.9/terraform_1.1.9_SHA256SUMS.sig
Downloading https://www.hashicorp.com/.well-known/pgp-key.txt
Installation of Terraform 1.1.9 successful
dvaumoron commented 3 months ago

@kvendingoldo Does it mean we should use something like this latest:^1.1. ( an additional dot ) instead of latest:^1.1 ?

a dot in a regexp capture every character, to capture only the dot character you need to escape it in the regexp with a backslash

dvaumoron commented 3 months ago

What have you tried ? It seem to work well (tested on Windows).

tested again on linux with bash...

you need to use quote to avoid interpretration from bash which lead to the strange behavior (i.e. use tenv tf install "latest:^1\.1\.")

dvaumoron commented 3 months ago

single quote work too tenv tf install 'latest:^1\.1\.'