Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/test_terraform_module.yaml
Original file line number Diff line number Diff line change
@@ -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"]'
40 changes: 40 additions & 0 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -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+(?<depName>[^:]*):(?<currentValue>[^\\s@]*)(@(?<currentDigest>sha256:[0-9a-f]*))?",
"# renovate: base:\\s+(?<depName>[^:]*):(?<currentValue>[^\\s@]*)(@(?<currentDigest>sha256:[0-9a-f]*))?"
],
"matchStringsStrategy": "any",
"versioningTemplate": "ubuntu"
},
{
"customType": "regex",
"fileMatch": ["\\.tftest\\.hcl$", "\\.tf$"],
"matchStrings": ["# renovate: depName=\"(?<packageName>[^\"]+)\"\\s*\\n\\s*(?<fieldName>[a-zA-Z0-9_]+)\\s*=\\s*(?<currentValue>\\d+)"],
"versioningTemplate": "semver-coerced",
"datasourceTemplate": "custom.charmhub"
}
],
"enabled": false,
"extends": [
"config:base"
],
"ignorePaths": [],
"packageRules": [
{
"enabled": true,
Expand All @@ -13,6 +46,13 @@
],
"pinDigests": true
},
{
"matchDatasources": [
"custom.charmhub"
],
"automerge": true,
"enabled": true
},
{
"enabled": false,
"matchFiles": [
Expand Down
6 changes: 6 additions & 0 deletions terraform/.tflint.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

rule "terraform_required_version" {
Comment thread
seb4stien marked this conversation as resolved.
enabled = true
}
50 changes: 50 additions & 0 deletions terraform/README.md
Original file line number Diff line number Diff line change
@@ -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. |
18 changes: 18 additions & 0 deletions terraform/main.tf
Original file line number Diff line number Diff line change
@@ -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
}
29 changes: 29 additions & 0 deletions terraform/outputs.tf
Original file line number Diff line number Diff line change
@@ -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"
}
}
6 changes: 6 additions & 0 deletions terraform/tests/.tflint.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

rule "terraform_required_version" {
Comment thread
seb4stien marked this conversation as resolved.
enabled = true
}
22 changes: 22 additions & 0 deletions terraform/tests/main.tftest.hcl
Original file line number Diff line number Diff line change
@@ -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"
}
}
22 changes: 22 additions & 0 deletions terraform/tests/setup/main.tf
Original file line number Diff line number Diff line change
@@ -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
}
49 changes: 49 additions & 0 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -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
}
12 changes: 12 additions & 0 deletions terraform/versions.tf
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
Loading