tfenv icon indicating copy to clipboard operation
tfenv copied to clipboard

feature request: happy path for new deployment should honor terraform's required_version

Open jmnavarrol opened this issue 2 years ago • 1 comments

Hi!

First of all, thanks for this nice utility (I use it within my Bash Magic Enviro project).

I want to ask for the default in case of new use to slightly change: given that default for TFENV_AUTO_INSTALL is true (which sounds sensible) and that Terraform has its own well-known way to state the required version, I think tfenv should honor it.

Desired outcome:

  1. TFENV_AUTO_INSTALL to maintain its current default (true).
  2. When requesting any terraform command, if no terraform available, honor TFENV_TERRAFORM_VERSION, auto-install & activate it as needed.
  3. If TFENV_TERRAFORM_VERSION is not defined, look for Terraform's required_version in code (not necessarily in a versions.tf file, but in all available). At first glance, there's another project that can be of help here: terraform-config-inspect. Default version to install in case required_version allows for a range should be the topmost one (equivalent to tfenv install latest-allowed) if no compatible version already installed, or the topmost valid already installed, if any.
  4. if neither TFENV_TERRAFORM_VERSION nor required_version are defined and TFENV_AUTO_INSTALL=true, default to terraform's current higher stable version, or the highest already installed, if any.

Note that the above neglects the need for a .terraform_version file, which should be ditched or, at most, left for backwards compatibility reasons but with discouraged usage (this is a case of "less is more", I think).

jmnavarrol avatar Nov 12 '22 15:11 jmnavarrol

I agree that this is the best solution - There is already a way to specify required version within standard terraform and we should use it if practical. Some care will need to be taken to implement the flexible version syntax used in required_version as that will be required for this implementation to work as expected.

samjgalbraith avatar Mar 22 '23 02:03 samjgalbraith