diff --git a/.github/actions/fabric-tests/action.yml b/.github/actions/fabric-tests/action.yml index aaf8290941..a25438da81 100644 --- a/.github/actions/fabric-tests/action.yml +++ b/.github/actions/fabric-tests/action.yml @@ -19,6 +19,8 @@ inputs: required: true TERRAFORM_VERSION: required: true + TERRAFORM_FLAVOUR: + required: true runs: using: composite steps: @@ -33,11 +35,20 @@ runs: python-version: ${{ inputs.PYTHON_VERSION }} cache: 'pip' cache-dependency-path: 'tests/requirements.txt' + - name: Set up Terraform uses: hashicorp/setup-terraform@v3 + if: ${{ inputs.TERRAFORM_FLAVOUR == 'terraform' }} with: terraform_version: ${{ inputs.TERRAFORM_VERSION }} terraform_wrapper: false + + - uses: opentofu/setup-opentofu@v1 + if: ${{ inputs.TERRAFORM_FLAVOUR == 'tofu' }} + with: + tofu_version: ${{ inputs.TERRAFORM_VERSION }} + tofu_wrapper: false + - name: Configure provider cache shell: bash run: | @@ -49,19 +60,19 @@ runs: - name: Download lockfile uses: actions/download-artifact@v4 with: - name: lockfile + name: lockfile-${{ runner.os }}-${{ inputs.TERRAFORM_FLAVOUR }}-${{ inputs.TERRAFORM_VERSION }} path: tools/lockfile - name: Download 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 }}-${{ inputs.TERRAFORM_FLAVOUR }}-${{ inputs.TERRAFORM_VERSION }}-${{ hashFiles('tools/lockfile/.terraform.lock.hcl') }} # avoid conflicts with user-installed providers on local machines - name: Pin provider versions shell: bash run: | for f in $(find . -name versions.tf); do - sed -i 's/>=\(.*# tftest\)/=\1/g' $f; + sed -i -e 's/>=\(.*# tftest\)/=\1/g' -e 's/required_version = .*$/required_version = ">= ${{ inputs.TERRAFORM_VERSION }}"/g' $f; done - name: Install Python Dependencies shell: bash diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 379eca5528..3ba2ac0a40 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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