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 pkg/iac/detection/detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func IsTerraformFile(path string) bool {
return true
}

for _, ext := range []string{".tf", ".tf.json", ".tfvars"} {
for _, ext := range []string{".tf", ".tf.json", ".tfvars", ".tofu", ".tofu.json"} {
if strings.HasSuffix(path, ext) {
return true
}
Expand Down
40 changes: 40 additions & 0 deletions pkg/iac/detection/detect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,46 @@ func Test_Detection(t *testing.T) {
FileTypeTerraform,
},
},
{
name: "tofu, no reader",
path: "main.tofu",
expected: []FileType{
FileTypeTerraform,
},
},
{
name: "tofu, with reader",
path: "main.tofu",
r: strings.NewReader("some file content"),
expected: []FileType{
FileTypeTerraform,
},
},
{
name: "tofu json, no reader",
path: "main.tofu.json",
expected: []FileType{
FileTypeTerraform,
FileTypeJSON,
},
},
{
name: "tofu json, with reader",
path: "main.tofu.json",
r: strings.NewReader(`
{
"variable": {
"example": {
"default": "hello"
}
}
}
`),
expected: []FileType{
FileTypeTerraform,
FileTypeJSON,
},
},
{
name: "cloudformation, no reader",
path: "main.yaml",
Expand Down
4 changes: 2 additions & 2 deletions pkg/iac/scanners/terraform/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ func (p *Parser) Files() map[string]*hcl.File {

func (p *Parser) ParseFile(_ context.Context, fullPath string) error {

isJSON := strings.HasSuffix(fullPath, ".tf.json")
isHCL := strings.HasSuffix(fullPath, ".tf")
isJSON := strings.HasSuffix(fullPath, ".tf.json") || strings.HasSuffix(fullPath, ".tofu.json")
isHCL := strings.HasSuffix(fullPath, ".tf") || strings.HasSuffix(fullPath, ".tofu")
if !isJSON && !isHCL {
return nil
}
Expand Down
Loading