Skip to content

Commit

Permalink
chore: add tf validation (#185)
Browse files Browse the repository at this point in the history
* chore: refine fmt

* chore: add terraform validate check
  • Loading branch information
lechnerc77 authored Jun 2, 2024
1 parent 41282e2 commit 28f86ea
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/terraform_format_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ on:
workflow_dispatch:

jobs:
# Retrive the changed directories from the PR
terraform-fmt:
name: Validate format of Terraform files
name: Validate Format of Terraform Files
runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/terraform_validate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Terraform Validation Check

on:
pull_request:
types:
- opened
- reopened
- synchronize
- ready_for_review
workflow_dispatch:

jobs:
terraform-validate:
name: Validate Syntax 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@v44
with:
dir_names: 'true'

- name: Validate Terraform sytnax
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 "Validating Terraform files in $file with terraform fmt"
cd $file
terraform init -backend=false || EXIT_CODE=$?
terraform validate || EXIT_CODE=$?
rm -rf .terraform/
cd ${{ github.workspace }}
done
exit $EXIT_CODE

0 comments on commit 28f86ea

Please sign in to comment.