Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 71 additions & 11 deletions .github/workflows/terraform.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: "Terraform checks"

on:
push:
branches:
Expand All @@ -20,6 +21,8 @@ env:
modules/ami-housekeeper
modules/compute-providers/aws/ec2
modules/compute-providers/aws/ec2/trust-policy
modules/compute-providers/aws/microvm
modules/compute-providers/aws/microvm/trust-policy
modules/download-lambda
modules/lambda
modules/multi-runner
Expand Down Expand Up @@ -53,11 +56,15 @@ env:
TEST_MODULES: |
modules/runners
modules/multi-runner
modules/compute-providers/aws/microvm
modules/compute-providers/aws/microvm/trust-policy

jobs:
verify_modules:
name: Verify modules (${{ matrix.iac.name }} ${{ matrix.iac.version }})
strategy:
fail-fast: false
fail-fast: true
max-parallel: 1
matrix:
iac:
- name: terraform
Expand All @@ -72,7 +79,9 @@ jobs:
- name: tofu-latest
version: latest
command: tofu

runs-on: ubuntu-latest

steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1
Expand All @@ -97,7 +106,7 @@ jobs:
mkdir -p "$HOME/.terraform.d/plugin"
echo "TF_PLUGIN_CACHE_DIR=$HOME/.terraform.d/plugin" >> "$GITHUB_ENV"

- name: "Fake zip files" # Validate will fail if it cannot find the zip files
- name: Fake zip files
run: |
touch lambdas/functions/webhook/webhook.zip
touch lambdas/functions/control-plane/runners.zip
Expand Down Expand Up @@ -125,7 +134,10 @@ jobs:
run: |
printf '%s\n' "${MODULES}" | while IFS= read -r module; do
[ -z "${module}" ] && continue

echo "::group::Running $IAC_COMMAND init for module: ${module}"
$IAC_COMMAND -chdir="${module}" init -get -backend=false -input=false
echo "::endgroup::"
done

- name: Check ${{ matrix.iac.name }} formatting
Expand All @@ -134,7 +146,10 @@ jobs:
run: |
printf '%s\n' "${MODULES}" | while IFS= read -r module; do
[ -z "${module}" ] && continue

echo "::group::Checking $IAC_COMMAND formatting for module: ${module}"
$IAC_COMMAND -chdir="${module}" fmt -recursive -check=true -write=false
echo "::endgroup::"
done
continue-on-error: ${{ matrix.iac.version == 'latest' }}

Expand All @@ -144,7 +159,10 @@ jobs:
run: |
printf '%s\n' "${MODULES}" | while IFS= read -r module; do
[ -z "${module}" ] && continue

echo "::group::Validating module: ${module}"
$IAC_COMMAND -chdir="${module}" validate
echo "::endgroup::"
done

- uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
Expand All @@ -161,15 +179,23 @@ jobs:
- name: Run TFLint
run: |
tflint --init -c ${GITHUB_WORKSPACE}/.tflint.hcl

printf '%s\n' "${MODULES}" | while IFS= read -r module; do
[ -z "${module}" ] && continue
tflint -f compact -c ${GITHUB_WORKSPACE}/.tflint.hcl --var-file ${GITHUB_WORKSPACE}/.github/lint/tflint.tfvars --chdir "${module}"

echo "::group::Running TFLint for module: ${module}"
tflint -f compact \
-c ${GITHUB_WORKSPACE}/.tflint.hcl \
--var-file ${GITHUB_WORKSPACE}/.github/lint/tflint.tfvars \
--chdir "${module}"
echo "::endgroup::"
done

verify_examples:
name: Verify examples (${{ matrix.iac.name }} ${{ matrix.iac.version }})
strategy:
fail-fast: false
fail-fast: true
max-parallel: 1
matrix:
iac:
- name: terraform
Expand All @@ -188,7 +214,9 @@ jobs:
version: latest
command: tofu
lockfile: .terraform.lock.hcl.tofu

runs-on: ubuntu-latest

steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1
Expand Down Expand Up @@ -234,7 +262,11 @@ jobs:
run: |
printf '%s\n' "${EXAMPLES}" | while IFS= read -r example; do
[ -z "${example}" ] && continue
cp "examples/${example}/${IAC_LOCK_FILE}" "examples/${example}/.terraform.lock.hcl"

echo "::group::Selecting lockfile for example: ${example}"
cp "examples/${example}/${IAC_LOCK_FILE}" \
"examples/${example}/.terraform.lock.hcl"
echo "::endgroup::"
done

- name: ${{ matrix.iac.name }} init
Expand All @@ -243,7 +275,11 @@ jobs:
run: |
printf '%s\n' "${EXAMPLES}" | while IFS= read -r example; do
[ -z "${example}" ] && continue
$IAC_COMMAND -chdir="examples/${example}" init -get -backend=false -input=false -lockfile=readonly

echo "::group::Running $IAC_COMMAND init for example: ${example}"
$IAC_COMMAND -chdir="examples/${example}" init \
-get -backend=false -input=false -lockfile=readonly
echo "::endgroup::"
done

- name: Check ${{ matrix.iac.name }} formatting
Expand All @@ -252,7 +288,11 @@ jobs:
run: |
printf '%s\n' "${EXAMPLES}" | while IFS= read -r example; do
[ -z "${example}" ] && continue
$IAC_COMMAND -chdir="examples/${example}" fmt -recursive -check=true -write=false

echo "::group::Checking $IAC_COMMAND formatting for example: ${example}"
$IAC_COMMAND -chdir="examples/${example}" fmt \
-recursive -check=true -write=false
echo "::endgroup::"
done
continue-on-error: ${{ matrix.iac.version == 'latest' }}

Expand All @@ -262,7 +302,10 @@ jobs:
run: |
printf '%s\n' "${EXAMPLES}" | while IFS= read -r example; do
[ -z "${example}" ] && continue

echo "::group::Validating example: ${example}"
$IAC_COMMAND -chdir="examples/${example}" validate
echo "::endgroup::"
done

- uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
Expand All @@ -279,15 +322,23 @@ jobs:
- name: Run TFLint
run: |
tflint --init -c ${GITHUB_WORKSPACE}/.tflint.hcl

printf '%s\n' "${EXAMPLES}" | while IFS= read -r example; do
[ -z "${example}" ] && continue
tflint -f compact -c ${GITHUB_WORKSPACE}/.tflint.hcl --var-file ${GITHUB_WORKSPACE}/.github/lint/tflint.tfvars --chdir "examples/${example}"

echo "::group::Running TFLint for example: ${example}"
tflint -f compact \
-c ${GITHUB_WORKSPACE}/.tflint.hcl \
--var-file ${GITHUB_WORKSPACE}/.github/lint/tflint.tfvars \
--chdir "examples/${example}"
echo "::endgroup::"
done

terraform_test:
name: ${{ matrix.iac.name }} test
strategy:
fail-fast: false
fail-fast: true
max-parallel: 1
matrix:
iac:
- name: terraform
Expand All @@ -296,7 +347,9 @@ jobs:
- name: tofu
version: latest
command: tofu

runs-on: ubuntu-latest

steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1
Expand Down Expand Up @@ -341,7 +394,11 @@ jobs:
run: |
printf '%s\n' "${TEST_MODULES}" | while IFS= read -r module; do
[ -z "${module}" ] && continue
$IAC_COMMAND -chdir="${module}" init -backend=false -input=false

echo "::group::Running $IAC_COMMAND init for test module: ${module}"
$IAC_COMMAND -chdir="${module}" init \
-backend=false -input=false
echo "::endgroup::"
done

- name: ${{ matrix.iac.name }} test
Expand All @@ -350,5 +407,8 @@ jobs:
run: |
printf '%s\n' "${TEST_MODULES}" | while IFS= read -r module; do
[ -z "${module}" ] && continue
$IAC_COMMAND -chdir="${module}" test -test-directory=tests

echo "::group::Running $IAC_COMMAND test for module: ${module}"
$IAC_COMMAND -chdir="${module}" test -test-directory=tests -compact-warnings
echo "::endgroup::"
done
Loading
Loading