hcl-emacs / terraform-mode

Major mode of Terraform configuration file
GNU General Public License v3.0
221 stars 33 forks source link

[Feat] Support for OpenTofu `tofu fmt` #73

Open smokestacklightnin opened 1 month ago

smokestacklightnin commented 1 month ago

terraform-mode currently necessarily calls the terraform binary when formatting buffers or regions

Would it please be possible to add the option to call the OpenTofu tofu command for fomatting instead of terraform for those of us with only OpenTofu installed?

I expect this is as simple as creating a configurable variable. I'd open a PR myself, but I'm not familiar enough with Lisp to do this quickly.

dotemacs commented 1 month ago

This is what you can use to detect which registry you're using:

https://noxon.cc/@jeff/112157251058272180

So taking that idea, a way to go about this is to look at the presence of registry.opentofu.org in .terraform.lock.hcl. If OpenTofu's registry is used, use the tofu executable, otherwise, use terraform.

Fuco1 commented 1 month ago

@dotemacs Can't you use one registry with the other binary? If this is 100% reliable then we can do that indeed, otherwise a config variable (which you can also set in directory local setup then to override for specific repository) would be a better option.

dotemacs commented 1 month ago

@dotemacs Can't you use one registry with the other binary?

What exactly do you mean by this @Fuco1?

Do you mean can OpenTofu registry be used with Terraform? And vice versa?

If this is 100% reliable then we can do that indeed,

I saw the above quoted answer on Mastodon and then saw the same toot shared by the OpenTofu core developers, when other people asked about it on OpenTofu Slack. I'm basing my perception of reliability solely on that.

otherwise a config variable (which you can also set in directory local setup then to override for specific repository) would be a better option.

I'd say, that having both would be a good thing.