@@ -9,7 +9,7 @@ set -euo pipefail
99# Run tfsec for security checks on Terraform code.
1010#
1111# Usage:
12- # $ ./tfsec .sh [directory]
12+ # $ ./trivy .sh [directory]
1313# ==============================================================================
1414
1515function main() {
@@ -18,68 +18,63 @@ function main() {
1818
1919 local dir_to_scan=${1:- .}
2020
21- if command -v tfsec > /dev/null 2>&1 && ! is-arg-true " ${FORCE_USE_DOCKER:- false} " ; then
21+ if command -v trivy > /dev/null 2>&1 && ! is-arg-true " ${FORCE_USE_DOCKER:- false} " ; then
2222 # shellcheck disable=SC2154
23- run-tfsec -natively " $dir_to_scan "
23+ run-trivy -natively " $dir_to_scan "
2424 else
25- run-tfsec -in-docker " $dir_to_scan "
25+ run-trivy -in-docker " $dir_to_scan "
2626 fi
2727}
2828
29- # Run tfsec on the specified directory.
29+ # Run trivy on the specified directory.
3030# Arguments:
3131# $1 - Directory to scan
32- function run-tfsec -natively() {
32+ function run-trivy -natively() {
3333
3434 local dir_to_scan=" $1 "
3535
36- echo " TFSec found locally, running natively"
36+ echo " Trivy found locally, running natively"
3737
38- echo " Running TFSec on directory: $dir_to_scan "
39- tfsec \
40- --force-all-dirs \
41- --exclude-downloaded-modules \
42- --config-file scripts/config/tfsec.yaml \
43- --format text \
44- " $dir_to_scan "
38+ echo " Running Trivy on directory: $dir_to_scan "
39+ trivy config \
40+ --config scripts/config/trivy.yaml \
41+ --tf-exclude-downloaded-modules \
42+ " ${dir_to_scan} "
4543
46- check-tfsec -status
44+ check-trivy -status
4745}
4846
4947# Check the exit status of tfsec.
50- function check-tfsec -status() {
48+ function check-trivy -status() {
5149
5250 if [ $? -eq 0 ]; then
53- echo " TFSec completed successfully."
51+ echo " Trivy completed successfully."
5452 else
55- echo " TFSec found issues."
53+ echo " Trivy found issues."
5654 exit 1
5755 fi
5856}
5957
60- function run-tfsec -in-docker() {
58+ function run-trivy -in-docker() {
6159
6260 # shellcheck disable=SC1091
6361 source ./scripts/docker/docker.lib.sh
6462 local dir_to_scan=" $1 "
6563
6664 # shellcheck disable=SC2155
67- local image=$( name=aquasec/tfsec docker-get-image-version-and-pull)
65+ local image=$( name=aquasec/trivy docker-get-image-version-and-pull)
6866 # shellcheck disable=SC2086
69- echo " TFSec not found locally, running in Docker Container"
70- echo " Running TFSec on directory: $dir_to_scan "
67+ echo " Trivy not found locally, running in Docker Container"
68+ echo " Running Trivy on directory: $dir_to_scan "
7169 docker run --rm --platform linux/amd64 \
7270 --volume " $PWD " :/workdir \
7371 --workdir /workdir \
7472 " $image " \
75- --concise-output \
76- --force-all-dirs \
77- --exclude-downloaded-modules \
78- --config-file scripts/config/tfsec.yaml \
79- --format text \
80- --soft-fail \
81- " $dir_to_scan "
82- check-tfsec-status
73+ config \
74+ --config scripts/config/trivy.yaml \
75+ --tf-exclude-downloaded-modules \
76+ " ${dir_to_scan} "
77+ check-trivy-status
8378}
8479# ==============================================================================
8580
0 commit comments