Skip to content

Add tests for image build not required; Fix example to use platform-c… #606

Add tests for image build not required; Fix example to use platform-c…

Add tests for image build not required; Fix example to use platform-c… #606

name: Terraform Unit Tests
on:
push:
schedule:
- cron: '30 5 * * *'
permissions: read-all
jobs:
find-modules-to-test:
runs-on: ubuntu-latest
outputs:
modules: ${{ steps.find-modules.outputs.modules }}
steps:
- uses: actions/checkout@v4
- name: Find modules
id: find-modules
run: |
unit_test_files=$(find . -name "*tftest.hcl" | grep -v e2e-tests | sort)
modules=""
IFS=$'\n'
for file in $unit_test_files
do
# Lose leading ./ and select the part before the tests directory
module=$(echo "${file#./}" | awk -F "/tests/" '{print $1}')
# In case we separate the test files, only include each module once
if [[ "\"${modules}\"" != *"\"${module}\""* ]]; then
echo "Found module ${module}"
modules+="\"${module}\","
fi
done
echo "modules=[${modules%,}]" >> "$GITHUB_OUTPUT"
terraform-unit-tests:
name: ${{ matrix.module }} tf-${{ matrix.terraform-version }}
runs-on: ubuntu-latest
needs: find-modules-to-test
strategy:
matrix:
terraform-version:
- 1.8
- 1.9
module: ${{ fromJSON(needs.find-modules-to-test.outputs.modules) }}
fail-fast: false
steps:
- uses: actions/checkout@v4
- uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ matrix.terraform-version }}
- run: terraform --version
- name: terraform init
run: |
cd ${{ matrix.module }}
terraform init
- name: terraform test
run: |
cd ${{ matrix.module }}
terraform test