Skip to content

Commit d7d7265

Browse files
authored
test(terraform): skip cached modules (aquasecurity#6281)
1 parent 6639911 commit d7d7265

File tree

5 files changed

+21
-14
lines changed

5 files changed

+21
-14
lines changed

pkg/iac/scanners/terraform/module_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ variable "group" {
600600
type = string
601601
}
602602
603-
resource aws_iam_group_policy mfa {
603+
resource "aws_iam_group_policy" "mfa" {
604604
group = var.group
605605
policy = data.aws_iam_policy_document.policy.json
606606
}

pkg/iac/scanners/terraform/options.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func ScannerWithDownloadsAllowed(allowed bool) options.ScannerOption {
196196
func ScannerWithSkipCachedModules(b bool) options.ScannerOption {
197197
return func(s options.ConfigurableScanner) {
198198
if tf, ok := s.(ConfigurableTerraformScanner); ok {
199-
tf.AddParserOptions(parser.OptionWithDownloads(b))
199+
tf.AddParserOptions(parser.OptionWithSkipCachedModules(b))
200200
}
201201
}
202202
}

pkg/iac/scanners/terraform/parser/evaluator.go

+13-12
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,19 @@ func newEvaluator(
7373
}
7474

7575
return &evaluator{
76-
filesystem: target,
77-
parentParser: parentParser,
78-
modulePath: modulePath,
79-
moduleName: moduleName,
80-
projectRootPath: projectRootPath,
81-
ctx: ctx,
82-
blocks: blocks,
83-
inputVars: inputVars,
84-
moduleMetadata: moduleMetadata,
85-
ignores: ignores,
86-
debug: logger,
87-
allowDownloads: allowDownloads,
76+
filesystem: target,
77+
parentParser: parentParser,
78+
modulePath: modulePath,
79+
moduleName: moduleName,
80+
projectRootPath: projectRootPath,
81+
ctx: ctx,
82+
blocks: blocks,
83+
inputVars: inputVars,
84+
moduleMetadata: moduleMetadata,
85+
ignores: ignores,
86+
debug: logger,
87+
allowDownloads: allowDownloads,
88+
skipCachedModules: skipCachedModules,
8889
}
8990
}
9091

pkg/iac/scanners/terraform/scanner_integration_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ deny[cause] {
176176
t.Run("with skip", func(t *testing.T) {
177177
scanner := New(
178178
ScannerWithSkipDownloaded(true),
179+
ScannerWithSkipCachedModules(true),
179180
options.ScannerWithPolicyDirs("rules"),
180181
options.ScannerWithRegoOnly(true),
181182
options.ScannerWithEmbeddedPolicies(false),
@@ -229,6 +230,7 @@ deny[res] {
229230

230231
scanner := New(
231232
ScannerWithSkipDownloaded(true),
233+
ScannerWithSkipCachedModules(true),
232234
options.ScannerWithPolicyDirs("rules"),
233235
options.ScannerWithRegoOnly(true),
234236
options.ScannerWithEmbeddedLibraries(true),

pkg/iac/scanners/terraformplan/snapshot/scanner_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/aquasecurity/trivy/pkg/iac/scan"
1313
"github.com/aquasecurity/trivy/pkg/iac/scanners/options"
14+
tfscanner "github.com/aquasecurity/trivy/pkg/iac/scanners/terraform"
1415
"github.com/samber/lo"
1516
"github.com/stretchr/testify/assert"
1617
"github.com/stretchr/testify/require"
@@ -23,6 +24,8 @@ func initScanner(opts ...options.ScannerOption) *Scanner {
2324
options.ScannerWithPolicyNamespaces("user"),
2425
options.ScannerWithPolicyDirs("."),
2526
options.ScannerWithRegoOnly(true),
27+
options.ScannerWithRegoErrorLimits(0),
28+
tfscanner.ScannerWithSkipCachedModules(true),
2629
}
2730

2831
opts = append(opts, defaultOpts...)
@@ -110,6 +113,7 @@ func Test_ScanFS(t *testing.T) {
110113
options.ScannerWithEmbeddedLibraries(false),
111114
options.ScannerWithEmbeddedPolicies(false),
112115
options.ScannerWithRegoErrorLimits(0),
116+
tfscanner.ScannerWithSkipCachedModules(true),
113117
)
114118

115119
results, err := scanner.ScanFS(context.TODO(), fs, path.Join(tc.dir, "tfplan"))

0 commit comments

Comments
 (0)