tfutils / tfenv

Terraform version manager
MIT License
4.52k stars 454 forks source link

min-required and fallback #353

Open JeanFred opened 2 years ago

JeanFred commented 2 years ago

I have now tried the min-required feature that recently shipped with #335 (after testing the one in #305).

It does not seem to work for the use case I described at https://github.com/tfutils/tfenv/pull/305#issuecomment-979135096= and my mixed-version code base.

305 ended up implementing a graceful fallback on the next detection method. Would something similar be possible here?

(As said in that comment, perhaps my use-case is somewhat specific ; and I can see how automatic fallbacks can be confusing).

[1] Logs

[DEBUG] DEBUG trap set
[DEBUG] Helpers sourced successfully
[DEBUG] $PATH does not contain '/tfenv/libexec', prepending and exporting it now
[DEBUG] $PATH already contains '/tfenv/bin', not adding it again
[DEBUG] program="terraform"
[DEBUG] Getting version from tfenv-version-name
[DEBUG] TFENV_VERSION specified in TFENV_TERRAFORM_VERSION environment variable: min-required
[DEBUG] TFENV_VERSION uses min-required keyword, looking for a required_version in the code
[DEBUG] Appropriate required_version not found, skipping min-required
[ERROR] Specifically asked for min-required via terraform{required_version}, but none found

[2] Logs

[DEBUG] DEBUG trap set
[DEBUG] Helpers sourced successfully
[DEBUG] $PATH does not contain '/tfenv/libexec', prepending and exporting it now
[DEBUG] $PATH already contains '/tfenv/bin', not adding it again
[DEBUG] program="terraform"
[DEBUG] Getting version from tfenv-version-name
[DEBUG] We are not hardcoded by a TFENV_TERRAFORM_VERSION environment variable
[DEBUG] Looking for a version file in my-terraform-repo/environments/prod/app/
[DEBUG] Not found at my-terraform-repo/environments/prod/app/.terraform-version
[DEBUG] Not found at my-terraform-repo/environments/core-us/test/.terraform-version
[DEBUG] Not found at my-terraform-repo/environments/core-us/.terraform-version
[DEBUG] Not found at my-terraform-repo/environments/.terraform-version
[DEBUG] Found at my-terraform-repo/.terraform-version
[DEBUG] TFENV_VERSION_FILE retrieved from tfenv-version-file: my-terraform-repo/.terraform-version
[DEBUG] TFENV_VERSION specified in TFENV_VERSION_FILE: 0.12.31
[DEBUG] TFENV_VERSION does not use "latest" keyword
[DEBUG] TFENV_VERSION is 0.12.31
[DEBUG] TF_BIN_PATH added to PATH: /tfenv/versions/0.12.31/terraform
[DEBUG] Executing: /tfenv/versions/0.12.31/terraform --version

[DEBUG] DEBUG trap set
[DEBUG] Helpers sourced successfully
[DEBUG] $PATH does not contain '/tfenv/libexec', prepending and exporting it now
[DEBUG] $PATH already contains '/tfenv/bin', not adding it again
[DEBUG] program="terraform"
[DEBUG] Getting version from tfenv-version-name
[DEBUG] We are not hardcoded by a TFENV_TERRAFORM_VERSION environment variable
[DEBUG] Looking for a version file in my-terraform-repo/environments/prod/app/.terragrunt-cache/8kcUskwcodabi_9rgmHym1b0bKE/FHuSDBinFToTe6gwQR0jDZ9T7p4/app
[DEBUG] Not found at my-terraform-repo/environments/prod/app/.terragrunt-cache/8kcUskwcodabi_9rgmHym1b0bKE/FHuSDBinFToTe6gwQR0jDZ9T7p4/app/.terraform-version
[DEBUG] Not found at my-terraform-repo/environments/prod/app/.terragrunt-cache/8kcUskwcodabi_9rgmHym1b0bKE/FHuSDBinFToTe6gwQR0jDZ9T7p4/.terraform-version
[DEBUG] Not found at my-terraform-repo/environments/prod/app/.terragrunt-cache/8kcUskwcodabi_9rgmHym1b0bKE/.terraform-version
[DEBUG] Not found at my-terraform-repo/environments/prod/app/.terragrunt-cache/.terraform-version
[DEBUG] Not found at my-terraform-repo/environments/prod/app/.terraform-version
[DEBUG] Not found at my-terraform-repo/environments/prod/.terraform-version
[DEBUG] Not found at my-terraform-repo/environments/.terraform-version
[DEBUG] Found at my-terraform-repo/.terraform-version
[DEBUG] TFENV_VERSION_FILE retrieved from tfenv-version-file: my-terraform-repo/.terraform-version
[DEBUG] TFENV_VERSION specified in TFENV_VERSION_FILE: 0.12.31
[DEBUG] TFENV_VERSION does not use "latest" keyword
[DEBUG] TFENV_VERSION is 0.12.31
[DEBUG] TF_BIN_PATH added to PATH: /tfenv/versions/0.12.31/terraform
[DEBUG] Executing: /tfenv/versions/0.12.31/terraform init
tpoindessous commented 2 years ago

Yes, this is quite strange :

$ export TFENV_TERRAFORM_VERSION=min-required
$ ls
# empty dir
$ tfenv use 1.0.2
Failure to resolve version from 1.0.2
$ cd myapp
# terraform min required : 1.0.3
$ tfenv use 1.0.2
Switching default version to v1.0.3
Default version (when not overridden by .terraform-version or TFENV_TERRAFORM_VERSION) is now: 1.0.3

I was thinking that TFENV_TERRAFORM_VERSION would be used ONLY when I don't specify a version in command line.