From 1b021586aee7c1c9c3b1195f627dd372ff6e25be Mon Sep 17 00:00:00 2001 From: "Sebastien Georget (charmkeeper)" Date: Thu, 12 Mar 2026 07:40:43 +0100 Subject: [PATCH 1/2] chore(terraform): add terraform module Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .github/workflows/test_terraform_module.yaml | 19 ++++++++ renovate.json | 40 ++++++++++++++++ terraform/.tflint.hcl | 3 ++ terraform/README.md | 50 ++++++++++++++++++++ terraform/main.tf | 18 +++++++ terraform/outputs.tf | 29 ++++++++++++ terraform/tests/.tflint.hcl | 3 ++ terraform/tests/main.tftest.hcl | 22 +++++++++ terraform/tests/setup/main.tf | 22 +++++++++ terraform/variables.tf | 49 +++++++++++++++++++ terraform/versions.tf | 12 +++++ 11 files changed, 267 insertions(+) create mode 100644 .github/workflows/test_terraform_module.yaml create mode 100644 terraform/.tflint.hcl create mode 100644 terraform/README.md create mode 100644 terraform/main.tf create mode 100644 terraform/outputs.tf create mode 100644 terraform/tests/.tflint.hcl create mode 100644 terraform/tests/main.tftest.hcl create mode 100644 terraform/tests/setup/main.tf create mode 100644 terraform/variables.tf create mode 100644 terraform/versions.tf diff --git a/.github/workflows/test_terraform_module.yaml b/.github/workflows/test_terraform_module.yaml new file mode 100644 index 0000000..c5e5588 --- /dev/null +++ b/.github/workflows/test_terraform_module.yaml @@ -0,0 +1,19 @@ +# Copyright 2025 Canonical Ltd. +# See LICENSE file for licensing details. + +name: Terraform modules tests + +on: + workflow_dispatch: + pull_request: + paths: + - 'terraform/**' + +jobs: + terraform-tests: + uses: canonical/operator-workflows/.github/workflows/terraform_modules_test.yaml@main + secrets: inherit + with: + #k8s-controller: true + lxd-controller: true + terraform-directories: '["terraform"]' diff --git a/renovate.json b/renovate.json index 697bf93..81beb08 100644 --- a/renovate.json +++ b/renovate.json @@ -1,10 +1,43 @@ { "$schema": "https://docs.renovatebot.com/renovate-schema.json", "automerge": true, + "customDatasources": { + "charmhub": { + "defaultRegistryUrlTemplate": "https://api.charmhub.io/v2/charms/info/{{packageName}}?fields=channel-map", + "format": "json", + "transformTemplates": [ + "{\"releases\": [{\"version\": $string($$.(`channel-map`[channel.risk = 'edge' and channel.track = 'latest' and channel.base.architecture = 'amd64' and channel.base.channel = '22.04'].revision.revision))}]}" + ] + } + }, + "customManagers": [ + { + "customType": "regex", + "datasourceTemplate": "docker", + "description": "Update base image references", + "managerFilePatterns": [ + "/(^|/)rockcraft.yaml$/" + ], + "matchStrings": [ + "# renovate: build-base:\\s+(?[^:]*):(?[^\\s@]*)(@(?sha256:[0-9a-f]*))?", + "# renovate: base:\\s+(?[^:]*):(?[^\\s@]*)(@(?sha256:[0-9a-f]*))?" + ], + "matchStringsStrategy": "any", + "versioningTemplate": "ubuntu" + }, + { + "customType": "regex", + "fileMatch": ["\\.tftest\\.hcl$", "\\.tf$"], + "matchStrings": ["# renovate: depName=\"(?[^\"]+)\"\\s*\\n\\s*(?[a-zA-Z0-9_]+)\\s*=\\s*(?\\d+)"], + "versioningTemplate": "semver-coerced", + "datasourceTemplate": "custom.charmhub" + } + ], "enabled": false, "extends": [ "config:base" ], + "ignorePaths": [], "packageRules": [ { "enabled": true, @@ -13,6 +46,13 @@ ], "pinDigests": true }, + { + "matchDatasources": [ + "custom.charmhub" + ], + "automerge": true, + "enabled": true + }, { "enabled": false, "matchFiles": [ diff --git a/terraform/.tflint.hcl b/terraform/.tflint.hcl new file mode 100644 index 0000000..d0bbf8b --- /dev/null +++ b/terraform/.tflint.hcl @@ -0,0 +1,3 @@ +rule "terraform_required_version" { + enabled = true +} diff --git a/terraform/README.md b/terraform/README.md new file mode 100644 index 0000000..93ad9aa --- /dev/null +++ b/terraform/README.md @@ -0,0 +1,50 @@ +# IRC Bridge Terraform Module + +This Terraform module deploys the [irc-bridge](https://charmhub.io/irc-bridge) charm on a Juju model. + +## Usage + +```hcl +module "irc-bridge" { + source = "git::https://github.com/canonical/irc-bridge-operator//terraform" + model_uuid = juju_model.my_model.uuid +} +``` + +## Integrations + +The irc-bridge charm requires the following integrations: + +- `database`: PostgreSQL database (interface: `postgresql_client`) +- `matrix-auth`: Matrix authentication (interface: `matrix_auth`) +- `ingress`: Ingress for the bridge (interface: `ingress`) +- `ingress-media`: Ingress for media (interface: `ingress`) + +## Requirements + +| Name | Version | +|------|---------| +| terraform | ~> 1.12 | +| juju | ~> 1.0 | + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|----------| +| app\_name | Name of the application in the Juju model. | `string` | `"irc-bridge"` | no | +| base | The operating system on which to deploy. | `string` | `"ubuntu@22.04"` | no | +| channel | The channel to use when deploying a charm. | `string` | `"latest/stable"` | no | +| config | Application config. | `map(string)` | `{}` | no | +| constraints | Juju constraints to apply for this application. | `string` | `""` | no | +| model\_uuid | UUID of the Juju model where the application will be deployed. | `string` | n/a | yes | +| revision | Revision number of the charm. | `number` | `null` | no | +| units | Number of units to deploy. | `number` | `1` | no | + +## Outputs + +| Name | Description | +|------|-------------| +| app\_name | Name of the deployed application. | +| requires | Map of required relation endpoints. | +| provides | Map of provided relation endpoints. | +| endpoints | Map of all relation endpoints. | diff --git a/terraform/main.tf b/terraform/main.tf new file mode 100644 index 0000000..2d62529 --- /dev/null +++ b/terraform/main.tf @@ -0,0 +1,18 @@ +# Copyright 2025 Canonical Ltd. +# See LICENSE file for licensing details. + +resource "juju_application" "irc-bridge" { + name = var.app_name + model_uuid = var.model_uuid + + charm { + name = "irc-bridge" + base = var.base + channel = var.channel + revision = var.revision + } + + config = var.config + constraints = var.constraints + units = var.units +} diff --git a/terraform/outputs.tf b/terraform/outputs.tf new file mode 100644 index 0000000..2e8b32e --- /dev/null +++ b/terraform/outputs.tf @@ -0,0 +1,29 @@ +# Copyright 2025 Canonical Ltd. +# See LICENSE file for licensing details. + +output "app_name" { + description = "Name of the deployed application." + value = juju_application.irc-bridge.name +} + +output "requires" { + value = { + database = "database" + matrix_auth = "matrix-auth" + ingress = "ingress" + ingress_media = "ingress-media" + } +} + +output "provides" { + value = {} +} + +output "endpoints" { + value = { + database = "database" + matrix_auth = "matrix-auth" + ingress = "ingress" + ingress_media = "ingress-media" + } +} diff --git a/terraform/tests/.tflint.hcl b/terraform/tests/.tflint.hcl new file mode 100644 index 0000000..d0bbf8b --- /dev/null +++ b/terraform/tests/.tflint.hcl @@ -0,0 +1,3 @@ +rule "terraform_required_version" { + enabled = true +} diff --git a/terraform/tests/main.tftest.hcl b/terraform/tests/main.tftest.hcl new file mode 100644 index 0000000..ff1c6c3 --- /dev/null +++ b/terraform/tests/main.tftest.hcl @@ -0,0 +1,22 @@ +# Copyright 2025 Canonical Ltd. +# See LICENSE file for licensing details. + +run "setup_tests" { + module { + source = "./tests/setup" + } +} + +run "basic_deploy" { + variables { + model_uuid = run.setup_tests.model_uuid + channel = "latest/edge" + # renovate: depName="irc-bridge" + revision = 43 + } + + assert { + condition = output.app_name == "irc-bridge" + error_message = "irc-bridge app_name did not match expected" + } +} diff --git a/terraform/tests/setup/main.tf b/terraform/tests/setup/main.tf new file mode 100644 index 0000000..da1e204 --- /dev/null +++ b/terraform/tests/setup/main.tf @@ -0,0 +1,22 @@ +# Copyright 2025 Canonical Ltd. +# See LICENSE file for licensing details. + +terraform { + required_version = "~> 1.12" + required_providers { + juju = { + version = "~> 1.0" + source = "juju/juju" + } + } +} + +provider "juju" {} + +resource "juju_model" "test_model" { + name = "tf-testing-${formatdate("YYYYMMDDhhmmss", timestamp())}" +} + +output "model_uuid" { + value = juju_model.test_model.uuid +} diff --git a/terraform/variables.tf b/terraform/variables.tf new file mode 100644 index 0000000..028a445 --- /dev/null +++ b/terraform/variables.tf @@ -0,0 +1,49 @@ +# Copyright 2025 Canonical Ltd. +# See LICENSE file for licensing details. + +variable "app_name" { + description = "Name of the application in the Juju model." + type = string + default = "irc-bridge" +} + +variable "base" { + description = "The operating system on which to deploy." + type = string + default = "ubuntu@22.04" +} + +variable "channel" { + description = "The channel to use when deploying a charm." + type = string + default = "latest/stable" +} + +variable "config" { + description = "Application config. Details about available options can be found at https://charmhub.io/irc-bridge/configurations." + type = map(string) + default = {} +} + +variable "constraints" { + description = "Juju constraints to apply for this application." + type = string + default = "" +} + +variable "model_uuid" { + description = "UUID of the Juju model where the application will be deployed." + type = string +} + +variable "revision" { + description = "Revision number of the charm." + type = number + default = null +} + +variable "units" { + description = "Number of units to deploy." + type = number + default = 1 +} diff --git a/terraform/versions.tf b/terraform/versions.tf new file mode 100644 index 0000000..de6e0db --- /dev/null +++ b/terraform/versions.tf @@ -0,0 +1,12 @@ +# Copyright 2025 Canonical Ltd. +# See LICENSE file for licensing details. + +terraform { + required_version = "~> 1.12" + required_providers { + juju = { + source = "juju/juju" + version = "~> 1.0" + } + } +} From c68ee2753af500db2f7bf36ef6c969b91efa350e Mon Sep 17 00:00:00 2001 From: "Sebastien Georget (charmkeeper)" Date: Thu, 12 Mar 2026 08:30:27 +0100 Subject: [PATCH 2/2] fix(terraform): add missing license headers to .tflint.hcl files Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- terraform/.tflint.hcl | 3 +++ terraform/tests/.tflint.hcl | 3 +++ 2 files changed, 6 insertions(+) diff --git a/terraform/.tflint.hcl b/terraform/.tflint.hcl index d0bbf8b..f4e30c5 100644 --- a/terraform/.tflint.hcl +++ b/terraform/.tflint.hcl @@ -1,3 +1,6 @@ +# Copyright 2025 Canonical Ltd. +# See LICENSE file for licensing details. + rule "terraform_required_version" { enabled = true } diff --git a/terraform/tests/.tflint.hcl b/terraform/tests/.tflint.hcl index d0bbf8b..f4e30c5 100644 --- a/terraform/tests/.tflint.hcl +++ b/terraform/tests/.tflint.hcl @@ -1,3 +1,6 @@ +# Copyright 2025 Canonical Ltd. +# See LICENSE file for licensing details. + rule "terraform_required_version" { enabled = true }