Skip to content
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
2 changes: 1 addition & 1 deletion cli/commands/run/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (err BackendNotDefined) Error() string {
type NoTerraformFilesFound string

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

type ModuleIsProtected struct {
Expand Down
14 changes: 14 additions & 0 deletions cli/commands/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,13 +540,27 @@ func CheckFolderContainsTerraformCode(terragruntOptions *options.TerragruntOptio

files = append(files, hclFiles...)

tofuHclFiles, err := zglob.Glob(terragruntOptions.WorkingDir + "/**/*.tofu")
if err != nil {
return errors.New(err)
}

files = append(files, tofuHclFiles...)

jsonFiles, err := zglob.Glob(terragruntOptions.WorkingDir + "/**/*.tf.json")
if err != nil {
return errors.New(err)
}

files = append(files, jsonFiles...)

tofuJSONFiles, err := zglob.Glob(terragruntOptions.WorkingDir + "/**/*.tofu.json")
if err != nil {
return errors.New(err)
}

files = append(files, tofuJSONFiles...)

if len(files) == 0 {
return errors.New(NoTerraformFilesFound(terragruntOptions.WorkingDir))
}
Expand Down
22 changes: 21 additions & 1 deletion cli/commands/run/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,33 @@ func TestTerragruntTerraformCodeCheck(t *testing.T) {
workingDir: "test-fixtures/dir-with-terraform",
valid: true,
},
{
description: "Directory with plain OpenTofu",
workingDir: "test-fixtures/dir-with-tofu",
valid: true,
},
{
description: "Directory with plain Terraform and OpenTofu",
workingDir: "test-fixtures/dir-with-terraform-and-tofu",
valid: true,
},
{
description: "Directory with JSON formatted Terraform",
workingDir: "test-fixtures/dir-with-terraform-json",
valid: true,
},
{
description: "Directory with no Terraform",
description: "Directory with JSON formatted OpenTofu",
workingDir: "test-fixtures/dir-with-tofu-json",
valid: true,
},
{
description: "Directory with JSON formatted Terraform and OpenTofu",
workingDir: "test-fixtures/dir-with-terraform-and-tofu-json",
valid: true,
},
{
description: "Directory with no Terraform or OpenTofu",
workingDir: "test-fixtures/dir-with-no-terraform",
valid: false,
},
Expand Down
Empty file.
Empty file.
Empty file.
Empty file.