feat: add terraform module for webhook gateway #5
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: | |
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: "k8s" | |
use-canonical-k8s: true | |
channel: 1.33-classic/stable | |
juju-channel: 3.6/stable | |
- name: Prepare juju tf provider environment | |
run: | | |
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 plan -out=tfplan | |
working-directory: ${{env.WORKING_DIR}} | |
- run: terraform show tfplan | |
working-directory: ${{env.WORKING_DIR}} | |
- run: | | |
juju add-model prod-chat-example | |
set -e # Exit on error | |
terraform test || { echo "Terraform test failed"; exit 1; } | |
working-directory: ${{env.WORKING_DIR}} |