diff --git a/pkg/iac/ignore/rule.go b/pkg/iac/ignore/rule.go index ebe8c780a198..61057ce75f87 100644 --- a/pkg/iac/ignore/rule.go +++ b/pkg/iac/ignore/rule.go @@ -12,7 +12,7 @@ import ( ) // Ignorer represents a function that checks if the rule should be ignored. -type Ignorer func(resultMeta types.Metadata, param any) bool +type Ignorer func(resultMeta types.Metadata, ignoredParam any) bool type Rules []Rule diff --git a/pkg/iac/scanners/terraform/executor/executor.go b/pkg/iac/scanners/terraform/executor/executor.go index c8728636847e..23f05046b163 100644 --- a/pkg/iac/scanners/terraform/executor/executor.go +++ b/pkg/iac/scanners/terraform/executor/executor.go @@ -122,22 +122,8 @@ func (e *Executor) Execute(modules terraform.Modules) (scan.Results, Metrics, er } ignorers := map[string]ignore.Ignorer{ - "ws": func(_ types.Metadata, param any) bool { - ws, ok := param.(string) - if !ok { - return false - } - - return ignore.MatchPattern(e.workspaceName, ws) - }, - "ignore": func(resultMeta types.Metadata, param any) bool { - params, ok := param.(map[string]string) - if !ok { - return false - } - - return ignoreByParams(params, modules, &resultMeta) - }, + "ws": workspaceIgnorer(e.workspaceName), + "ignore": attributeIgnorer(modules), } results.Ignore(ignores, ignorers) @@ -268,3 +254,23 @@ func ignoreByParams(params map[string]string, modules terraform.Modules, m *type } return true } + +func workspaceIgnorer(ws string) ignore.Ignorer { + return func(_ types.Metadata, param any) bool { + ignoredWorkspace, ok := param.(string) + if !ok { + return false + } + return ignore.MatchPattern(ws, ignoredWorkspace) + } +} + +func attributeIgnorer(modules terraform.Modules) ignore.Ignorer { + return func(resultMeta types.Metadata, param any) bool { + params, ok := param.(map[string]string) + if !ok { + return false + } + return ignoreByParams(params, modules, &resultMeta) + } +}