feat: add terraform module for webhook gateway #7
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 (webhook-gateway) | |
on: | |
pull_request: | |
paths: | |
- "**/terraform/**" | |
permissions: | |
contents: read | |
jobs: | |
build: | |
runs-on: [self-hosted, linux, X64, jammy, large] | |
steps: | |
- name: Setup tmate session | |
uses: canonical/action-tmate@main | |
with: | |
detached: true | |
test-terraform: | |
name: Test Terraform with Juju | |
runs-on: ubuntu-latest | |
env: | |
WORKING_DIR: "webhook-gateway/charm/terraform/tests" | |
steps: | |
- uses: actions/checkout@v5.0.0 | |
- uses: charmed-kubernetes/actions-operator@main | |
with: | |
provider: "microk8s" | |
channel: 1.33-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" | |
- uses: hashicorp/setup-terraform@v3.1.2 | |
- 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: | | |
juju add-model test-deploy-webhook-gateway | |
set -e # Exit on error | |
terraform test || { echo "Terraform test failed"; exit 1; } | |
working-directory: ${{env.WORKING_DIR}} | |
- name: Apply Terraform | |
run: terraform apply -auto-approve | |
working-directory: ${{ env.WORKING_DIR }} | |
- name: Wait for github-runner-webhook-gateway to be deployed | |
run: | | |
echo "Waiting for github-runner-webhook-gateway to be deployed..." | |
juju wait-for application github-runner-webhook-gateway --query='status=="maintenance" || status=="blocked"' --timeout=10m | |
- name: Verify github-runner-webhook-gateway application is deployed | |
run: | | |
STATUS=$(juju status github-runner-webhook-gateway --model test-deploy-webhook-gateway --format=json | jq -r '.applications.github-runner-webhook-gateway["application-status"].current') | |
echo "github-runner-webhook-gateway status: $STATUS" | |
if [ "$STATUS" == "error" ] || [ "$STATUS" == "unknown" ]; then | |
echo "github-runner-webhook-gateway failed to deploy or is unknown" | |
juju status --model test-deploy-webhook-gateway | |
exit 1 | |
fi |