Skip to content

Commit 8935c09

Browse files
committed
updated terraform scan
1 parent 6ca2378 commit 8935c09

File tree

1 file changed

+26
-38
lines changed

1 file changed

+26
-38
lines changed
Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Azure Terraform Security Scan
1+
name: Azure Infrastructure Security Scan
22

33
on:
44
push:
@@ -9,21 +9,16 @@ on:
99
paths:
1010
- '**.tf'
1111
- '.github/workflows/terraform-scan.yml'
12-
workflow_dispatch: # Allow manual triggering
12+
workflow_dispatch:
1313

1414
jobs:
1515
security-scan:
16-
name: Azure Terraform Security Scan
16+
name: Terrascan Security Analysis
1717
runs-on: ubuntu-latest
1818
steps:
1919
- name: Checkout repository
2020
uses: actions/checkout@v4
2121

22-
- name: Setup Terraform
23-
uses: hashicorp/setup-terraform@v3
24-
with:
25-
terraform_version: "1.6.0"
26-
2722
- name: Install Terrascan
2823
run: |
2924
TERRASCAN_VERSION=$(curl -s https://api.github.com/repos/tenable/terrascan/releases/latest | jq -r '.tag_name')
@@ -34,28 +29,18 @@ jobs:
3429
sudo install terrascan /usr/local/bin
3530
rm terrascan
3631
37-
- name: Initialize Terraform
38-
run: terraform init -backend=false
39-
40-
- name: Run Terrascan for Azure
41-
id: terrascan
32+
- name: Run Terrascan
4233
run: |
43-
# Create scan config file for Azure
34+
# Create scan config file
4435
cat > config.toml << EOF
45-
[rules]
46-
skip-rules = [
47-
"AC_AZURE_0356", # Skip rule for public network access as we're using firewall rules
48-
"AC_AZURE_0185" # Skip rule for default virtual network as we're defining custom ones
49-
]
50-
5136
[severity]
5237
level = "HIGH"
5338
5439
[notifications]
5540
webhook = false
5641
EOF
5742
58-
# Run scan with Azure-specific configuration
43+
# Run scan for Azure infrastructure
5944
terrascan scan \
6045
--config config.toml \
6146
-t azure \
@@ -74,44 +59,47 @@ jobs:
7459
-o human | tee terrascan-human.txt
7560
continue-on-error: true
7661

77-
- name: Run Azure Policy Compliance Check
78-
run: |
79-
terraform show -json | jq . > plan.json
80-
# Add Azure policy compliance check here if needed
81-
8262
- name: Parse Results
8363
id: parse
8464
run: |
65+
# Count violations by severity
8566
HIGH_COUNT=$(jq -r '.results.violations | map(select(.severity == "HIGH")) | length' terrascan-results.json || echo "0")
8667
MEDIUM_COUNT=$(jq -r '.results.violations | map(select(.severity == "MEDIUM")) | length' terrascan-results.json || echo "0")
68+
69+
# Set environment variables
8770
echo "high_severity_count=${HIGH_COUNT}" >> $GITHUB_ENV
8871
echo "medium_severity_count=${MEDIUM_COUNT}" >> $GITHUB_ENV
8972
90-
echo "Summary of Azure Security Findings:"
91-
echo "High severity issues: ${HIGH_COUNT}"
92-
echo "Medium severity issues: ${MEDIUM_COUNT}"
73+
# Generate detailed report
74+
echo "Security Scan Summary:" > scan-report.txt
75+
echo "===================" >> scan-report.txt
76+
echo "High severity issues: ${HIGH_COUNT}" >> scan-report.txt
77+
echo "Medium severity issues: ${MEDIUM_COUNT}" >> scan-report.txt
78+
echo "" >> scan-report.txt
79+
80+
# Extract detailed violations
81+
echo "High Severity Violations:" >> scan-report.txt
82+
jq -r '.results.violations[] | select(.severity == "HIGH") | "Rule: \(.rule_id)\nResource: \(.resource_name)\nDescription: \(.description)\n"' terrascan-results.json >> scan-report.txt
9383
94-
# Extract specific Azure-related violations
95-
jq -r '.results.violations[] | select(.severity == "HIGH") | "Rule: \(.rule_id)\nDescription: \(.description)\n"' terrascan-results.json > azure-high-severity.txt
84+
cat scan-report.txt
9685
9786
- name: Upload Results
9887
uses: actions/upload-artifact@v4
9988
if: always()
10089
with:
101-
name: azure-terraform-scan-results
90+
name: azure-security-scan
10291
path: |
10392
terrascan-results.json
10493
terrascan-human.txt
105-
azure-high-severity.txt
106-
plan.json
94+
scan-report.txt
10795
108-
- name: Check Results and Apply Azure-Specific Policies
96+
- name: Check Results
10997
run: |
11098
if [ "${{ env.high_severity_count }}" -gt 0 ]; then
111-
echo "::error::Found ${{ env.high_severity_count }} high severity Azure security issues!"
112-
cat azure-high-severity.txt
99+
echo "::error::Found ${{ env.high_severity_count }} high severity security issues!"
100+
cat scan-report.txt
113101
exit 1
114102
fi
115103
if [ "${{ env.medium_severity_count }}" -gt 5 ]; then
116-
echo "::warning::Found more than 5 medium severity Azure security issues"
104+
echo "::warning::Found more than 5 medium severity issues. Review scan-report.txt for details."
117105
fi

0 commit comments

Comments
 (0)