tfutils / tfenv

Terraform version manager
MIT License
4.43k stars 450 forks source link

[WIP] Add graceful fail for min-required #365

Open JeanFred opened 1 year ago

JeanFred commented 1 year ago

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 #353

JeanFred commented 1 year ago

I’m floating this a fairly naive (and maybe not desirable) solution to #353. It does work fine, although the recursive call to tfenv-version-name might not be the most elegant solution. I mean this as a conversation starter :)

JeanFred commented 1 year ago

Sample output: TFENV_DEBUG=1 TFENV_TERRAFORM_VERSION='min-required' /.tfenv/bin/terraform --version

[DEBUG] Sourcing helpers from /.tfenv/lib/helpers.sh
DEBUG trap set
Helpers sourced successfully
$PATH does not contain '/.tfenv/libexec', prepending and exporting it now
$PATH does not contain '/.tfenv/bin', prepending and exporting it now
program="terraform"
Getting version from tfenv-version-name
TFENV_VERSION specified in TFENV_TERRAFORM_VERSION environment variable: min-required
TFENV_VERSION uses min-required keyword, looking for a required_version in the code
Appropriate required_version not found, skipping min-required
Specifically asked for min-required via terraform{required_version}, but none found, continuing
We are not hardcoded by a TFENV_TERRAFORM_VERSION environment variable
Looking for a version file in /code/x/y
Not found at /code/x/y/.terraform-version
Not found at /code/x/.terraform-version
Found at /code/.terraform-version
TFENV_VERSION_FILE retrieved from tfenv-version-file: /code/.terraform-version
TFENV_VERSION specified in TFENV_VERSION_FILE: 0.12.31
TFENV_VERSION does not use "latest" keyword
TFENV_VERSION does not use "latest" keyword
Appropriate required_version not found, skipping min-required
TFENV_VERSION is 0.12.31
TF_BIN_PATH added to PATH: /.tfenv/versions/0.12.31/terraform
Executing: /.tfenv/versions/0.12.31/terraform --version
Terraform v0.12.31
JeanFred commented 1 year ago

Is there any interest in this proposed change? :)