tfutils/tfenv

Let .terraform-version have comments with a #

isybub opened this issue · 1 comments

I made a branch and tried to make a PR but I can't find contribution guidelines so I don't think I can push to the remote.
All it is is changing line 13 in lib/tfenv-version-name.sh
from
TFENV_VERSION="$cat "${TFENV_VERSION_FILE}" || true)"
to
TFENV_VERSION="$(sed -e '/^#/d' "${TFENV_VERSION_FILE}" || true)" \

This also strips blank lines.

An alternate, maybe easier and less prone to side effects, approach would be to completely ditch .terraform-version file. See #367 for a happy path.

Then:

  • If TFENV_AUTO_INSTALL=true:
    • Is there a version requested on Terraform source code? Honor it, maybe with the help of TFENV_TERRAFORM_VERSION's value min-allowed / latest-allowed.
    • When Terraform source code doesn't hint a version, honor TFENV_TERRAFORM_VERSION. If TFENV_TERRAFORM_VERSION is not set, consider its default value to be latest-allowed.
  • If TFENV_AUTO_INSTALL=false, do nothing.

This way, just using tfenv on its default configuration will render the expected results: Terraform ends up installed and working on the highest valid version (either latest stable or the highest one as per Terraform's code constrains).

Also you can avoid tfenv automatically installing terraform as per TFENV_AUTO_INSTALL=false.
Also you can change tfenv's default version management behaviour by means of TFENV_TERRAFORM_VERSION=min-allowed.
Also you could set TFENV_TERRAFORM_VERSION to an explicit version (this usage should be discouraged: use Terraform's own required_version parameter for that.