2022-09-20 07:38:22 -04:00
|
|
|
name: Terraform validation
|
|
|
|
|
|
|
|
on:
|
|
|
|
workflow_dispatch:
|
|
|
|
push:
|
|
|
|
branches:
|
|
|
|
- main
|
|
|
|
paths:
|
|
|
|
- "**.tf"
|
|
|
|
pull_request:
|
|
|
|
paths:
|
|
|
|
- "**.tf"
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
tfsec:
|
|
|
|
name: terraform
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
- name: Checkout
|
2022-10-13 10:54:43 -04:00
|
|
|
uses: actions/checkout@8230315d06ad95c617244d2f265d237a1682d445
|
2022-09-20 07:38:22 -04:00
|
|
|
with:
|
|
|
|
ref: ${{ github.event.pull_request.head.sha }}
|
|
|
|
|
|
|
|
- name: Setup Terraform
|
2022-10-13 11:34:28 -04:00
|
|
|
uses: hashicorp/setup-terraform@a2a0e9d877cffca80feedfc0d9072834be6c42e7
|
2022-09-20 07:38:22 -04:00
|
|
|
|
|
|
|
- name: Terraform format and validate
|
|
|
|
shell: bash
|
|
|
|
run: |
|
|
|
|
dirs=$(find . -type f -name "*.tf" -exec dirname "{}" \; | sort -ud)
|
|
|
|
result=0
|
|
|
|
for dir in $dirs; do
|
|
|
|
echo "Checking $dir"
|
|
|
|
terraform -chdir=$dir init || result=1
|
|
|
|
terraform -chdir=$dir fmt -check=true -diff=true || result=1
|
|
|
|
terraform -chdir=$dir validate -no-color || result=1
|
|
|
|
done
|
|
|
|
exit $result
|