2022-09-20 07:38:22 -04:00
|
|
|
name: Terraform validation
|
|
|
|
|
|
|
|
on:
|
|
|
|
workflow_dispatch:
|
|
|
|
push:
|
|
|
|
branches:
|
|
|
|
- main
|
2022-10-18 10:17:41 -04:00
|
|
|
- "release/**"
|
2022-09-20 07:38:22 -04:00
|
|
|
paths:
|
|
|
|
- "**.tf"
|
|
|
|
pull_request:
|
|
|
|
paths:
|
|
|
|
- "**.tf"
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
tfsec:
|
|
|
|
name: terraform
|
2022-11-10 10:55:24 -05:00
|
|
|
runs-on: ubuntu-22.04
|
2022-09-20 07:38:22 -04:00
|
|
|
steps:
|
|
|
|
- name: Checkout
|
2022-11-17 05:37:00 -05:00
|
|
|
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # tag=v3.1.0
|
2022-09-20 07:38:22 -04:00
|
|
|
with:
|
2022-10-19 04:32:22 -04:00
|
|
|
ref: ${{ github.head_ref }}
|
2022-09-20 07:38:22 -04:00
|
|
|
|
|
|
|
- name: Setup Terraform
|
2022-11-02 06:00:40 -04:00
|
|
|
uses: hashicorp/setup-terraform@633666f66e0061ca3b725c73b2ec20cd13a8fdd1 # tag=v2.0.3
|
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"
|
2022-11-11 08:49:16 -05:00
|
|
|
terraform -chdir="$dir" init || result=1
|
|
|
|
terraform -chdir="$dir" fmt -check=true -diff=true || result=1
|
|
|
|
terraform -chdir="$dir" validate -no-color || result=1
|
2022-09-20 07:38:22 -04:00
|
|
|
done
|
|
|
|
exit $result
|