Open paultyng opened 4 years ago
also possibly https://warrensbox.github.io/terraform-switcher/
See https://github.com/hashicorp/terraform-ls/issues/128 for unexpected behaviour cased by using a wrapper script to set appropriate env vars.
At least warn or let consumers know if these tools are being used, even if we aren't going to handle it.
Another one: https://github.com/Yleisradio/homebrew-terraforms
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).
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
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
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
tfinstall.LookPath()
- do not error out when an executable named terraform
is found but terraform version
does not return reasonable output; fall through to the next method instead.terraform
on their path resolves to a different version depending on working directory, this will also be true of the Terraform executable located by tfinstall.LookPath()
.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.
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: yesterraform-switcher
terraform
on path is now a shell script: no Terraform version may depend on working directory: yeshomebrew-terraforms
terraform
on path is now a shell script: no Terraform version may depend on working directory: noasdf
terraform
on path is now a shell script: unknown Terraform version may depend on working directory: unknown