From 0bf247e0e432d25371ec9e55072326756f8bc110 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Wed, 14 Oct 2026 20:15:42 +0800 Subject: [PATCH 1/6] chore: migrate terraform modules to CC008 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../workflows/generate_terraform_docs.yaml | 23 ++++++ .../terraform_modules_compliance.yaml | 17 +++++ .../workflows/terraform_modules_release.yaml | 23 ++++++ ...odule.yaml => test_terraform_modules.yaml} | 7 +- .gitignore | 2 + .licenserc.yaml | 1 + docs/changelog.md | 7 ++ terraform/MAJOR_VERSION | 1 + terraform/README.md | 25 ++++--- terraform/main.tf | 7 +- terraform/outputs.tf | 20 ++++-- terraform/{versions.tf => terraform.tf} | 2 + terraform/tests/integration/main.tf | 50 ------------- .../tests/integration/wait-for-status.sh | 10 --- terraform/tests/main.tftest.hcl | 72 ++++++++++++++----- terraform/tests/setup/main.tf | 22 ------ terraform/variables.tf | 11 ++- 17 files changed, 178 insertions(+), 122 deletions(-) create mode 100644 .github/workflows/generate_terraform_docs.yaml create mode 100644 .github/workflows/terraform_modules_compliance.yaml create mode 100644 .github/workflows/terraform_modules_release.yaml rename .github/workflows/{test_terraform_module.yaml => test_terraform_modules.yaml} (66%) create mode 100644 terraform/MAJOR_VERSION rename terraform/{versions.tf => terraform.tf} (81%) delete mode 100644 terraform/tests/integration/main.tf delete mode 100755 terraform/tests/integration/wait-for-status.sh delete mode 100644 terraform/tests/setup/main.tf diff --git a/.github/workflows/generate_terraform_docs.yaml b/.github/workflows/generate_terraform_docs.yaml new file mode 100644 index 0000000..e97f826 --- /dev/null +++ b/.github/workflows/generate_terraform_docs.yaml @@ -0,0 +1,23 @@ +# Copyright 2026 Canonical Ltd. +# See LICENSE file for licensing details. + +name: Generate Terraform docs + +on: + workflow_dispatch: + push: + branches: + - main + paths: + - '**/terraform/**' + - '.github/workflows/generate_terraform_docs.yaml' + +permissions: + contents: write + pull-requests: write + +jobs: + generate-terraform-docs: + uses: canonical/operator-workflows/.github/workflows/generate_terraform_docs.yaml@030c5b20a0bb880dcf1ed326bff0fc16b6eb6ac1 # main + with: + terraform-directory: 'terraform' diff --git a/.github/workflows/terraform_modules_compliance.yaml b/.github/workflows/terraform_modules_compliance.yaml new file mode 100644 index 0000000..96daeeb --- /dev/null +++ b/.github/workflows/terraform_modules_compliance.yaml @@ -0,0 +1,17 @@ +# Copyright 2026 Canonical Ltd. +# See LICENSE file for licensing details. + +name: Terraform modules compliance + +on: + workflow_dispatch: + pull_request: + paths: + - '**/terraform/**' + - '.github/workflows/terraform_modules_compliance.yaml' + +jobs: + terraform-compliance: + uses: canonical/operator-workflows/.github/workflows/terraform_modules_compliance.yaml@030c5b20a0bb880dcf1ed326bff0fc16b6eb6ac1 # main + with: + terraform-directories: '["terraform"]' diff --git a/.github/workflows/terraform_modules_release.yaml b/.github/workflows/terraform_modules_release.yaml new file mode 100644 index 0000000..c124256 --- /dev/null +++ b/.github/workflows/terraform_modules_release.yaml @@ -0,0 +1,23 @@ +# Copyright 2026 Canonical Ltd. +# See LICENSE file for licensing details. + +name: Release Terraform modules + +on: + push: + branches: + - main + paths: + - '**/terraform/**' + - '.github/workflows/terraform_modules_release.yaml' + pull_request: + paths: + - '**/terraform/**' + - '.github/workflows/terraform_modules_release.yaml' + +permissions: + contents: write + +jobs: + terraform-release: + uses: canonical/operator-workflows/.github/workflows/terraform_modules_release.yaml@030c5b20a0bb880dcf1ed326bff0fc16b6eb6ac1 # main diff --git a/.github/workflows/test_terraform_module.yaml b/.github/workflows/test_terraform_modules.yaml similarity index 66% rename from .github/workflows/test_terraform_module.yaml rename to .github/workflows/test_terraform_modules.yaml index aa92d51..e921166 100644 --- a/.github/workflows/test_terraform_module.yaml +++ b/.github/workflows/test_terraform_modules.yaml @@ -1,19 +1,20 @@ # Copyright 2025 Canonical Ltd. # See LICENSE file for licensing details. -name: Test Terraform Module +name: Test Terraform Modules on: workflow_dispatch: pull_request: paths: - - "terraform/**" + - "**/terraform/**" + - ".github/workflows/test_terraform_modules.yaml" permissions: contents: read jobs: test-terraform: - uses: canonical/operator-workflows/.github/workflows/terraform_modules_test.yaml@main + uses: canonical/operator-workflows/.github/workflows/terraform_modules_test.yaml@030c5b20a0bb880dcf1ed326bff0fc16b6eb6ac1 # main with: lxd-controller: true k8s-controller: false diff --git a/.gitignore b/.gitignore index 61820f7..b50b7e9 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,8 @@ __pycache__/ *.egg-info/ */*.rock terraform/tests/.terraform +**/.terraform/ +**/.terraform.lock.hcl # BEGIN VALE WORKFLOW IGNORE .vale/styles/* diff --git a/.licenserc.yaml b/.licenserc.yaml index c960196..34cb6b1 100644 --- a/.licenserc.yaml +++ b/.licenserc.yaml @@ -19,6 +19,7 @@ header: - '.jujuignore' - '.gitignore' - '.licenserc.yaml' + - '**/MAJOR_VERSION' - 'CODEOWNERS' - 'LICENSE' - 'trivy.yaml' diff --git a/docs/changelog.md b/docs/changelog.md index 2052832..4cd9a88 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -13,6 +13,13 @@ Place any unreleased changes here, that are subject to release in coming version - Added support for base ubuntu@26.04. Aproxy now supports 20.04, 22.04, 24.04, and 26.04. - Load the netfilter kernel modules required by the nftables rules before applying them. - Organize the documentation home page by user needs and explain its structure. +- Migrated the `terraform/` module to the CC008 Charm Terraform Standard: renamed `versions.tf` to + `terraform.tf`, added the mandatory `constraints` variable and the `application`/`provides`/`requires` + outputs (replacing the deprecated `app_name` and `endpoints` outputs), added a `terraform/MAJOR_VERSION` + file, and wired the `terraform_modules_compliance`, `terraform_modules_release` and + `generate_terraform_docs` CI workflows. Note that the `base` variable now defaults to `null` (the + charm's default base) instead of `ubuntu@24.04`; pass `base = "ubuntu@24.04"` explicitly to keep the + previous default. # 2026-05-19 - Add `aproxy-port` charm configuration to allow customizing the port that aproxy listens on. diff --git a/terraform/MAJOR_VERSION b/terraform/MAJOR_VERSION new file mode 100644 index 0000000..56a6051 --- /dev/null +++ b/terraform/MAJOR_VERSION @@ -0,0 +1 @@ +1 \ No newline at end of file diff --git a/terraform/README.md b/terraform/README.md index 217b6fc..6970989 100644 --- a/terraform/README.md +++ b/terraform/README.md @@ -10,15 +10,16 @@ deployment onto any Kubernetes environment managed by [Juju][Juju]. - **main.tf** - Defines the Juju application to be deployed. - **variables.tf** - Allows customization of the deployment. Also models the charm configuration, except for exposing the deployment options (Juju model name, channel or application name). -- **output.tf** - Integrates the module with other Terraform modules, primarily +- **outputs.tf** - Integrates the module with other Terraform modules, primarily by defining potential integration endpoints (charm integrations), but also by exposing - the Juju application name. -- **versions.tf** - Defines the Terraform provider version. + the deployed Juju application. +- **terraform.tf** - Defines the Terraform and Juju provider versions. ## Using aproxy base module in higher level modules If you want to use `aproxy` base module as part of your Terraform module, import it -like shown below: +like shown below. Always pin the `?ref=` to a released tag or a commit hash: CC008 does +not allow floating references such as branches. ```text data "juju_model" "my_model" { @@ -26,9 +27,9 @@ data "juju_model" "my_model" { } module "aproxy" { - source = "git::https://github.com/canonical/aproxy-operator//terraform" - - model = juju_model.my_model.name + source = "git::https://github.com/canonical/aproxy-operator//terraform?ref=tf-1.0.0" + + model_uuid = data.juju_model.my_model.uuid # (Customize configuration variables here if needed) } ``` @@ -37,10 +38,10 @@ Create integrations, for instance: ```text resource "juju_integration" "aproxy_to_principal" { - model = juju_model.my_model.name + model_uuid = data.juju_model.my_model.uuid application { - name = module.aproxy.app_name - endpoint = module.aproxy.endpoints.juju_info + name = module.aproxy.application.name + endpoint = module.aproxy.requires.juju_info.endpoint } application { name = "principal-app" @@ -51,6 +52,10 @@ resource "juju_integration" "aproxy_to_principal" { The complete list of available integrations can be found [in the Integrations tab][aproxy-integrations]. + + + + [Terraform]: https://www.terraform.io/ [Terraform Juju provider]: https://registry.terraform.io/providers/juju/juju/latest [Juju]: https://juju.is diff --git a/terraform/main.tf b/terraform/main.tf index 1aedb5b..ad34f84 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -10,7 +10,8 @@ resource "juju_application" "aproxy" { base = var.base } - model_uuid = var.model_uuid - config = var.config - units = 1 + model_uuid = var.model_uuid + config = var.config + constraints = var.constraints + units = 1 } diff --git a/terraform/outputs.tf b/terraform/outputs.tf index d995d82..d52b94d 100644 --- a/terraform/outputs.tf +++ b/terraform/outputs.tf @@ -1,13 +1,23 @@ # Copyright 2025 Canonical Ltd. # See LICENSE file for licensing details. -output "app_name" { - description = "Name of the deployed application." - value = juju_application.aproxy.name +output "application" { + description = "The deployed application object." + value = juju_application.aproxy } -output "endpoints" { +output "provides" { + description = "Map of the provided integration endpoints." + value = {} +} + +output "requires" { + description = "Map of the required integration endpoints." value = { - juju_info = "juju-info" + juju_info = { + kind = "endpoint" + name = juju_application.aproxy.name + endpoint = "juju-info" + } } } diff --git a/terraform/versions.tf b/terraform/terraform.tf similarity index 81% rename from terraform/versions.tf rename to terraform/terraform.tf index 70b645f..0f37edd 100644 --- a/terraform/versions.tf +++ b/terraform/terraform.tf @@ -2,6 +2,8 @@ # See LICENSE file for licensing details. terraform { + required_version = ">= 1.6.0, < 2.0.0" + required_providers { juju = { source = "juju/juju" diff --git a/terraform/tests/integration/main.tf b/terraform/tests/integration/main.tf deleted file mode 100644 index dd0822d..0000000 --- a/terraform/tests/integration/main.tf +++ /dev/null @@ -1,50 +0,0 @@ -# Copyright 2025 Canonical Ltd. -# See LICENSE file for licensing details. - -terraform { - required_version = ">= 1.0" - required_providers { - juju = { - version = "> 1.1.0" - source = "juju/juju" - } - external = { - version = "> 2" - source = "hashicorp/external" - } - } -} - -provider "juju" {} - -variable "model_uuid" { - type = string -} - -resource "juju_application" "ubuntu" { - model_uuid = var.model_uuid - charm { - name = "ubuntu" - } -} - -resource "juju_integration" "aproxy_ubuntu" { - model_uuid = var.model_uuid - - application { - name = juju_application.ubuntu.name - } - - application { - name = "aproxy" - } -} - -# tflint-ignore: terraform_unused_declarations -data "external" "aproxy_status" { - program = ["bash", "${path.module}/wait-for-status.sh", var.model_uuid] - - depends_on = [ - juju_integration.aproxy_ubuntu - ] -} diff --git a/terraform/tests/integration/wait-for-status.sh b/terraform/tests/integration/wait-for-status.sh deleted file mode 100755 index cbce262..0000000 --- a/terraform/tests/integration/wait-for-status.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -# Copyright 2026 Canonical Ltd. -# See LICENSE file for licensing details. - -MODEL_UUID=$1 - -juju wait-for application aproxy --query='status=="maintenance" || status=="blocked"' --timeout=10m &> /dev/null -STATUS=$(juju status aproxy --model "$MODEL_UUID" --format=json | jq -r '.applications.aproxy["application-status"].current') - -echo '{"status": "'"$STATUS"'"}' diff --git a/terraform/tests/main.tftest.hcl b/terraform/tests/main.tftest.hcl index fcbb264..eb4eebf 100644 --- a/terraform/tests/main.tftest.hcl +++ b/terraform/tests/main.tftest.hcl @@ -1,36 +1,72 @@ # Copyright 2025 Canonical Ltd. # See LICENSE file for licensing details. -run "setup_tests" { - module { - source = "./tests/setup" +variables { + app_name = "aproxy" + base = "ubuntu@24.04" + channel = "latest/stable" + config = {} + constraints = "arch=amd64" + model_uuid = "00000000-0000-0000-0000-000000000001" + # renovate: depName="aproxy" + revision = 270 +} + +mock_provider "juju" { + mock_resource "juju_application" { + defaults = { + id = "aproxy" + model_type = "lxd" + unit_numbers = ["0"] + } } } -run "basic_deploy" { - variables { - model_uuid = run.setup_tests.model_uuid - # renovate: depName="aproxy" - revision = 270 +run "deploys_application" { + command = plan + + assert { + condition = output.application.name == "aproxy" + error_message = "aproxy application name did not match expected" } assert { - condition = output.app_name == "aproxy" - error_message = "aproxy app_name did not match expected" + condition = output.application.model_uuid == var.model_uuid + error_message = "aproxy application model_uuid did not match expected" } -} -run "integration" { - variables { - model_uuid = run.setup_tests.model_uuid + assert { + condition = output.application.charm[0].name == "aproxy" + error_message = "aproxy application charm name did not match expected" } - module { - source = "./tests/integration" + assert { + condition = output.application.charm[0].channel == "latest/stable" + error_message = "aproxy application charm channel did not match expected" + } + + assert { + condition = output.application.charm[0].revision == 270 + error_message = "aproxy application charm revision did not match expected" + } + + assert { + condition = output.provides == {} + error_message = "aproxy provides output did not match expected" + } + + assert { + condition = output.requires.juju_info.kind == "endpoint" + error_message = "aproxy requires.juju_info kind did not match expected" + } + + assert { + condition = output.requires.juju_info.name == "aproxy" + error_message = "aproxy requires.juju_info name did not match expected" } assert { - condition = data.external.aproxy_status.result.status == "maintenance" || data.external.aproxy_status.result.status == "blocked" - error_message = "aproxy is not in the expected status after integration." + condition = output.requires.juju_info.endpoint == "juju-info" + error_message = "aproxy requires.juju_info endpoint did not match expected" } } diff --git a/terraform/tests/setup/main.tf b/terraform/tests/setup/main.tf deleted file mode 100644 index 9c958bc..0000000 --- a/terraform/tests/setup/main.tf +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright 2025 Canonical Ltd. -# See LICENSE file for licensing details. - -terraform { - required_version = ">= 1.0" - required_providers { - juju = { - version = "> 1.1.0" - source = "juju/juju" - } - } -} - -provider "juju" {} - -resource "juju_model" "test_model" { - name = "tf-testing-aproxy" -} - -output "model_uuid" { - value = juju_model.test_model.uuid -} diff --git a/terraform/variables.tf b/terraform/variables.tf index b19b6cb..0544243 100644 --- a/terraform/variables.tf +++ b/terraform/variables.tf @@ -5,18 +5,20 @@ variable "app_name" { description = "Application name for aproxy." type = string default = "aproxy" + nullable = false } variable "base" { description = "The operating system on which to deploy" type = string - default = "ubuntu@24.04" + default = null } variable "channel" { description = "The channel to use when deploying a charm." type = string default = "latest/stable" + nullable = false } variable "config" { @@ -25,9 +27,16 @@ variable "config" { default = {} } +variable "constraints" { + description = "Juju constraints to apply for this application." + type = string + default = null +} + variable "model_uuid" { description = "UUID of the Juju model where the application will be deployed." type = string + nullable = false } variable "revision" { From 0e3676840de5963fc660edb7941d30d0e9618235 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Wed, 14 Oct 2026 20:52:35 +0800 Subject: [PATCH 2/6] chore: align terraform modules with falco-operators conventions Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../workflows/generate_terraform_docs.yaml | 21 ++++-- .../terraform_modules_compliance.yaml | 6 +- .../workflows/terraform_modules_release.yaml | 22 +++--- .github/workflows/test_terraform_modules.yaml | 15 ++-- terraform/README.md | 2 + terraform/terraform.tf | 4 +- terraform/tests/main.tftest.hcl | 72 ++++--------------- terraform/tests/setup/main.tf | 22 ++++++ 8 files changed, 75 insertions(+), 89 deletions(-) create mode 100644 terraform/tests/setup/main.tf diff --git a/.github/workflows/generate_terraform_docs.yaml b/.github/workflows/generate_terraform_docs.yaml index e97f826..44b45de 100644 --- a/.github/workflows/generate_terraform_docs.yaml +++ b/.github/workflows/generate_terraform_docs.yaml @@ -1,23 +1,30 @@ # Copyright 2026 Canonical Ltd. # See LICENSE file for licensing details. -name: Generate Terraform docs +name: Update Terraform documentation +# Keep the `paths` filters below and the `terraform-directory` input in sync with +# the directories where the Terraform modules live. on: - workflow_dispatch: + pull_request: + paths: + - "terraform/**" + - ".github/workflows/generate_terraform_docs.yaml" push: branches: - main paths: - - '**/terraform/**' - - '.github/workflows/generate_terraform_docs.yaml' + - "terraform/**" + - ".github/workflows/generate_terraform_docs.yaml" permissions: contents: write pull-requests: write jobs: - generate-terraform-docs: - uses: canonical/operator-workflows/.github/workflows/generate_terraform_docs.yaml@030c5b20a0bb880dcf1ed326bff0fc16b6eb6ac1 # main + terraform-docs: + name: Update Terraform documentation + uses: canonical/operator-workflows/.github/workflows/generate_terraform_docs.yaml@030c5b20a0bb880dcf1ed326bff0fc16b6eb6ac1 # main + secrets: inherit with: - terraform-directory: 'terraform' + terraform-directory: terraform diff --git a/.github/workflows/terraform_modules_compliance.yaml b/.github/workflows/terraform_modules_compliance.yaml index 96daeeb..cae3dcf 100644 --- a/.github/workflows/terraform_modules_compliance.yaml +++ b/.github/workflows/terraform_modules_compliance.yaml @@ -7,11 +7,11 @@ on: workflow_dispatch: pull_request: paths: - - '**/terraform/**' - - '.github/workflows/terraform_modules_compliance.yaml' + - "**/terraform/**" + - ".github/workflows/terraform_modules_compliance.yaml" jobs: terraform-compliance: - uses: canonical/operator-workflows/.github/workflows/terraform_modules_compliance.yaml@030c5b20a0bb880dcf1ed326bff0fc16b6eb6ac1 # main + uses: canonical/operator-workflows/.github/workflows/terraform_modules_compliance.yaml@030c5b20a0bb880dcf1ed326bff0fc16b6eb6ac1 # main with: terraform-directories: '["terraform"]' diff --git a/.github/workflows/terraform_modules_release.yaml b/.github/workflows/terraform_modules_release.yaml index c124256..b470385 100644 --- a/.github/workflows/terraform_modules_release.yaml +++ b/.github/workflows/terraform_modules_release.yaml @@ -1,23 +1,23 @@ # Copyright 2026 Canonical Ltd. # See LICENSE file for licensing details. -name: Release Terraform modules +name: Terraform modules release on: + workflow_dispatch: + pull_request: + paths: + - "terraform/**" + - ".github/workflows/terraform_modules_release.yaml" push: branches: - main paths: - - '**/terraform/**' - - '.github/workflows/terraform_modules_release.yaml' - pull_request: - paths: - - '**/terraform/**' - - '.github/workflows/terraform_modules_release.yaml' - -permissions: - contents: write + - "terraform/**" + - ".github/workflows/terraform_modules_release.yaml" jobs: terraform-release: - uses: canonical/operator-workflows/.github/workflows/terraform_modules_release.yaml@030c5b20a0bb880dcf1ed326bff0fc16b6eb6ac1 # main + uses: canonical/operator-workflows/.github/workflows/terraform_modules_release.yaml@030c5b20a0bb880dcf1ed326bff0fc16b6eb6ac1 # main + permissions: + contents: write diff --git a/.github/workflows/test_terraform_modules.yaml b/.github/workflows/test_terraform_modules.yaml index e921166..1d58ae6 100644 --- a/.github/workflows/test_terraform_modules.yaml +++ b/.github/workflows/test_terraform_modules.yaml @@ -1,7 +1,8 @@ -# Copyright 2025 Canonical Ltd. +# Copyright 2026 Canonical Ltd. # See LICENSE file for licensing details. -name: Test Terraform Modules +name: Terraform modules tests + on: workflow_dispatch: pull_request: @@ -9,13 +10,11 @@ on: - "**/terraform/**" - ".github/workflows/test_terraform_modules.yaml" -permissions: - contents: read - jobs: - test-terraform: - uses: canonical/operator-workflows/.github/workflows/terraform_modules_test.yaml@030c5b20a0bb880dcf1ed326bff0fc16b6eb6ac1 # main + terraform-tests-lxd: + uses: canonical/operator-workflows/.github/workflows/terraform_modules_test.yaml@030c5b20a0bb880dcf1ed326bff0fc16b6eb6ac1 # main + secrets: inherit with: - lxd-controller: true k8s-controller: false + lxd-controller: true terraform-directories: '["terraform"]' diff --git a/terraform/README.md b/terraform/README.md index 6970989..1630d56 100644 --- a/terraform/README.md +++ b/terraform/README.md @@ -53,8 +53,10 @@ resource "juju_integration" "aproxy_to_principal" { The complete list of available integrations can be found [in the Integrations tab][aproxy-integrations]. + + [Terraform]: https://www.terraform.io/ [Terraform Juju provider]: https://registry.terraform.io/providers/juju/juju/latest diff --git a/terraform/terraform.tf b/terraform/terraform.tf index 0f37edd..bbca7d5 100644 --- a/terraform/terraform.tf +++ b/terraform/terraform.tf @@ -2,12 +2,12 @@ # See LICENSE file for licensing details. terraform { - required_version = ">= 1.6.0, < 2.0.0" + required_version = "~> 1.12" required_providers { juju = { source = "juju/juju" - version = "> 1.1.0" + version = "~> 1.0" } } } diff --git a/terraform/tests/main.tftest.hcl b/terraform/tests/main.tftest.hcl index eb4eebf..558a677 100644 --- a/terraform/tests/main.tftest.hcl +++ b/terraform/tests/main.tftest.hcl @@ -1,29 +1,20 @@ -# Copyright 2025 Canonical Ltd. +# Copyright 2026 Canonical Ltd. # See LICENSE file for licensing details. -variables { - app_name = "aproxy" - base = "ubuntu@24.04" - channel = "latest/stable" - config = {} - constraints = "arch=amd64" - model_uuid = "00000000-0000-0000-0000-000000000001" - # renovate: depName="aproxy" - revision = 270 -} - -mock_provider "juju" { - mock_resource "juju_application" { - defaults = { - id = "aproxy" - model_type = "lxd" - unit_numbers = ["0"] - } +run "setup_tests" { + module { + source = "./tests/setup" } } -run "deploys_application" { - command = plan +run "basic_deploy" { + variables { + model_uuid = run.setup_tests.model_uuid + base = "ubuntu@24.04" + channel = "latest/edge" + # renovate: depName="aproxy" + revision = 303 + } assert { condition = output.application.name == "aproxy" @@ -31,42 +22,7 @@ run "deploys_application" { } assert { - condition = output.application.model_uuid == var.model_uuid - error_message = "aproxy application model_uuid did not match expected" - } - - assert { - condition = output.application.charm[0].name == "aproxy" - error_message = "aproxy application charm name did not match expected" - } - - assert { - condition = output.application.charm[0].channel == "latest/stable" - error_message = "aproxy application charm channel did not match expected" - } - - assert { - condition = output.application.charm[0].revision == 270 - error_message = "aproxy application charm revision did not match expected" - } - - assert { - condition = output.provides == {} - error_message = "aproxy provides output did not match expected" - } - - assert { - condition = output.requires.juju_info.kind == "endpoint" - error_message = "aproxy requires.juju_info kind did not match expected" - } - - assert { - condition = output.requires.juju_info.name == "aproxy" - error_message = "aproxy requires.juju_info name did not match expected" - } - - assert { - condition = output.requires.juju_info.endpoint == "juju-info" - error_message = "aproxy requires.juju_info endpoint did not match expected" + condition = output.requires.value.endpoint == "juju-info" + error_message = "aproxy module should provide 'requires.value' output" } } diff --git a/terraform/tests/setup/main.tf b/terraform/tests/setup/main.tf new file mode 100644 index 0000000..0236105 --- /dev/null +++ b/terraform/tests/setup/main.tf @@ -0,0 +1,22 @@ +# Copyright 2026 Canonical Ltd. +# See LICENSE file for licensing details. + +terraform { + required_version = "~> 1.12" + required_providers { + juju = { + source = "juju/juju" + version = "~> 1.0" + } + } +} + +provider "juju" {} + +resource "juju_model" "test_model" { + name = "tf-testing-${formatdate("YYYYMMDDhhmmss", timestamp())}" +} + +output "model_uuid" { + value = juju_model.test_model.uuid +} From 011369318b9d5d89e59271fa01b28878b7638679 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Wed, 14 Oct 2026 21:51:24 +0800 Subject: [PATCH 3/6] fix: correct terraform test assertions and serialize per-charm releases Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- terraform/tests/main.tftest.hcl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/terraform/tests/main.tftest.hcl b/terraform/tests/main.tftest.hcl index 558a677..65fa177 100644 --- a/terraform/tests/main.tftest.hcl +++ b/terraform/tests/main.tftest.hcl @@ -22,7 +22,7 @@ run "basic_deploy" { } assert { - condition = output.requires.value.endpoint == "juju-info" - error_message = "aproxy module should provide 'requires.value' output" + condition = output.requires.juju_info.endpoint == "juju-info" + error_message = "aproxy module should provide 'requires.juju_info' output" } } From f5646440445736a4c062c9d30a2c1c4ef75476f6 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Thu, 15 Oct 2026 13:35:33 +0800 Subject: [PATCH 4/6] docs: point the Juju links at canonical.com/juju Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- terraform/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terraform/README.md b/terraform/README.md index 1630d56..ae516ae 100644 --- a/terraform/README.md +++ b/terraform/README.md @@ -60,5 +60,5 @@ The complete list of available integrations can be found [in the Integrations ta [Terraform]: https://www.terraform.io/ [Terraform Juju provider]: https://registry.terraform.io/providers/juju/juju/latest -[Juju]: https://juju.is +[Juju]: https://canonical.com/juju [aproxy-integrations]: https://charmhub.io/aproxy/integrations From 5cf0cb082a11cc9cfbd07be9aa24b4b25028e7e2 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Thu, 15 Oct 2026 14:04:09 +0800 Subject: [PATCH 5/6] refactor: move terraform modules to the terraform/charm and terraform/product layout Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .github/workflows/generate_terraform_docs.yaml | 2 +- .github/workflows/terraform_modules_compliance.yaml | 2 +- .github/workflows/test_terraform_modules.yaml | 2 +- .gitignore | 2 +- docs/changelog.md | 3 ++- terraform/{ => charm}/.tflint.hcl | 0 terraform/charm/MAJOR_VERSION | 1 + terraform/{ => charm}/README.md | 2 +- terraform/{ => charm}/main.tf | 0 terraform/{ => charm}/outputs.tf | 0 terraform/{ => charm}/terraform.tf | 0 terraform/{ => charm}/tests/.tflint.hcl | 0 terraform/{ => charm}/tests/main.tftest.hcl | 0 terraform/{ => charm}/tests/setup/main.tf | 0 terraform/{ => charm}/variables.tf | 0 15 files changed, 8 insertions(+), 6 deletions(-) rename terraform/{ => charm}/.tflint.hcl (100%) create mode 120000 terraform/charm/MAJOR_VERSION rename terraform/{ => charm}/README.md (98%) rename terraform/{ => charm}/main.tf (100%) rename terraform/{ => charm}/outputs.tf (100%) rename terraform/{ => charm}/terraform.tf (100%) rename terraform/{ => charm}/tests/.tflint.hcl (100%) rename terraform/{ => charm}/tests/main.tftest.hcl (100%) rename terraform/{ => charm}/tests/setup/main.tf (100%) rename terraform/{ => charm}/variables.tf (100%) diff --git a/.github/workflows/generate_terraform_docs.yaml b/.github/workflows/generate_terraform_docs.yaml index 44b45de..3a78108 100644 --- a/.github/workflows/generate_terraform_docs.yaml +++ b/.github/workflows/generate_terraform_docs.yaml @@ -27,4 +27,4 @@ jobs: uses: canonical/operator-workflows/.github/workflows/generate_terraform_docs.yaml@030c5b20a0bb880dcf1ed326bff0fc16b6eb6ac1 # main secrets: inherit with: - terraform-directory: terraform + terraform-directory: terraform/charm diff --git a/.github/workflows/terraform_modules_compliance.yaml b/.github/workflows/terraform_modules_compliance.yaml index cae3dcf..39c04ed 100644 --- a/.github/workflows/terraform_modules_compliance.yaml +++ b/.github/workflows/terraform_modules_compliance.yaml @@ -14,4 +14,4 @@ jobs: terraform-compliance: uses: canonical/operator-workflows/.github/workflows/terraform_modules_compliance.yaml@030c5b20a0bb880dcf1ed326bff0fc16b6eb6ac1 # main with: - terraform-directories: '["terraform"]' + terraform-directories: '["terraform/charm"]' diff --git a/.github/workflows/test_terraform_modules.yaml b/.github/workflows/test_terraform_modules.yaml index 1d58ae6..e74cb0e 100644 --- a/.github/workflows/test_terraform_modules.yaml +++ b/.github/workflows/test_terraform_modules.yaml @@ -17,4 +17,4 @@ jobs: with: k8s-controller: false lxd-controller: true - terraform-directories: '["terraform"]' + terraform-directories: '["terraform/charm"]' diff --git a/.gitignore b/.gitignore index b50b7e9..2099862 100644 --- a/.gitignore +++ b/.gitignore @@ -11,7 +11,7 @@ __pycache__/ .mypy_cache *.egg-info/ */*.rock -terraform/tests/.terraform +terraform/charm/tests/.terraform **/.terraform/ **/.terraform.lock.hcl diff --git a/docs/changelog.md b/docs/changelog.md index 4cd9a88..569a3ed 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -13,7 +13,8 @@ Place any unreleased changes here, that are subject to release in coming version - Added support for base ubuntu@26.04. Aproxy now supports 20.04, 22.04, 24.04, and 26.04. - Load the netfilter kernel modules required by the nftables rules before applying them. - Organize the documentation home page by user needs and explain its structure. -- Migrated the `terraform/` module to the CC008 Charm Terraform Standard: renamed `versions.tf` to +- Migrated the Terraform module to the CC008 Charm Terraform Standard and moved it from `terraform/` to + `terraform/charm/`: renamed `versions.tf` to `terraform.tf`, added the mandatory `constraints` variable and the `application`/`provides`/`requires` outputs (replacing the deprecated `app_name` and `endpoints` outputs), added a `terraform/MAJOR_VERSION` file, and wired the `terraform_modules_compliance`, `terraform_modules_release` and diff --git a/terraform/.tflint.hcl b/terraform/charm/.tflint.hcl similarity index 100% rename from terraform/.tflint.hcl rename to terraform/charm/.tflint.hcl diff --git a/terraform/charm/MAJOR_VERSION b/terraform/charm/MAJOR_VERSION new file mode 120000 index 0000000..4f13f03 --- /dev/null +++ b/terraform/charm/MAJOR_VERSION @@ -0,0 +1 @@ +../MAJOR_VERSION \ No newline at end of file diff --git a/terraform/README.md b/terraform/charm/README.md similarity index 98% rename from terraform/README.md rename to terraform/charm/README.md index ae516ae..a037c60 100644 --- a/terraform/README.md +++ b/terraform/charm/README.md @@ -27,7 +27,7 @@ data "juju_model" "my_model" { } module "aproxy" { - source = "git::https://github.com/canonical/aproxy-operator//terraform?ref=tf-1.0.0" + source = "git::https://github.com/canonical/aproxy-operator//terraform/charm?ref=tf-1.0.0" model_uuid = data.juju_model.my_model.uuid # (Customize configuration variables here if needed) diff --git a/terraform/main.tf b/terraform/charm/main.tf similarity index 100% rename from terraform/main.tf rename to terraform/charm/main.tf diff --git a/terraform/outputs.tf b/terraform/charm/outputs.tf similarity index 100% rename from terraform/outputs.tf rename to terraform/charm/outputs.tf diff --git a/terraform/terraform.tf b/terraform/charm/terraform.tf similarity index 100% rename from terraform/terraform.tf rename to terraform/charm/terraform.tf diff --git a/terraform/tests/.tflint.hcl b/terraform/charm/tests/.tflint.hcl similarity index 100% rename from terraform/tests/.tflint.hcl rename to terraform/charm/tests/.tflint.hcl diff --git a/terraform/tests/main.tftest.hcl b/terraform/charm/tests/main.tftest.hcl similarity index 100% rename from terraform/tests/main.tftest.hcl rename to terraform/charm/tests/main.tftest.hcl diff --git a/terraform/tests/setup/main.tf b/terraform/charm/tests/setup/main.tf similarity index 100% rename from terraform/tests/setup/main.tf rename to terraform/charm/tests/setup/main.tf diff --git a/terraform/variables.tf b/terraform/charm/variables.tf similarity index 100% rename from terraform/variables.tf rename to terraform/charm/variables.tf From e1c649fd986ab1ba267fb3329f1e45f479add97c Mon Sep 17 00:00:00 2001 From: florentianayuwono <76247368+florentianayuwono@users.noreply.github.com> Date: Thu, 15 Oct 2026 19:52:34 +0700 Subject: [PATCH 6/6] Apply suggestion from @florentianayuwono --- terraform/charm/MAJOR_VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terraform/charm/MAJOR_VERSION b/terraform/charm/MAJOR_VERSION index 4f13f03..89ac4b6 120000 --- a/terraform/charm/MAJOR_VERSION +++ b/terraform/charm/MAJOR_VERSION @@ -1 +1 @@ -../MAJOR_VERSION \ No newline at end of file +../MAJOR_VERSION