Skip to content

feat: add terraform static #1

feat: add terraform static

feat: add terraform static #1

name: CI
on:
pull_request:
permissions:
contents: read
jobs:
terraform-trivy:
name: Trivy Scan
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: Scan
uses: aquasecurity/[email protected]
with:
exit-code: 1
scan-ref: "."
scan-type: "config" # scan terraform
severity: "CRITICAL"
format: 'table'
ignore-unfixed: true
terraform-checkov:
name: Checkov Scan
permissions:
contents: read
actions: read
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Checkov Scan
uses: bridgecrewio/checkov-action@v12
with:
output_format: cli
quiet: true # display only failed checks
download_external_modules: true # downloads and checks external modules
check-changed-files:
runs-on: ubuntu-latest
name: Checking Modified Files
steps:
- uses: actions/checkout@v4
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v45
- name: List all changed files
id: list-changed-files
env:
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
# Loop though files, get terraform files and reformat for tflint
run: |
echo "### Modified files:" >> $GITHUB_STEP_SUMMARY
export tf_files=""
export tf_files_filtered=""
for file in ${ALL_CHANGED_FILES}; do
echo "$file" >> $GITHUB_STEP_SUMMARY
if echo "$file" | grep -q ".*\.tf$" ; then
tf_files+="${file} "
tf_files_filtered+="--filter=${file} "
fi
done
echo "tf_files=$tf_files" >> $GITHUB_OUTPUT
echo "tf_files_filtered=$tf_files_filtered" >> $GITHUB_OUTPUT
outputs:
tf_files: ${{ steps.list-changed-files.outputs.tf_files }}
tf_files_filtered: ${{ steps.list-changed-files.outputs.tf_files_filtered }}
terraform-fmt:
name: Format Terraform
if: ${{ needs.check-changed-files.outputs.tf_files != '' }}
needs:
- check-changed-files
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./
steps:
- uses: actions/checkout@v4
- run: terraform fmt -check -no-color -recursive ${{ needs.check-changed-files.outputs.tf_files }}
- if: failure()
name: Output to summary
run: |
echo "### Failing files:" >> $GITHUB_STEP_SUMMARY
terraform fmt -check -no-color -recursive ${{ needs.check-changed-files.outputs.tf_files }} | tee -a $GITHUB_STEP_SUMMARY
terraform-lint:
name: Lint Terraform
if: ${{ needs.check-changed-files.outputs.tf_files_filtered != '' }}
needs:
- check-changed-files
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v4
name: Cache plugin dir
with:
path: ~/.tflint.d/plugins
key: tflint-${{ hashFiles('.tflint.hcl') }}
- uses: terraform-linters/setup-tflint@v4
- run: tflint --init --recursive --config=$(realpath .tflint.hcl)
- run: tflint --recursive --config=$(realpath .tflint.hcl) ${{ needs.check-changed-files.outputs.tf_files_filtered }}