From e4009068aae35a482dbc5abf13eeedbfbf9f7035 Mon Sep 17 00:00:00 2001 From: Christian Lechner Date: Sun, 2 Jun 2024 16:31:21 +0200 Subject: [PATCH] chore: add terraform validate check --- .github/workflows/terraform_validate.yml | 46 ++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .github/workflows/terraform_validate.yml diff --git a/.github/workflows/terraform_validate.yml b/.github/workflows/terraform_validate.yml new file mode 100644 index 00000000..2e85309a --- /dev/null +++ b/.github/workflows/terraform_validate.yml @@ -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 \ No newline at end of file