-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Bahmni/BAH-1566
BAH - 1566 | Added. terrascan to pre-commit hook
- Loading branch information
Showing
5 changed files
with
39 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
rules: | ||
skip-rules: | ||
- AC_AWS_0480 # Skips validation of detailed monitoring for EC2 Instances |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/bash | ||
|
||
# Terrascan scan and save output to scan_results | ||
scan_results="$(terrascan scan --config-path terrascan/terrascan-config.yaml --iac-type terraform --use-colors t)" | ||
|
||
# Get scan summary from scan_results | ||
scan_summary=$(echo "$scan_results" | sed -n -e '/Scan Summary -/,$p' | sed -r "s/[[:cntrl:]]\[([0-9]{1,3};)*[0-9]{1,3}m//g") | ||
|
||
#Extract values from scan_summary | ||
low_level_violations=$(grep "Low" <<< "$scan_summary" | grep -o -E "[0-9]+") | ||
medium_level_violations=$(grep "Medium" <<< "$scan_summary" | grep -o -E "[0-9]+") | ||
high_level_violations=$(grep "High" <<< "$scan_summary" | grep -o -E "[0-9]+") | ||
|
||
#Show Scan Output | ||
echo "$scan_results" | ||
|
||
#Check for violations | ||
if [[ $high_level_violations -gt 0 ]] | ||
then | ||
echo "High Level Voilations Found" | ||
exit 1 | ||
fi | ||
echo "No Violations found" | ||
exit 0 |