-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add terraform test GitHub Action (and make tests pass) (#254)
- Loading branch information
1 parent
13e0572
commit 9b5de3f
Showing
20 changed files
with
351 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
mock_provider "aws" {} | ||
|
||
variables { | ||
config = { | ||
"source_bucket_arn" = "test-source-bucket-arn" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.