Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lint(pre-commit): add trivy check on modules #135

Merged
merged 2 commits into from
Jan 14, 2025
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
10 changes: 10 additions & 0 deletions .lint/trivy/trivy-scan.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
set -euxo pipefail

# list of the folders that we want to parse, only if a README.md exists and no .trivy_ignore
for dir in $(find modules -type d -maxdepth 1) $(find examples -type d -maxdepth 1); do
if [ -f "$dir/README.md" ] && ! [ -e "$dir/.trivy_ignore" ]; then
echo "Scanning terraform module with trivy: $dir"
trivy config --config .lint/trivy/trivy.yaml --ignorefile .trivyignore "$dir"
fi
done
9 changes: 9 additions & 0 deletions .lint/trivy/trivy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
quiet: false
debug: false
format: table
exit-code: 1

misconfiguration:
scanners:
- terraform
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,12 @@ repos:
rev: 0.2.3
hooks:
- id: yamlfmt

- repo: local
hooks:
- id: trivy-scan
name: Trivy Scan
entry: .lint/trivy/trivy-scan.sh
language: script
types: [terraform]
pass_filenames: false
2 changes: 2 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ terraform-docs 0.19.0
tflint 0.55.0

tfsec 1.28.13

trivy 0.58.1
1 change: 1 addition & 0 deletions .trivyignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
AVD-AWS-0178 #(MEDIUM): VPC does not have VPC Flow Logs enabled.
Empty file added modules/fixtures/.trivy_ignore
Empty file.
Loading