Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow "terraform" to be equivalent to "tf" (prefer opentofu, if version file exists) #339

Open
kittydoor opened this issue Jan 23, 2025 · 5 comments
Assignees

Comments

@kittydoor
Copy link

Taken from README:

tool (alias) env vars description
tofu (opentofu) TOFUENV_ OpenTofu
tf (terraform) TFENV_ Terraform
tg (terragrunt) TG_ Terragrunt
at (atmos) ATMOS_ Atmos

In my testing, current behavior of the above commands is actually like below:

  • tofu -> assumes opentofu
  • terraform -> assumes Hashicorp Terraform
  • tf -> checks for .terraform-version or .opentofu-version, prefers latter
  • opentofu -> command not found

I ended up investigating this as I had an issue with my neovim setup (specifically, the linting plugin) failing to run tenv managed opentofu. I came across this issue by someone else which made me realise the issue might be because tenv is being called under the name terraform: mfussenegger/nvim-lint#726

This neovim plugin, as well as tons of other tooling, assume that they will find the tool under the name terraform. In my case, it is a lot easier to have tenv replicate the same behavior for tf when called as terraform, rather than keep an eye out for this issue for every integration I use and configure them. After all, it is rare for me to want to use both terraform and opentofu on the same project.

A global config file or .tenvrc or an environment variable (ideally, all of the above) that let me change this behavior would be perfect, however maybe you have thoughts about what's best in the long term to ensure stability for all users while allowing this workflow without requiring shell aliases or shadowing the binary.

@dvaumoron
Copy link
Contributor

dvaumoron commented Jan 23, 2025

There is a misunderstanding here, as stated in the sentence at the start of this section, the tool column describe the possibility for tenv <tool>, so tenv tf install is equivalent to tenv terraform install.

That's different from the terraform proxy which call the right terraform version, tofu proxy which call the right version of opentofu (project name differs from the cli executable which is also tofu) and tf which is meant to be an agnostic proxy and "prefer" opentofu (see resolution order)

@kittydoor
Copy link
Author

@dvaumoron thank you for the additional context! I will clarify my request then.

For personal use in the terminal, I use the tf agnostic proxy, and this works perfectly.

Some tools I use that integrate with terraform/opentofu have terraform hardcoded and thus end up using the terraform proxy, and I would like to request a way to configure it to behave the same way as tf (i.e. be agnostic).

@dvaumoron
Copy link
Contributor

dvaumoron commented Jan 29, 2025

You can rename the binary (the tf link in it is hardcoded, so does not rely on it's own name)

@kittydoor
Copy link
Author

Rather than overriding the "terraform" binary by masking it with a symlink to "tf" earlier in my PATH, I would prefer to be able to configure tenv to handle this (imo this should be the default behavior of tenv's terraform shim).

My primary concern that makes me prefer this is to avoid confusion with differences in environments such as my local machine vs GitHub Actions vs a compute instance somewhere vs other developers' machines. tenv uniting these environments is the part that makes it so useful for me, and at least until terraform and opentofu diverge significantly, having this be integrated into tenv would be convenient.

However, if you as the maintainer think differently about this, and don't want this change implemented in tenv, that's totally fine 👍
In that case, please feel free to close this issue as WONTFIX.

@dvaumoron
Copy link
Contributor

I will add an env var to switch the terraform proxy behavior to be the agnostic behavior.

@dvaumoron dvaumoron self-assigned this Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants