tofuutils / tenv

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

No compatible version found when loading required_version from .tf file #163

Closed ThibaultNocchi closed 3 months ago

ThibaultNocchi commented 3 months ago

Describe the bug Since tenv v2, I can't fetch the TF CLI when detecting the required_version from a .tf file. I get the Error: no compatible version found error.

It worked in v1 and I can use tenv tf install 1.7.0 without problem in v2.

To Reproduce Steps to reproduce the behavior:

  1. Write a basic providers.tf
# Configure the Terraform backend for remote state
terraform {
  required_version = "~> 1.7.0"
}
  1. Run tenv tf detect -v
  2. Fails

Expected behavior It should download the correct version like when using tenv tf install.

Environment (please complete the following information):

Additional context

root@818c4335f354:/# cat providers.tf
# Configure the Terraform backend for remote state
terraform {
  required_version = "~> 1.7.0"
}

root@818c4335f354:/# tenv --version
tenv version v2.0.3

root@818c4335f354:/# tenv tf detect -v
2024-06-11T12:53:52.586Z [DEBUG] tenv: Failed to read file: error="open .terraform-version: no such file or directory"
2024-06-11T12:53:52.586Z [DEBUG] tenv: Failed to read file: error="open .tfswitchrc: no such file or directory"
2024-06-11T12:53:52.586Z [DEBUG] tenv: Failed to read terragrunt file: error="open terragrunt.hcl: no such file or directory"
2024-06-11T12:53:52.586Z [DEBUG] tenv: Failed to read terragrunt file: error="open terragrunt.hcl.json: no such file or directory"
2024-06-11T12:53:52.586Z [DEBUG] tenv: Failed to read file: error="open /root/.terraform-version: no such file or directory"
2024-06-11T12:53:52.586Z [DEBUG] tenv: Failed to read file: error="open /root/.tfswitchrc: no such file or directory"
2024-06-11T12:53:52.586Z [DEBUG] tenv: Failed to read terragrunt file: error="open /root/terragrunt.hcl: no such file or directory"
2024-06-11T12:53:52.586Z [DEBUG] tenv: Failed to read terragrunt file: error="open /root/terragrunt.hcl.json: no such file or directory"
2024-06-11T12:53:52.586Z [DEBUG] tenv: Failed to read file: error="open /root/.tenv/Terraform/version: no such file or directory"
No version files found for Terraform, fallback to latest-allowed strategy
Scan project to find .tf files
2024-06-11T12:53:52.586Z [DEBUG] tenv: Read: filePaths=["providers.tf"]
2024-06-11T12:53:52.587Z [DEBUG] tenv: Failed to read file: error="open /root/.tenv/Terraform/constraint: no such file or directory"
2024-06-11T12:53:52.587Z [DEBUG] tenv: Find: constraints=["~> 1.7.0"]
Error: no compatible version found
Usage:
  tenv tf detect [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 detect
  -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

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 "/root/.tenv")
  -v, --verbose            verbose output (and set log level to Trace)

no compatible version found
kvendingoldo commented 3 months ago

can you try to do the following, please?

export TENV_AUTO_INSTALL=true
tenv tf detect -v

By default, we disabled autoinstall in V2 via detect command. I think that we can add flag to the command to install tools automatically, like tenv tf detect --install

ThibaultNocchi commented 3 months ago

Indeed it works way better, thank you! I missed it in the 2.0 changes! Maybe the error message reworded, but thank you! Have a nice day!

kvendingoldo commented 3 months ago

@ThibaultNocchi one more question for you as for user. Do you think that it's more or less expected behavior? We have debated about it some time ago (https://github.com/orgs/tofuutils/discussions/4) and still gathering user opinions.