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 tf use` uninformative error if no terraform version installed #172

Closed Nmishin closed 3 months ago

Nmishin commented 3 months ago

Describe the bug If I run tenv tf use 1.2.0 I expect that terraform version will be switched to the needed version, or i will have an error like "version should be installed"

To Reproduce For now I have no error, or additional log message

$ tenv tf use 1.2.0
Written 1.2.0 in /Users/nmishin/.tenv/Terraform/version
$ terraform version
Failure during terraform call : fork/exec /Users/nmishin/.tenv/Terraform/1.2.0/terraform: no such file or directory

Expected behavior I want to have some error log

Environment (please complete the following information): $ tenv --version tenv version 2.0.7

dvaumoron commented 3 months ago

Will be fixed by #165

Nmishin commented 3 months ago

fixed by https://github.com/tofuutils/tenv/pull/165

kvendingoldo commented 3 months ago

Still an issue:

➜  ~ tenv tf list
  1.1.0-rc1
  1.1.9
  1.5.7
  1.7.4
  1.8.0
  1.8.1
  1.8.2
  1.8.3
  1.8.4
  1.8.5
  1.10.0-alpha20240606
➜  ~ tenv tf use 1.6.0
Written 1.6.0 in /Users/asharov/.tenv/Terraform/version
➜  ~ terraform version
Failure during terraform call : fork/exec /Users/asharov/.tenv/Terraform/1.6.0/terraform: no such file or directory
dvaumoron commented 3 months ago

Seem to work as expected

$ tenv tf use latest
No compatible version found locally, search a remote one...
Fetching all releases information from https://releases.hashicorp.com/terraform/index.json
Found compatible version remotely : 1.8.5
Auto-install is disabled. To install 1.8.5 version you can set environment variable TENV_AUTO_INSTALL=true, or install it via any of the following command: 'tenv terraform install', 'tenv terraform install 1.8.5'
Error: no compatible version found locally
Usage:
  tenv tf use version [flags]

Flags:
  -a, --arch string          specify arch for binaries downloading (default "amd64")
  -f, --force-remote         force search on versions available at TFENV_REMOTE url
  -h, --help                 help for use
  -k, --key-file string      local path to PGP public key file (replace check against remote one)
  -n, --no-install           disable installation of missing version (default true)
  -c, --remote-conf string   path to remote configuration file (advanced settings)
  -u, --remote-url string    remote url to install from
  -w, --working-dir          create .terraform-version file in working directory

Global Flags:
  -q, --quiet              no unnecessary output (and no log)
  -r, --root-path string   local path to install versions of OpenTofu, Terraform, Terragrunt, and Atmos (default "C:\\Users\\Denis\\.tenv")      
  -v, --verbose            verbose output (and set log level to Trace)

no compatible version found locally
Nmishin commented 3 months ago

$ tenv tf use latest works good if no versions present locally. $ tenv tf use latest will use the last one version presented locally, I'm not sure that this is expected behaviour, but this is different question.

Could you please try to reproduce the issue like this:

$ tenv tf list
* 1.2.0 (set by /Users/nmishin/.tenv/Terraform/version)
  1.3.0
  1.5.7
  1.6.0
  1.6.1
  1.8.0
$ tenv tf use 1.3.7
Written 1.3.7 in /Users/nmishin/.tenv/Terraform/version
$ terraform version
Failure during terraform call : fork/exec /Users/nmishin/.tenv/Terraform/1.3.7/terraform: no such file or directory
$ tenv --version
tenv version 2.1.6
dvaumoron commented 3 months ago

Got it, you use a specific version, so tenv did not search what it mean in either case, and the message did not help, we should improve that...

dvaumoron commented 3 months ago

$ tenv tf use latest will use the last one version presented locally, I'm not sure that this is expected behaviour, but this is different question.

In my opinion, we don't need to manage that, because Terraform and OpenTofu already warn there user when a new version is available