Skip to content

Add tofu to format on save list#199

Open
dpiddock wants to merge 1 commit into
hashivim:masterfrom
dpiddock:tofu
Open

Add tofu to format on save list#199
dpiddock wants to merge 1 commit into
hashivim:masterfrom
dpiddock:tofu

Conversation

@dpiddock
Copy link
Copy Markdown

A follow-on from #193, this adds the tofu extensions to the format-on-save list.

@dimbleby
Copy link
Copy Markdown
Contributor

dimbleby commented Nov 1, 2025

I'm inclined to think that #193 was a mistake and should be undone, rather than going further down that path.

Are .tofu and .tf files the same or not?

  • if yes, then folk can either use the .tf extension all along, or else set up their own filetype detection
  • if no, then it is a mistake to treat them as if they are the same

What I don't want is to slip gradually into accidental support for a non-terraform filetype

@yermulnik
Copy link
Copy Markdown

Are .tofu and .tf files the same or not?

They are the same. OpenTofu prefers .tofu over .tf files if they have the same base name, but otherwise OpenTofu reads both. Terraform ignores .tofu files obviously.
Ref: https://opentofu.org/docs/language/files/

ps: I'm not a user of OpenTofu though, just wanted to add clarity FWIW.

@ab
Copy link
Copy Markdown

ab commented Mar 25, 2026

Ping on this? It's pretty confusing having .tofu files recognized by vim-terraform for file type detection but not for auto-formatting. (It took me a while to figure out why they weren't getting formatted.)

As far as syntax goes, they're currently the same and compatible. Although they certainly could diverge at some point in the future.

terraform fmt normally doesn't accept .tofu files on the command line, but because terraform#fmt() passes the buffer in on stdin, there's no compatibility issue at present.

I'd vote for merging as is, but an alternative possibility might be to introduce a setting like g:terraform_use_opentofu, which would set g:terraform_binary_path = 'tofu' and also add the .tofu file types.

@dimbleby
Copy link
Copy Markdown
Contributor

I still think I would prefer just to revert #193, users who care about .tofu can add their own autocmds

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

Successfully merging this pull request may close these issues.

4 participants