-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwarnings.go
44 lines (36 loc) · 1.28 KB
/
warnings.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package preview
import (
"fmt"
"github.com/aquasecurity/trivy/pkg/iac/terraform"
"github.com/hashicorp/hcl/v2"
)
func warnings(modules terraform.Modules) hcl.Diagnostics {
var diags hcl.Diagnostics
diags = diags.Extend(unexpandedCountBlocks(modules))
return diags
}
// unexpandedCountBlocks is to compensate for a bug in the trivy parser.
// It is related to https://github.com/aquasecurity/trivy/pull/8479.
// Essentially, submodules are processed once. So if there is interdependent
// submodule references, then
func unexpandedCountBlocks(modules terraform.Modules) hcl.Diagnostics {
var diags hcl.Diagnostics
for _, block := range modules.GetBlocks() {
block := block
if countAttr, ok := block.Attributes()["count"]; ok {
if block.IsExpanded() {
continue
}
diags = append(diags, &hcl.Diagnostic{
Severity: hcl.DiagWarning,
Summary: fmt.Sprintf("Unexpanded count argument on block %q", block.FullName()),
Detail: "The count argument is not expanded. This may lead to unexpected behavior. The default behavior is to assume count is 1.",
Subject: &countAttr.HCLAttribute().Range,
Context: &block.HCLBlock().DefRange,
Expression: countAttr.HCLAttribute().Expr,
EvalContext: block.Context().Inner(),
})
}
}
return diags
}