[WIP] feat(garm): add PostgreSQL backend via postgresql relation #99
This file contains hidden or 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
| # Copyright 2025 Canonical Ltd. | |
| # See LICENSE file for licensing details. | |
| name: Terraform module tests (garm-configurator) | |
| on: | |
| pull_request: | |
| permissions: | |
| contents: read | |
| jobs: | |
| detect-changes: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| terraform: ${{ steps.filter.outputs.terraform }} | |
| steps: | |
| - uses: actions/checkout@v6.0.2 | |
| - uses: dorny/paths-filter@v4 | |
| id: filter | |
| with: | |
| filters: | | |
| terraform: | |
| - "**/terraform/**" | |
| - ".github/workflows/test_terraform_garm_configurator_module.yaml" | |
| test-terraform: | |
| needs: detect-changes | |
| if: needs.detect-changes.outputs.terraform == 'true' | |
| name: Test Terraform with Juju | |
| runs-on: self-hosted-linux-amd64-noble-edge | |
| env: | |
| WORKING_DIR: "charms/garm-configurator/terraform/tests" | |
| steps: | |
| - uses: actions/checkout@v6.0.2 | |
| - uses: charmed-kubernetes/actions-operator@main | |
| with: | |
| provider: "microk8s" | |
| channel: 1.34-strict/stable | |
| juju-channel: 3.6/stable | |
| - name: Prepare juju tf provider environment | |
| run: | | |
| set -e | |
| CONTROLLER=$(juju whoami | yq .Controller) | |
| JUJU_CONTROLLER_ADDRESSES="$(juju show-controller | yq '.[$CONTROLLER]'.details.\"api-endpoints\" | tr -d "[]' "|tr -d '"'|tr -d '\n')" | |
| JUJU_USERNAME="$(cat ~/.local/share/juju/accounts.yaml | yq .controllers.$CONTROLLER.user|tr -d '"')" | |
| JUJU_PASSWORD="$(cat ~/.local/share/juju/accounts.yaml | yq .controllers.$CONTROLLER.password|tr -d '"')" | |
| echo "JUJU_CONTROLLER_ADDRESSES=$JUJU_CONTROLLER_ADDRESSES" >> "$GITHUB_ENV" | |
| echo "JUJU_USERNAME=$JUJU_USERNAME" >> "$GITHUB_ENV" | |
| echo "JUJU_PASSWORD=$JUJU_PASSWORD" >> "$GITHUB_ENV" | |
| { | |
| echo 'JUJU_CA_CERT<<EOF' | |
| juju show-controller $(echo $CONTROLLER|tr -d '"') | yq '.[$CONTROLLER]'.details.\"ca-cert\"|tr -d '"' | |
| echo EOF | |
| } >> "$GITHUB_ENV" | |
| - run: juju add-model stg-deploy-garm-configurator | |
| - uses: hashicorp/setup-terraform@v4.0.1 | |
| - run: terraform init | |
| working-directory: ${{env.WORKING_DIR}} | |
| - run: terraform validate | |
| working-directory: ${{env.WORKING_DIR}} | |
| - run: terraform plan -out=tfplan | |
| working-directory: ${{env.WORKING_DIR}} | |
| - run: terraform show tfplan | |
| working-directory: ${{env.WORKING_DIR}} | |
| - run: terraform test | |
| working-directory: ${{env.WORKING_DIR}} | |
| terraform-status-check: | |
| runs-on: ubuntu-latest | |
| needs: [detect-changes, test-terraform] | |
| if: always() | |
| steps: | |
| - name: Check terraform test results | |
| run: | | |
| # If tests were skipped because no changes, that's success | |
| if [ "${{ needs.detect-changes.outputs.terraform }}" != "true" ]; then | |
| echo "No terraform changes detected, skipping tests is expected" | |
| exit 0 | |
| fi | |
| # If tests ran, check their results | |
| test_result="${{ needs.test-terraform.result }}" | |
| echo "Terraform test result: $test_result" | |
| # Fail if test that ran actually failed (not skipped) | |
| if [ "$test_result" = "failure" ]; then | |
| echo "Terraform tests failed" | |
| exit 1 | |
| fi | |
| echo "Terraform tests passed or were skipped appropriately" | |
| exit 0 |