Skip to content

Next release

Next release #37

Workflow file for this run

name: Validate terraform modules
on:
push:
branches:
- main
paths:
- "terraform/modules/**"
- ".github/workflows/validate-tf.yml"
pull_request:
paths:
- "terraform/modules/**"
- ".github/workflows/validate-tf.yml"
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
jobs:
get-tf-modules:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- id: get-tf-modules
name: "Build TF modules matrix"
run: |
modules=$(ls -d */ | sed 's#/##' | jq -R -s -c 'split("\n") | map(select(length > 0))')
echo "modules=$modules" >> $GITHUB_OUTPUT
working-directory: "terraform/modules/"
outputs:
modules: ${{ steps.get-tf-modules.outputs.modules }}
validate-tf-modules:
name: Terraform
needs: get-tf-modules
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
modules: ${{ fromJson(needs.get-tf-modules.outputs.modules) }}
defaults:
run:
working-directory: "terraform/modules/${{ matrix.modules }}"
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_wrapper: false
terraform_version: latest
- name: Terraform Version
run: terraform version
- name: Terraform Format
run: terraform fmt -check
- name: Terraform Init
run: terraform init
- name: Terraform Validate
run: terraform validate
- name: Terraform Test
run: |
OUTPUT=$(terraform test -verbose)
echo "$OUTPUT"
if [[ "$OUTPUT" == *"0 passed"* ]]; then
echo "::warning::No unit test for ${{ matrix.modules }}."
fi
- name: Check terraform with Checkov
id: checkov
uses: using-system/devops/github/actions/checkov@main
with:
working-directory: "terraform/modules/${{ matrix.modules }}"