Test different versions of Terraform (#2399)

Add capability to run tests using terraform version 1.5.7 and OpenTofu. 

Automatic checks are run with  Terraform 1.7.4 and OpenTofu 1.7.2, it should be possible to override terraform version when Tests workflow is run manually.
This commit is contained in:
Wiktor Niesiobędzki
2024-07-05 13:21:41 +02:00
committed by GitHub
parent 45fd48db42
commit afa6e7425c
2 changed files with 99 additions and 18 deletions

View File

@@ -19,26 +19,61 @@ on:
pull_request:
branches:
- master
workflow_dispatch:
inputs:
terraform_version:
description: "Use '1.5.7' to test last MPLv2 Terraform version"
required: true
default: 1.7.4
type: string
env:
GOOGLE_APPLICATION_CREDENTIALS: "/home/runner/credentials.json"
PYTEST_ADDOPTS: "--color=yes"
PYTHON_VERSION: "3.10"
TF_PLUGIN_CACHE_DIR: "/home/runner/.terraform.d/plugin-cache"
TF_VERSION: 1.7.4
TFTEST_COPY: 1
DEFAULT_TERRAFORM_FLAVOUR: terraform
DEFAULT_TERRAFORM_VERSION: ${{ inputs.terraform_version || '1.7.4' }}
DEFAULT_TOFU_VERSION: "1.7.2"
jobs:
compute-matrix:
runs-on: ubuntu-latest
outputs:
DEFAULT_TERRAFORM_FLAVOUR: ${{ env.DEFAULT_TERRAFORM_FLAVOUR }}
DEFAULT_TERRAFORM_VERSION: ${{ env.DEFAULT_TERRAFORM_VERSION }}
DEFAULT_TOFU_VERSION: ${{ env.DEFAULT_TOFU_VERSION }}
steps:
- name: dummy
run: echo
setup-tf-providers:
runs-on: ubuntu-latest
needs:
- compute-matrix
strategy:
matrix:
include:
- flavour: terraform
version: "${{ needs.compute-matrix.outputs.DEFAULT_TERRAFORM_VERSION }}"
- flavour: tofu
version: "${{ needs.compute-matrix.outputs.DEFAULT_TOFU_VERSION }}"
steps:
- uses: actions/checkout@v4
- uses: hashicorp/setup-terraform@v3
if: ${{ matrix.flavour == 'terraform' }}
with:
terraform_version: ${{ env.TF_VERSION }}
terraform_version: ${{ matrix.version }}
terraform_wrapper: false
- uses: opentofu/setup-opentofu@v1
if: ${{ matrix.flavour == 'tofu' }}
with:
tofu_version: ${{ matrix.version }}
tofu_wrapper: false
- name: Build lockfile and fetch providers
shell: bash
run: |
@@ -46,20 +81,24 @@ jobs:
echo 'plugin_cache_dir = "${{ env.TF_PLUGIN_CACHE_DIR }}"' | tee -a /home/runner/.terraformrc
echo 'disable_checkpoint = true' | tee -a /home/runner/.terraformrc
cp default-versions.tf tools/lockfile
sed -i 's/>=\(.*# tftest\)/=\1/g' tools/lockfile/default-versions.tf
sed -i -e 's/>=\(.*# tftest\)/=\1/g' tools/lockfile/default-versions.tf
# change terraform version to the one that is running
sed -i 's/required_version = .*$/required_version = ">= ${{ matrix.version }}"/g' tools/lockfile/default-versions.tf
cd tools/lockfile
terraform init -upgrade=true
${{ matrix.flavour }} init -upgrade=true
- name: Upload Terraform provider cache
uses: actions/cache@v4
with:
path: ${{ env.TF_PLUGIN_CACHE_DIR }}
key: ${{ runner.os }}-terraform-${{ hashFiles('tools/lockfile/.terraform.lock.hcl') }}
key: ${{ runner.os }}-${{ matrix.flavour }}-${{ matrix.version }}-${{ hashFiles('tools/lockfile/.terraform.lock.hcl') }}
- name: Upload lockfile
uses: actions/upload-artifact@v4
with:
name: lockfile
name: lockfile-${{ runner.os }}-${{ matrix.flavour }}-${{ matrix.version }}
path: tools/lockfile/.terraform.lock.hcl
overwrite: true
@@ -74,7 +113,8 @@ jobs:
uses: ./.github/actions/fabric-tests
with:
PYTHON_VERSION: ${{ env.PYTHON_VERSION }}
TERRAFORM_VERSION: ${{ env.TF_VERSION }}
TERRAFORM_VERSION: ${{ env.DEFAULT_TERRAFORM_VERSION }}
TERRAFORM_FLAVOUR: ${{ env.DEFAULT_TERRAFORM_FLAVOUR }}
- name: Run tests on documentation examples
run: pytest -vv -n4 --tb=line --junit-xml=test-results-raw.xml -k blueprints/ tests/examples
@@ -87,7 +127,17 @@ jobs:
examples-modules:
runs-on: ubuntu-latest
needs: setup-tf-providers
needs:
- setup-tf-providers
- compute-matrix
strategy:
matrix:
include:
- flavour: terraform
version: "${{ needs.compute-matrix.outputs.DEFAULT_TERRAFORM_VERSION }}"
- flavour: tofu
version: "${{ needs.compute-matrix.outputs.DEFAULT_TOFU_VERSION }}"
steps:
- uses: actions/checkout@v4
@@ -95,10 +145,13 @@ jobs:
uses: ./.github/actions/fabric-tests
with:
PYTHON_VERSION: ${{ env.PYTHON_VERSION }}
TERRAFORM_VERSION: ${{ env.TF_VERSION }}
TERRAFORM_VERSION: ${{ matrix.version }}
TERRAFORM_FLAVOUR: ${{ matrix.flavour }}
- name: Run tests on documentation examples
run: pytest -vv -n4 --tb=line --junit-xml=test-results-raw.xml -k modules/ tests/examples
env:
TERRAFORM: ${{ matrix.flavour }}
run: pytest -vv ${{ matrix.flavour == 'terraform' && '-n4' || '-n4' }} --tb=line --junit-xml=test-results-raw.xml -k modules/ tests/examples
- name: Create report
uses: ./.github/actions/post-fabric-tests
@@ -116,7 +169,8 @@ jobs:
uses: ./.github/actions/fabric-tests
with:
PYTHON_VERSION: ${{ env.PYTHON_VERSION }}
TERRAFORM_VERSION: ${{ env.TF_VERSION }}
TERRAFORM_VERSION: ${{ env.DEFAULT_TERRAFORM_VERSION }}
TERRAFORM_FLAVOUR: ${{ env.DEFAULT_TERRAFORM_FLAVOUR }}
- name: Run tests environments
run: pytest -vv -n4 --tb=line --junit-xml=test-results-raw.xml tests/blueprints
@@ -129,18 +183,33 @@ jobs:
modules:
runs-on: ubuntu-latest
needs: setup-tf-providers
needs:
- setup-tf-providers
- compute-matrix
strategy:
matrix:
include:
- flavour: terraform
version: "${{ needs.compute-matrix.outputs.DEFAULT_TERRAFORM_VERSION }}"
- flavour: tofu
version: "${{ needs.compute-matrix.outputs.DEFAULT_TOFU_VERSION }}"
steps:
- uses: actions/checkout@v4
- name: Call composite action fabric-tests
uses: ./.github/actions/fabric-tests
env:
TERRAFORM: ${{ matrix.flavour }}
with:
PYTHON_VERSION: ${{ env.PYTHON_VERSION }}
TERRAFORM_VERSION: ${{ env.TF_VERSION }}
TERRAFORM_VERSION: ${{ matrix.version }}
TERRAFORM_FLAVOUR: ${{ matrix.flavour }}
- name: Run tests modules
run: pytest -vv -n4 --tb=line --junit-xml=test-results-raw.xml tests/modules
env:
TERRAFORM: ${{ matrix.flavour }}
run: pytest -vv ${{ matrix.flavour == 'terraform' && '-n4' || '-n4' }} --tb=line --junit-xml=test-results-raw.xml tests/modules
- name: Create report
uses: ./.github/actions/post-fabric-tests
@@ -158,7 +227,8 @@ jobs:
uses: ./.github/actions/fabric-tests
with:
PYTHON_VERSION: ${{ env.PYTHON_VERSION }}
TERRAFORM_VERSION: ${{ env.TF_VERSION }}
TERRAFORM_VERSION: ${{ env.DEFAULT_TERRAFORM_VERSION }}
TERRAFORM_FLAVOUR: ${{ env.DEFAULT_TERRAFORM_FLAVOUR }}
- name: Run tests on FAST stages
run: pytest -vv -n4 --tb=line --junit-xml=test-results-raw.xml tests/fast