Skip to content

Add Terraform & OpenTofu End-to-End tests, minor cleanup #2

Add Terraform & OpenTofu End-to-End tests, minor cleanup

Add Terraform & OpenTofu End-to-End tests, minor cleanup #2

Workflow file for this run

name: "Terraform Checks"
defaults:
run:
shell: bash
on:
pull_request:
env:
MODULE_DIRECTORIES: '[".", "./examples/complete/"]' # List of directories to test
TERRAFORM_VERSIONS: '["1.5.6", "1.10.1"]' # Current and latest Terraform
jobs:
# Performs linting and format checks and suggests fixes on PR
terraform-linter:
name: Terraform Linter
runs-on: ubuntu-latest
timeout-minutes: 5
strategy:
matrix:
terraform_version: ${{ fromJson(env.TERRAFORM_VERSIONS) }}

Check failure on line 19 in .github/workflows/tests.yml

View workflow run for this annotation

GitHub Actions / Terraform Checks

Invalid workflow file

The workflow is not valid. .github/workflows/tests.yml (Line: 19, Col: 28): Unrecognized named-value: 'env'. Located at position 10 within expression: fromJson(env.TERRAFORM_VERSIONS) .github/workflows/tests.yml (Line: 19, Col: 28): Unexpected value '${{ fromJson(env.TERRAFORM_VERSIONS) }}'
directory: ${{ fromJson(env.MODULE_DIRECTORIES) }}
fail-fast: false
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
submodules: true
- uses: hashicorp/setup-terraform@v3
with:
terraform_version: "${{ matrix.terraform_version }}"
- name: Terraform init
working-directory: ${{ matrix.directory }}
run: terraform init
- name: Tflint Report Output
uses: reviewdog/[email protected]
with:
working_directory: ${{ matrix.directory }}
github_token: ${{ secrets.GITHUB_TOKEN }}
tflint_version: "v0.49.0" # Version set due to this https://github.com/reviewdog/action-tflint/issues/83
reporter: github-pr-review
fail_on_error: "true"
filter_mode: "added"
flags: "--module" # This option should work until tflint v0.5.1.
# Performs linting and format checks and suggests fixes on PR
terraform-formatter:
name: Terraform Formatter
runs-on: ubuntu-latest
timeout-minutes: 5
strategy:
matrix:
terraform_version: ${{ fromJson(env.TERRAFORM_VERSIONS) }}
directory: ${{ fromJson(env.MODULE_DIRECTORIES) }}
fail-fast: false
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
submodules: true
- uses: hashicorp/setup-terraform@v3
with:
terraform_version: "${{ matrix.terraform_version }}"
- name: Terraform init
working-directory: ${{ matrix.directory }}
run: terraform init
# This step applies format suggestions locally which would be used by a suggester
- name: Terraform Format suggestions
working-directory: ${{ matrix.directory }}
run: terraform fmt
- uses: reviewdog/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
tool_name: "terraform"
fail_on_error: "true"
filter_mode: "added"
test-e2e:
name: E2E Tests
strategy:
max-parallel: 1
matrix:
terraform_version: ${{ fromJson(env.TERRAFORM_VERSIONS) }}
os:
- ubuntu-latest
runs-on: ${{ matrix.os }}
steps:
- name: Configure Environment Variables
run: |
echo "${{ github.workspace }}/bin/" >> $GITHUB_PATH
echo "ENV=${{ github.job }}-$(echo $GITHUB_SHA | cut -c 1-6)" >> $GITHUB_ENV
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.23.x
- name: Run Tests
working-directory: test/
env:
LOCALSTACK_AUTH_TOKEN: ${{ secrets.LOCALSTACK_AUTH_TOKEN }}
run: |
go install github.com/gruntwork-io/terratest/cmd/terratest_log_parser@latest
go mod tidy
go test -v -timeout 60m -coverprofile=coverage-examples-complete.out -race -covermode=atomic | tee test_output.log
terratest_log_parser -testlog test_output.log -outputdir results
- name: Test Summary
uses: test-summary/action@v2
with:
paths: |
test/results/**/*.xml
test/results/*.xml