-
Notifications
You must be signed in to change notification settings - Fork 28
43 lines (38 loc) · 1.2 KB
/
terraform_format_check.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
name: Terraform Format Check
on:
pull_request:
types:
- opened
- reopened
- synchronize
- ready_for_review
workflow_dispatch:
jobs:
terraform-fmt:
name: Validate Format of Terraform Files
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_wrapper: false
- name: Get changed directories
id: changed-files
uses: tj-actions/changed-files@v45
with:
dir_names: 'true'
- name: Validate Terraform format
if: steps.changed-files.outputs.any_changed == 'true'
env:
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
shell: bash
run: |
EXIT_CODE=0
for file in ${ALL_CHANGED_FILES}; do
echo "Checking format of $file with terraform fmt"
terraform fmt -check -recursive "$file" || EXIT_CODE=$?
echo "Result is $EXIT_CODE"
done
exit $EXIT_CODE