Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Adding first-class support for .tofu files. #811

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
skyzyx opened this issue Oct 24, 2024 · 4 comments · Fixed by #833
Open

Adding first-class support for .tofu files. #811

skyzyx opened this issue Oct 24, 2024 · 4 comments · Fixed by #833

Comments

@skyzyx
Copy link

skyzyx commented Oct 24, 2024

What problem are you facing?

OpenTofu is adding support for .tofu files in addition to .tf files. Terraform only supports .tf files, and OpenTofu will support both. This will allow users to have tool-specific configurations in places where it matters (e.g., provider functions landing in Terraform 1.8 and OpenTofu 1.7, and wanting to gate-keep the CLI tool by version).

If two files have the same name with each file extension (e.g., main.tf and main.tofu), OpenTofu will execute main.tofu and NOT main.tf, while Terraform will execute main.tf.

It's still all HCL syntax in these files.

How could terraform-docs help solve your problem?

I don't believe that generating two sets of documentation is the right approach — one for Terraform, and one for OpenTofu. Instead, I believe that in cases where .tofu files exist, the OpenTofu configuration should be provided in tandem with the Terraform configuration.

For example, in the JSON output, requirements is an array of objects, with each object defining name and version. Perhaps this could be modified to support "name": "opentofu" with its version, and for any providers/modules, there is a new tool key which contains an array of tool identifiers (e.g., terraform and opentofu).

This would allow flexibility in the future in case (God forbid) another fork happens in the community. This also shouldn't (AFAIK) require any backwards-incompatible changes.

This would also mean that for content, it would be useful to define .IsTerraform and .IsOpenTofu variables, so that users can adjust the examples or other custom documentation to more specifically target each tool.

Ways for readers to switch between the two flavors of tooling could be either a tabbed interface (and a nice touch would be like many API documentation websites where if you select a preferred language in a tabbed interface to view those examples, that all other examples switch to that same language too) — OR something simpler, but less "nice" like a <select> HTML field where you can select which version to view.

@pascal-hofmann
Copy link
Contributor

I just merged #833 which adds support for .tofu files. I think this is a good first step. Let's see how this works out, and what we need to improve in the wild with projects that used a mix of both file endings.

@muffl0n
Copy link

muffl0n commented Apr 7, 2025

I think I'm using this wrong, cause files with .tofu are still being ignored. I made a minimal POC in https://github.com/muffl0n/terraform-docs-opentofu where the resource in opentofu.tofu is being ignored, but the resource in terraform.tf is not.

@khos2ow
Copy link
Member

khos2ow commented Apr 8, 2025

@muffl0n , you are not wrong on this. I've spent a bit of time today and as of now v0.20.0 only partially supports OpenTofu. I've updated release notes accordingly.

As of now, we are only able to read header and footer from .tofu files. I'm working on it.

As I've looked around, nothing else needs to be done within terraform-docs/terraform-docs repo though, terraform-docs/terraform-config-inspect needs updating.

I am going to reopen this issue for further tracking and visibility.

@jamesgeddes
Copy link
Contributor

Apologies for the omission!

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

Successfully merging a pull request may close this issue.

5 participants