-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add terraform #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
8239429
add terraform
florentianayuwono e5e959e
fix terraform config
florentianayuwono 54682c0
fix formatting
florentianayuwono 0427a74
update test
florentianayuwono 119cc68
update format
florentianayuwono 60a7199
remove unused var
florentianayuwono 71ec35d
update test
florentianayuwono 29b85db
fix file path
florentianayuwono ec5ac5a
update channel
florentianayuwono 09341d5
update format
florentianayuwono c7e44bc
change model name
florentianayuwono a772d4c
adjust units
florentianayuwono 55f5e72
modify assert
florentianayuwono 7772cb2
fix charm name
florentianayuwono dac6fb3
modify workflow
florentianayuwono e19db0a
use juju wait
florentianayuwono 8e10ad7
use juju wait-for
florentianayuwono 024694a
modify name
florentianayuwono e5a896b
deploy principal
florentianayuwono 8bf1e71
add proxy-address
florentianayuwono 37b25c1
simplify check
florentianayuwono d047510
Merge branch 'main' into feat/add-terraform-ISD-4342
florentianayuwono 34300e7
apply suggestion
florentianayuwono File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,58 +1,84 @@ | ||
| # Copyright 2025 Canonical Ltd. | ||
| # See LICENSE file for licensing details. | ||
|
|
||
| # Attention: valid for K8s charms only | ||
|
|
||
| name: Terraform module tests | ||
| name: Terraform module tests (machine-based) | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths: | ||
| - 'terraform/**' | ||
| - "terraform/**" | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| test-terraform: | ||
| # remove this condition for enabling the workflow | ||
| if: false | ||
| name: Test Terraform with Juju | ||
| runs-on: ubuntu-latest | ||
| env: | ||
| WORKING_DIR: 'terraform/tests' | ||
| WORKING_DIR: "terraform/tests" | ||
| steps: | ||
| - uses: actions/checkout@@v4.2.2 | ||
| - 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}} | ||
| - 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}} | ||
|
|
||
| - name: Apply Terraform | ||
| run: terraform apply -auto-approve | ||
| working-directory: ${{ env.WORKING_DIR }} | ||
|
|
||
| - name: Deploy principal and relate aproxy | ||
| run: | | ||
| juju deploy ubuntu --channel=latest/stable --model test-aproxy-example | ||
| juju integrate ubuntu aproxy --model test-aproxy-example | ||
|
|
||
| - name: Wait for aproxy to be deployed | ||
| run: | | ||
| echo "Waiting for aproxy to be deployed..." | ||
| juju wait-for application aproxy --query='status=="maintenance" || status=="blocked"' --timeout=10m | ||
|
|
||
| - name: Verify aproxy application is deployed | ||
| run: | | ||
| STATUS=$(juju status aproxy --model test-aproxy-example --format=json | jq -r '.applications.aproxy["application-status"].current') | ||
| echo "aproxy status: $STATUS" | ||
| if [ "$STATUS" == "error" ] || [ "$STATUS" == "unknown" ]; then | ||
| echo "aproxy failed to deploy or is unknown" | ||
| juju status --model test-aproxy-example | ||
| exit 1 | ||
| fi | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,16 @@ | ||
| # Copyright 2025 Canonical Ltd. | ||
| # See LICENSE file for licensing details. | ||
|
|
||
| resource "juju_application" "charm_name" { | ||
| name = var.app_name | ||
| model = var.model | ||
|
|
||
| resource "juju_application" "aproxy" { | ||
| name = var.app_name | ||
| charm { | ||
| name = "<charm_name>" | ||
| name = "aproxy" | ||
| channel = var.channel | ||
| revision = var.revision | ||
| base = var.base | ||
| } | ||
|
|
||
| config = var.config | ||
| constraints = var.constraints | ||
| units = var.units | ||
| storage_directives = var.storage | ||
| model = var.model | ||
| config = var.config | ||
| units = 1 | ||
| } |
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ terraform { | |
| required_providers { | ||
| juju = { | ||
| source = "juju/juju" | ||
| version = ">= 0.20.0" | ||
| version = ">= 0.23.0" | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.