Skip to content

Conversation

@adalinesimonian
Copy link

Adds .tofu extension to HCL, as used by OpenTofu.

Description

OpenTofu supports .tf as used by Terraform, but uses .tofu to allow OpenTofu-specific behaviour to be ignored by Terraform. The project has also reserved any new OpenTofu syntax for compatibility reasons to .tofu files alone. New language-changing syntax that would require adjustments to syntax highlighting has not been introduced, so therefore I believe it is safe to simply add .tofu as an extension for HCL.

Adoption of .tofu seems to have been more rapid amongst end-users, who likely have private repositories. While there are still several hundred results on GitHub, most lengthy, good examples of HCL in use with the .tofu extension were likely going to be behind this wall. Therefore, I wrote a length-enough example that resembles code I have in production at my employer and with other projects. I am happy to have it licensed under Linguist's MIT licence.

Checklist:

  • I am adding a new extension to a language.

@adalinesimonian adalinesimonian requested a review from a team as a code owner January 2, 2025 21:53
@lildude lildude changed the title feat: Support OpenTofu .tofu extension for HCL Add OpenTofu .tofu extension to HCL Jan 3, 2025
@diofeher
Copy link

diofeher commented May 9, 2025

We're willing to see this being merged, thanks for the contribution @adalinesimonian !

@adalinesimonian
Copy link
Author

adalinesimonian commented May 11, 2025

We're willing to see this being merged, thanks for the contribution @adalinesimonian !

That's great news! I just merged main into the feature branch; it'll be great to see if GitHub can get around to giving this a look when they have the time. :)

@Mizux
Copy link
Contributor

Mizux commented Jul 2, 2025

FYI gitlab already patch their vendoring version but also add an alias opentofu ;)
see: https://gitlab.com/gitlab-org/gitlab/-/commit/55f90041e209157c86eca90f967c4ad86089d9f0#0b2f55bf2ba1a6446a3c4bc6fbdf423346760b6f

@adalinesimonian
Copy link
Author

FYI gitlab already patch their vendoring version but also add an alias opentofu

Just rebased off main and added the opentofu alias. I think that's a great catch.

@ab
Copy link

ab commented Nov 12, 2025

@lildude any chance this could be reviewed?

@lildude
Copy link
Member

lildude commented Nov 13, 2025

Usage it reviewed whenever a new release is made. I do not comment to say usage hasn't met as this would lead to a lot of unnecessary noise so no news means usage hasn't been met. I'll review again when I make the next release.

@ab
Copy link

ab commented Nov 13, 2025

Thanks! Usage means this popularity assessment? Which criteria weren't yet met?

I know this is subjective and open to debate so the loose rules I'll be using are along the lines of:

  • at least 2000 files per extension indexed in the last year (the number you see at the top of the search results), unless the extension is expected to only occur once per repo, then 200 files.
  • with a reasonable distribution across unique :user/:repo combinations assessed by manually and randomly clicking through the results.

I see 2.2k files in the search result now. Was that not true in September?

Just trying to understand the typical cadence, as this seems to be a similar number of search results as for .wls files, which had support merged in #7634 in October (pending release).

@rtorrente
Copy link

Usage it reviewed whenever a new release is made. I do not comment to say usage hasn't met as this would lead to a lot of unnecessary noise so no news means usage hasn't been met. I'll review again when I make the next release.

Furthermore, this mode of operation is not as relevant for this extension. Indeed, it is still possible to write most files in .hcl format, and GitHub's lack of support for .tofu does not encourage its adoption on github only project.
At my company, we write our opentofu code in .hcl and only use the .tofu extension for files that use features specific to open tofu. We made this choice solely to have syntax highlighting on PR reviews.

@raz-drift
Copy link

Hey, that will be really helpful. Waiting for that too in our company (and I know others too).
cc this request opentofu/vscode-opentofu#107 (comment)

@mikicz
Copy link

mikicz commented Dec 9, 2025

At my company, we write our opentofu code in .hcl and only use the .tofu extension for files that use features specific to open tofu. We made this choice solely to have syntax highlighting on PR reviews.

This is exactly the same case at my organisation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants