linguist icon indicating copy to clipboard operation
linguist copied to clipboard

Add OpenTofu .tofu extension to HCL

Open adalinesimonian opened this issue 11 months ago • 10 comments

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:

  • [x] I am adding a new extension to a language.
    • [x] The new extension is used in hundreds of repositories on GitHub.com
      • Search results for each extension:
        • https://github.com/search?type=code&q=NOT+is%3Afork+path%3A*.tofu
    • [x] I have included a real-world usage sample for all extensions added in this PR:
      • Sample source(s):
        • Self-written, see above
      • Sample license(s):
        • MIT

adalinesimonian avatar Jan 02 '25 21:01 adalinesimonian

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

diofeher avatar May 09 '25 09:05 diofeher

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. :)

adalinesimonian avatar May 11 '25 08:05 adalinesimonian

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

Mizux avatar Jul 02 '25 15:07 Mizux

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.

adalinesimonian avatar Jul 02 '25 15:07 adalinesimonian

@lildude any chance this could be reviewed?

ab avatar Nov 12 '25 21:11 ab

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.

lildude avatar Nov 13 '25 11:11 lildude

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).

ab avatar Nov 13 '25 14:11 ab

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.

rtorrente avatar Nov 21 '25 09:11 rtorrente

Hey, that will be really helpful. Waiting for that too in our company (and I know others too). cc this request https://github.com/opentofu/vscode-opentofu/issues/107#issue-3604003679

raz-drift avatar Nov 26 '25 11:11 raz-drift