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

Skip to content

add support for .tofu files #833

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

Merged
merged 1 commit into from
Apr 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/user-guide/configuration/footer-from.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ toc: true
Since `v0.12.0`

Relative path to a file to extract footer for the generated output from. Supported
file formats are `.adoc`, `.md`, `.tf`, and `.txt`.
file formats are `.adoc`, `.md`, `.tf`, `.tofu`, and `.txt`.

{{< alert type="info" >}}
The whole file content is being extracted as module footer when extracting from
`.adoc`, `.md`, or `.txt`.
{{< /alert >}}

To extract footer from `.tf` file you need to use following javascript, c, or java
To extract footer from `.tf` or `.tofu` file you need to use following javascript, c, or java
like multi-line comment.

```tf
Expand All @@ -37,7 +37,7 @@ resource "foo" "bar" { ... }
```

{{< alert type="info" >}}
This comment must start at the immediate first line of the `.tf` file
This comment must start at the immediate first line of the `.tf` or `.tofu` file
before any `resource`, `variable`, `module`, etc.
{{< /alert >}}

Expand Down
6 changes: 3 additions & 3 deletions docs/user-guide/configuration/header-from.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ toc: true
Since `v0.10.0`

Relative path to a file to extract header for the generated output from. Supported
file formats are `.adoc`, `.md`, `.tf`, and `.txt`.
file formats are `.adoc`, `.md`, `.tf`, `.tofu`, and `.txt`.

{{< alert type="info" >}}
The whole file content is being extracted as module header when extracting from
`.adoc`, `.md`, or `.txt`.
{{< /alert >}}

To extract header from `.tf` file you need to use following javascript, c, or java
To extract header from `.tf` or `.tofu` file you need to use following javascript, c, or java
like multi-line comment.

```tf
Expand All @@ -37,7 +37,7 @@ resource "foo" "bar" { ... }
```

{{< alert type="info" >}}
This comment must start at the immediate first line of the `.tf` file
This comment must start at the immediate first line of the `.tf` or `.tofu` file
before any `resource`, `variable`, `module`, etc.
{{< /alert >}}

Expand Down
7 changes: 4 additions & 3 deletions terraform/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ func isFileFormatSupported(filename string, section string) (bool, error) {
return false, fmt.Errorf("--%s-from value is missing", section)
}
switch getFileFormat(filename) {
case ".adoc", ".md", ".tf", ".txt":
case ".adoc", ".md", ".tf", ".tofu", ".txt":
return true, nil
}
return false, fmt.Errorf("only .adoc, .md, .tf, and .txt formats are supported to read %s from", section)
return false, fmt.Errorf("only .adoc, .md, .tf, .tofu and .txt formats are supported to read %s from", section)
}

func loadHeader(config *print.Config) (string, error) {
Expand Down Expand Up @@ -146,7 +146,8 @@ func loadSection(config *print.Config, file string, section string) (string, err
}
return "", err // user explicitly asked for a file which doesn't exist
}
if getFileFormat(file) != ".tf" {
format := getFileFormat(file)
if format != ".tf" && format != ".tofu" {
content, err := os.ReadFile(filepath.Clean(filename))
if err != nil {
return "", err
Expand Down
14 changes: 11 additions & 3 deletions terraform/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@ func TestIsFileFormatSupported(t *testing.T) {
errText: "",
section: "header",
},
{
name: "is file format supported",
filename: "main.tofu",
expected: true,
wantErr: false,
errText: "",
section: "header",
},
{
name: "is file format supported",
filename: "main.txt",
Expand All @@ -174,7 +182,7 @@ func TestIsFileFormatSupported(t *testing.T) {
filename: "main.doc",
expected: false,
wantErr: true,
errText: "only .adoc, .md, .tf, and .txt formats are supported to read header from",
errText: "only .adoc, .md, .tf, .tofu and .txt formats are supported to read header from",
section: "header",
},
{
Expand All @@ -189,7 +197,7 @@ func TestIsFileFormatSupported(t *testing.T) {
filename: "main.doc",
expected: false,
wantErr: true,
errText: "only .adoc, .md, .tf, and .txt formats are supported to read footer from",
errText: "only .adoc, .md, .tf, .tofu and .txt formats are supported to read footer from",
section: "footer",
},
{
Expand Down Expand Up @@ -405,7 +413,7 @@ func TestLoadSections(t *testing.T) {
file: "wrong-formate.docx",
expected: "",
wantErr: true,
errText: "only .adoc, .md, .tf, and .txt formats are supported to read footer from",
errText: "only .adoc, .md, .tf, .tofu and .txt formats are supported to read footer from",
section: "footer",
},
{
Expand Down