feat: add terraform #116
Workflow file for this run
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 (machine-based) | |
| on: | |
| pull_request: | |
| paths: | |
| - "terraform/**" | |
| permissions: | |
| contents: read | |
| jobs: | |
| test-terraform: | |
| name: Test Terraform with Juju | |
| runs-on: ubuntu-latest | |
| env: | |
| WORKING_DIR: "terraform/tests" | |
| steps: | |
| - name: Check out code | |
| uses: actions/checkout@v4.2.2 | |
| - name: Setup Juju with LXD | |
| uses: charmed-kubernetes/actions-operator@main | |
| with: | |
| provider: "lxd" | |
| juju-channel: 3/stable | |
| channel: "latest/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-aproxy-example | |
| set -e # Exit on error | |
| terraform test || { echo "Terraform test failed"; exit 1; } | |
| working-directory: ${{env.WORKING_DIR}} |