OOP for project writers #110
This file contains hidden or 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
| name: Terraform Check | |
| on: | |
| pull_request: | |
| types: [ opened, synchronize, reopened ] | |
| push: | |
| branches: [ master ] | |
| workflow_dispatch: | |
| concurrency: | |
| group: static-terraform-check-${{ github.ref }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: read | |
| security-events: write | |
| jobs: | |
| detect: | |
| name: Terraform Changes Detection | |
| runs-on: ubuntu-latest | |
| outputs: | |
| terraform_changed: ${{ steps.changes.outputs.terraform_changed }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v5 | |
| with: | |
| persist-credentials: false | |
| fetch-depth: 0 | |
| - name: Check if terraform/ changed | |
| id: changes | |
| shell: bash | |
| run: | | |
| if [[ "${{ github.event_name }}" == "pull_request" ]]; then | |
| RANGE="${{ github.event.pull_request.base.sha }}...${{ github.sha }}" | |
| else | |
| RANGE="${{ github.sha }}~1...${{ github.sha }}" | |
| fi | |
| if git diff --name-only "$RANGE" | grep -qE '^terraform/'; then | |
| echo "terraform_changed=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "terraform_changed=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| tflint: | |
| name: TFLint Static Code Analysis | |
| needs: detect | |
| if: needs.detect.outputs.terraform_changed == 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v5 | |
| with: | |
| persist-credentials: false | |
| fetch-depth: 0 | |
| - name: Setup TFLint | |
| uses: terraform-linters/setup-tflint@v6 | |
| with: | |
| tflint_version: latest | |
| - name: TFLint init | |
| working-directory: terraform | |
| run: tflint --init | |
| - name: Run TFLint | |
| working-directory: terraform | |
| run: tflint --minimum-failure-severity=error -f sarif > "$GITHUB_WORKSPACE/tflint_terraform.sarif" | |
| - name: Upload TFLint SARIF file | |
| uses: github/codeql-action/upload-sarif@v4 | |
| with: | |
| sarif_file: ${{ github.workspace }}/tflint_terraform.sarif | |
| # TODO: Trivy scan for changed Terraform files will be enabled in the upcoming issue: https://github.com/AbsaOSS/EventGate/issues/74 | |
| # trivy-terraform: | |
| # name: Trivy Security Scan | |
| # needs: detect | |
| # if: needs.detect.outputs.terraform_changed == 'true' | |
| # runs-on: ubuntu-latest | |
| # steps: | |
| # - name: Checkout repository | |
| # uses: actions/checkout@v5 | |
| # with: | |
| # persist-credentials: false | |
| # fetch-depth: 0 | |
| # | |
| # - name: Setup Trivy | |
| # uses: aquasecurity/[email protected] | |
| # | |
| # - name: Trivy security scan | |
| # run: | | |
| # trivy fs terraform/ \ | |
| # --format sarif \ | |
| # --output $GITHUB_WORKSPACE/trivy_terraform.sarif | |
| # | |
| # - name: Upload Terraform SARIF | |
| # uses: github/codeql-action/upload-sarif@v4 | |
| # with: | |
| # sarif_file: ${{ github.workspace }}/trivy_terraform.sarif | |
| noop: | |
| name: No Operation | |
| needs: detect | |
| if: needs.detect.outputs.terraform_changed != 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - run: echo "No changes under terraform/ — passing." |