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

min-required and fallback #353

Open
JeanFred opened this issue Jul 26, 2022 · 1 comment · May be fixed by #365
Open

min-required and fallback #353

JeanFred opened this issue Jul 26, 2022 · 1 comment · May be fixed by #365

Comments

@JeanFred
Copy link

JeanFred commented Jul 26, 2022

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 #305 (comment) and my mixed-version code base.

  • if I use TFENV_TERRAFORM_VERSION=min-required, then that first terraform --version call fails with [1]
  • if I don’t set it, then tfenv does not attempt to read the the min-required and use the 'default' 0.12, which fails with tf13 code. [2]

#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
Copy link

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.

JeanFred added a commit to JeanFred/tfenv that referenced this issue Oct 25, 2022
Even when setting `TFENV_TERRAFORM_VERSION` to `min-required`,
we might prefer to fallback on the normal inference method
rather than a hard fail.

Resolves tfutils#353
@JeanFred JeanFred linked a pull request Oct 25, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants