Add OpenTofu .tofu extension to HCL by adalinesimonian · Pull Request #7189 · github-linguist/linguist · GitHub
Skip to content

Add OpenTofu .tofu extension to HCL#7189

Merged
lildude merged 2 commits into
github-linguist:mainfrom
adalinesimonian:patch-1
Jan 8, 2026
Merged

Add OpenTofu .tofu extension to HCL#7189
lildude merged 2 commits into
github-linguist:mainfrom
adalinesimonian:patch-1

Conversation

@adalinesimonian

Copy link
Copy Markdown
Contributor

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

diofeher commented May 9, 2025

Copy link
Copy Markdown

@adalinesimonian

adalinesimonian commented May 11, 2025

Copy link
Copy Markdown
Contributor Author

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

Mizux commented Jul 2, 2025

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor 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

ab commented Nov 12, 2025

Copy link
Copy Markdown

@lildude any chance this could be reviewed?

@lildude

lildude commented Nov 13, 2025

Copy link
Copy Markdown
Member

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

ab commented Nov 13, 2025

Copy link
Copy Markdown

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
Copy Markdown

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
Copy Markdown

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

mikicz commented Dec 9, 2025

Copy link
Copy Markdown

@lildude lildude left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks.

Important

The changes in this PR will not appear on GitHub until the next release has been made and deployed. See here for more details.

@lildude lildude added this pull request to the merge queue Jan 8, 2026
Merged via the queue into github-linguist:main with commit 0fdef54 Jan 8, 2026
5 checks passed
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.

8 participants