Regression Test - OpenTofu #1
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
name: Regression Test - OpenTofu | |
# Idea: | |
# 1. Setup infrastructure with stable release of the provider in the live environment | |
# 2. Switch to a local build of the provider | |
# 3. Execute a tofu plan and check for deviations | |
# 4. Destroy the infrastructure | |
# 5. If deviation was detected create/update an issue | |
on: | |
workflow_dispatch: | |
env: | |
PATH_TO_TFSCRIPT: 'regression-test' | |
DEV_OVERRIDE: 'assets/provider-config-ghaction.txt' | |
TEMP_PLAN_OUTPUT : 'plan-output.txt' | |
permissions: | |
contents: read | |
issues: write | |
jobs: | |
execute_regression_test: | |
name: Regression Test OpenTofu | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out Git repository | |
id: checkout_repo | |
uses: actions/checkout@v4 | |
- name: Setup OpenTofu | |
id : setup_opentofu | |
uses: opentofu/setup-opentofu@v1 | |
with: | |
tofu_wrapper: false | |
terraform_version: latest | |
- name: Tofu Init with stable provider | |
id: tofu_init | |
shell: bash | |
run: | | |
tofu -chdir=${{ env.PATH_TO_TFSCRIPT }} init -no-color | |
- name: tofu Apply with stable provider | |
id: tofu_apply | |
shell: bash | |
run: | | |
export BTP_USERNAME=${{ secrets.BTP_USERNAME }} | |
export BTP_PASSWORD=${{ secrets.BTP_PASSWORD }} | |
tofu -chdir=${{ env.PATH_TO_TFSCRIPT }} apply -var globalaccount=${{ secrets.GLOBALACCOUNT }} -auto-approve -no-color | |
- name: Setup Go | |
uses: actions/[email protected] | |
with: | |
go-version-file: 'go.mod' | |
- name: Install local Terraform provider | |
id: build_provider | |
shell: bash | |
run: | | |
go mod tidy && make install | |
- name: Remove init data and place override | |
id: set_to_override | |
shell: bash | |
run: | | |
rm -rf .terraform && rm -rf .terraform.lock.hcl && cp ${{ env.DEV_OVERRIDE }} ~/.terraformrc | |
- name: Check for deviations in tofu plan | |
id: execute_deviation_check | |
shell: bash | |
run: | | |
export BTP_USERNAME=${{ secrets.BTP_USERNAME }} | |
export BTP_PASSWORD=${{ secrets.BTP_PASSWORD }} | |
tofu -chdir=${{ env.PATH_TO_TFSCRIPT }} plan -var globalaccount=${{ secrets.GLOBALACCOUNT }} -no-color -detailed-exitcode | |
- name: Remove init data and override | |
if: always() | |
id: remove_override | |
shell: bash | |
run: | | |
rm -rf .terraform && rm -rf .terraform.lock.hcl && rm -rf ~/.terraformrc | |
- name: Tofu Init with stable provider | |
if: always() | |
id: tofu_reinit | |
shell: bash | |
run: | | |
tofu -chdir=${{ env.PATH_TO_TFSCRIPT }} init -upgrade -no-color | |
- name: Tofu Destroy with stable provider | |
if: always() | |
id: tofu_destroy | |
shell: bash | |
run: | | |
export BTP_USERNAME=${{ secrets.BTP_USERNAME }} | |
export BTP_PASSWORD=${{ secrets.BTP_PASSWORD }} | |
tofu -chdir=${{ env.PATH_TO_TFSCRIPT }} destroy -var globalaccount='${{ secrets.GLOBALACCOUNT }}' -auto-approve -no-color | |
- name: State deviation - find existing issue for deviation | |
id: find_deviation_issue | |
uses: micalevisk/last-issue-action@v2 | |
if: ${{ steps.execute_deviation_check.outcome == 'failure' }} | |
with: | |
state: open | |
labels: | | |
state deviation | |
automated issue | |
- name: State deviation - create or update issue | |
uses: peter-evans/create-issue-from-file@v5 | |
if: ${{ steps.execute_deviation_check.outcome == 'failure' }} | |
with: | |
title: State deviation found | |
# If issue number is empty a new issue gets created | |
issue-number: ${{ steps.find_deviation_issue.outputs.issue-number }} | |
content-filepath: ${{ env.TEMP_PLAN_OUTPUT }} | |
labels: state deviation, automated issue | |
- name: Cleanup plan output | |
id: execute_plan_cleanup | |
if: always() | |
shell: bash | |
run: | | |
rm -rf ${{ env.TEMP_PLAN_OUTPUT }} | |
- name: State deviation - Set run to failed | |
if: ${{ steps.execute_deviation_check.outcome == 'failure' }} | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
core.setFailed('A state deviation was detected!') |