|
| 1 | +name: Terraform Security Scan |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: [main] |
| 6 | + paths: |
| 7 | + - 'infrastructure/terraform/**' |
| 8 | + push: |
| 9 | + branches: [main] |
| 10 | + paths: |
| 11 | + - 'infrastructure/terraform/**' |
| 12 | + workflow_dispatch: |
| 13 | + |
| 14 | +# Cancel any previous in-progress run for the same ref so superseded |
| 15 | +# commits on a PR don't waste runner minutes. |
| 16 | +concurrency: |
| 17 | + group: terraform-scan-${{ github.ref }} |
| 18 | + cancel-in-progress: true |
| 19 | + |
| 20 | +permissions: |
| 21 | + contents: read |
| 22 | + |
| 23 | +env: |
| 24 | + TF_WORKING_DIR: infrastructure/terraform |
| 25 | + |
| 26 | +jobs: |
| 27 | + # ------------------------------------------------------------------------- |
| 28 | + # tfsec – static analysis of Terraform templates for security |
| 29 | + # misconfigurations. Reads .tfsec.yml from the working directory to |
| 30 | + # determine minimum severity (HIGH / CRITICAL). |
| 31 | + # ------------------------------------------------------------------------- |
| 32 | + tfsec: |
| 33 | + name: tfsec |
| 34 | + runs-on: ubuntu-latest |
| 35 | + |
| 36 | + steps: |
| 37 | + - name: Checkout |
| 38 | + uses: actions/checkout@v4 |
| 39 | + |
| 40 | + - name: Run tfsec |
| 41 | + uses: aquasecurity/tfsec-action@v1.0.3 |
| 42 | + with: |
| 43 | + working_directory: ${{ env.TF_WORKING_DIR }} |
| 44 | + # soft_fail: false causes the step to exit with code 1 (and fail the |
| 45 | + # job) when any finding at or above the configured severity exists. |
| 46 | + soft_fail: false |
| 47 | + format: table |
| 48 | + |
| 49 | + # ------------------------------------------------------------------------- |
| 50 | + # checkov – comprehensive policy-as-code scanner covering CIS benchmarks, |
| 51 | + # HIPAA, GDPR, and hundreds of built-in Terraform / K8s rules. |
| 52 | + # ------------------------------------------------------------------------- |
| 53 | + checkov: |
| 54 | + name: checkov |
| 55 | + runs-on: ubuntu-latest |
| 56 | + |
| 57 | + steps: |
| 58 | + - name: Checkout |
| 59 | + uses: actions/checkout@v4 |
| 60 | + |
| 61 | + - name: Run checkov |
| 62 | + uses: bridgecrewio/checkov-action@v12 |
| 63 | + with: |
| 64 | + directory: ${{ env.TF_WORKING_DIR }} |
| 65 | + framework: terraform |
| 66 | + # soft_fail: false causes the step to exit with code 1 when |
| 67 | + # checkov finds any FAILED evaluation (skipped / passed checks |
| 68 | + # do not affect the exit code). |
| 69 | + soft_fail: false |
| 70 | + # Use CLI output for a human-readable scan summary in the action log. |
| 71 | + output_format: cli |
0 commit comments