hashicorp / terraform-exec

Terraform CLI commands via Go.
https://pkg.go.dev/github.com/hashicorp/terraform-exec
Mozilla Public License 2.0
662 stars 111 forks source link

Investigate / test tfenv usage or other script like executable wrappers #6

Open paultyng opened 4 years ago

paultyng commented 4 years ago

This is mostly relevant to the LS, but something we should investigate.

Known wrappers

See https://github.com/hashicorp/terraform-exec/issues/6#issuecomment-703315302 for more details.

tfenv

terraform on path is now a shell script: yes Terraform version may depend on working directory: yes

terraform-switcher

terraform on path is now a shell script: no Terraform version may depend on working directory: yes

homebrew-terraforms

terraform on path is now a shell script: no Terraform version may depend on working directory: no

asdf

terraform on path is now a shell script: unknown Terraform version may depend on working directory: unknown

kmoe commented 4 years ago

also possibly https://warrensbox.github.io/terraform-switcher/

kmoe commented 4 years ago

See https://github.com/hashicorp/terraform-ls/issues/128 for unexpected behaviour cased by using a wrapper script to set appropriate env vars.

paultyng commented 4 years ago

At least warn or let consumers know if these tools are being used, even if we aren't going to handle it.

kmoe commented 4 years ago

Another one: https://github.com/Yleisradio/homebrew-terraforms

kmoe commented 3 years ago

Results of investigation. Branch tfenv-etc contains some Dockerfiles for experimenting with these utilities in a clean environment (except homebrew-terraforms, which is only available for macOS).

tfenv

Installing tfenv adds a shell script named terraform to the $PATH, so which terraform resolves to this script. This script checks whether $TFENV_ROOT/version is set, and errors if not. An error will also be logged if the user has not selected a version with tfenv use.

Currently, this means that any use of tfinstall.LookPath() will error and not fall through to the next ExecPathFinder, because it assumes that if it finds a terraform binary then it must report terraform version properly. Recommend relaxing this and will open PR to do so.

terraform on path is now a shell script: yes Terraform version may depend on working directory: yes

terraform-switcher

Installing a Terraform version via tfswitch replaces any existing Terraform binary with a symlink. This is only done when installing a new version of Terraform, so unlike tfenv there is no risk of the binary or script at which terraform not pointing to Terraform itself.

terraform on path is now a shell script: no Terraform version may depend on working directory: yes

homebrew-terraforms

The most conservative of the three helpers, this simply provides a chtf utility which allows the user to install and (with caching) switch between various versions of Terraform via the brew package manager. It therefore has no more impact on tfexec than brew itself.

terraform on path is now a shell script: no Terraform version may depend on working directory: no

Conclusion & recommendations

kvendingoldo commented 5 months ago

btw. you can also use tenv that support Terraform as well as OpenTofu (and Terragrunt :) ) in one tool. It allow you to simplify version management and can do much more, than tfswitch.