Skip to content

Commit 43cbf4a

Browse files
authored
detect tofu and tofu.json files from #4061 (#4062)
1 parent 68948b3 commit 43cbf4a

File tree

9 files changed

+36
-2
lines changed

9 files changed

+36
-2
lines changed

cli/commands/run/errors.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func (err BackendNotDefined) Error() string {
3939
type NoTerraformFilesFound string
4040

4141
func (path NoTerraformFilesFound) Error() string {
42-
return "Did not find any Terraform files (*.tf) in " + string(path)
42+
return "Did not find any Terraform files (*.tf) or OpenTofu files (*.tofu) in " + string(path)
4343
}
4444

4545
type ModuleIsProtected struct {

cli/commands/run/run.go

+14
Original file line numberDiff line numberDiff line change
@@ -540,13 +540,27 @@ func CheckFolderContainsTerraformCode(terragruntOptions *options.TerragruntOptio
540540

541541
files = append(files, hclFiles...)
542542

543+
tofuHclFiles, err := zglob.Glob(terragruntOptions.WorkingDir + "/**/*.tofu")
544+
if err != nil {
545+
return errors.New(err)
546+
}
547+
548+
files = append(files, tofuHclFiles...)
549+
543550
jsonFiles, err := zglob.Glob(terragruntOptions.WorkingDir + "/**/*.tf.json")
544551
if err != nil {
545552
return errors.New(err)
546553
}
547554

548555
files = append(files, jsonFiles...)
549556

557+
tofuJSONFiles, err := zglob.Glob(terragruntOptions.WorkingDir + "/**/*.tofu.json")
558+
if err != nil {
559+
return errors.New(err)
560+
}
561+
562+
files = append(files, tofuJSONFiles...)
563+
550564
if len(files) == 0 {
551565
return errors.New(NoTerraformFilesFound(terragruntOptions.WorkingDir))
552566
}

cli/commands/run/run_test.go

+21-1
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,33 @@ func TestTerragruntTerraformCodeCheck(t *testing.T) {
9696
workingDir: "test-fixtures/dir-with-terraform",
9797
valid: true,
9898
},
99+
{
100+
description: "Directory with plain OpenTofu",
101+
workingDir: "test-fixtures/dir-with-tofu",
102+
valid: true,
103+
},
104+
{
105+
description: "Directory with plain Terraform and OpenTofu",
106+
workingDir: "test-fixtures/dir-with-terraform-and-tofu",
107+
valid: true,
108+
},
99109
{
100110
description: "Directory with JSON formatted Terraform",
101111
workingDir: "test-fixtures/dir-with-terraform-json",
102112
valid: true,
103113
},
104114
{
105-
description: "Directory with no Terraform",
115+
description: "Directory with JSON formatted OpenTofu",
116+
workingDir: "test-fixtures/dir-with-tofu-json",
117+
valid: true,
118+
},
119+
{
120+
description: "Directory with JSON formatted Terraform and OpenTofu",
121+
workingDir: "test-fixtures/dir-with-terraform-and-tofu-json",
122+
valid: true,
123+
},
124+
{
125+
description: "Directory with no Terraform or OpenTofu",
106126
workingDir: "test-fixtures/dir-with-no-terraform",
107127
valid: false,
108128
},

cli/commands/run/test-fixtures/dir-with-terraform-and-tofu-json/main.tf.json

Whitespace-only changes.

cli/commands/run/test-fixtures/dir-with-terraform-and-tofu-json/main.tofu.json

Whitespace-only changes.

cli/commands/run/test-fixtures/dir-with-terraform-and-tofu/main.tf

Whitespace-only changes.

cli/commands/run/test-fixtures/dir-with-terraform-and-tofu/main.tofu

Whitespace-only changes.

cli/commands/run/test-fixtures/dir-with-tofu-json/main.tofu.json

Whitespace-only changes.

cli/commands/run/test-fixtures/dir-with-tofu/main.tofu

Whitespace-only changes.

0 commit comments

Comments
 (0)