Skip to content
Draft
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
18 changes: 18 additions & 0 deletions .github/workflows/test_terraform_module.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 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
terraform-directories: '["terraform"]'
33 changes: 24 additions & 9 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
{
"$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 = '24.04'].revision.revision))}]}"
]
}
},
"customManagers": [
{
"customType": "regex",
Expand All @@ -15,12 +24,20 @@
],
"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"
}
],
"extends": [
"config:recommended",
"group:allNonMajor"
],
"ignorePaths": [],
"packageRules": [
{
"enabled": true,
Expand All @@ -29,6 +46,13 @@
],
"pinDigests": true
},
{
"matchDatasources": [
"custom.charmhub"
],
"automerge": true,
"enabled": true
},
{
"enabled": false,
"matchFileNames": [
Expand All @@ -39,15 +63,6 @@
"minor",
"patch"
]
},
{
"enabled": true,
"matchDatasources": [
"terraform-provider"
],
"matchPackageNames": [
"juju/juju"
]
}
],
"schedule": [
Expand Down
2 changes: 1 addition & 1 deletion terraform/.tflint.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# See LICENSE file for licensing details.

rule "terraform_required_version" {
enabled = false
enabled = true
}
24 changes: 12 additions & 12 deletions terraform/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<!-- Remember to update this file for your charm -- replace __charm_name__ with the appropriate name. -->
<!-- Remember to update this file for your charm -- replace mattermost-k8s with the appropriate name. -->

# __charm_name__ Terraform module
# mattermost-k8s Terraform module

This folder contains a base [Terraform][Terraform] module for the __charm_name__ charm.
This folder contains a base [Terraform][Terraform] module for the mattermost-k8s charm.

The module uses the [Terraform Juju provider][Terraform Juju provider] to model the charm
deployment onto any Kubernetes environment managed by [Juju][Juju].
Expand All @@ -17,18 +17,18 @@ deployment onto any Kubernetes environment managed by [Juju][Juju].
the Juju application name.
- **versions.tf** - Defines the Terraform provider version.

## Using __charm_name__ base module in higher level modules
## Using mattermost-k8s base module in higher level modules

If you want to use `__charm_name__` base module as part of your Terraform module, import it
If you want to use `mattermost-k8s` base module as part of your Terraform module, import it
like shown below:

```text
data "juju_model" "my_model" {
name = var.model
}

module "__charm_name__" {
source = "git::https://github.com/canonical/__charm_name__-operator//terraform"
module "mattermost-k8s" {
source = "git::https://github.com/canonical/mattermost-k8s-operator//terraform"

model = juju_model.my_model.name
# (Customize configuration variables here if needed)
Expand All @@ -38,11 +38,11 @@ module "__charm_name__" {
Create integrations, for instance:

```text
resource "juju_integration" "__charm_name__-loki" {
resource "juju_integration" "mattermost-k8s-loki" {
model = juju_model.my_model.name
application {
name = module.__charm_name__.app_name
endpoint = module.__charm_name__.endpoints.logging
name = module.mattermost-k8s.app_name
endpoint = module.mattermost-k8s.endpoints.logging
}
application {
name = "loki-k8s"
Expand All @@ -51,9 +51,9 @@ resource "juju_integration" "__charm_name__-loki" {
}
```

The complete list of available integrations can be found [in the Integrations tab][__charm_name__-integrations].
The complete list of available integrations can be found [in the Integrations tab][mattermost-k8s-integrations].

[Terraform]: https://developer.hashicorp.com/terraform
[Terraform Juju provider]: https://registry.terraform.io/providers/juju/juju/latest
[Juju]: https://juju.is
[__charm_name__-integrations]: https://charmhub.io/__charm_name__/integrations
[mattermost-k8s-integrations]: https://charmhub.io/mattermost-k8s/integrations
8 changes: 4 additions & 4 deletions terraform/main.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# 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" "mattermost_k8s" {
name = var.app_name
model_uuid = var.model_uuid

charm {
name = "__charm_name__"
name = "mattermost-k8s"
channel = var.channel
revision = var.revision
base = var.base
Expand Down
2 changes: 1 addition & 1 deletion terraform/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

output "app_name" {
description = "Name of the deployed application."
value = juju_application.__charm_name__.name
value = juju_application.mattermost_k8s.name
}

output "endpoints" {
Expand Down
2 changes: 1 addition & 1 deletion terraform/tests/.tflint.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# See LICENSE file for licensing details.

rule "terraform_required_version" {
enabled = false
enabled = true
}
33 changes: 0 additions & 33 deletions terraform/tests/main.tf

This file was deleted.

20 changes: 14 additions & 6 deletions terraform/tests/main.tftest.hcl
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

variables {
channel = "latest/edge"
# renovate: depName="__charm_name__"
revision = 1
run "setup_tests" {
module {
source = "./tests/setup"
}
}

run "basic_deploy" {
variables {
model_uuid = run.setup_tests.model_uuid
channel = "latest/edge"
# renovate: depName="mattermost-k8s"
revision = 18
}

assert {
condition = module.__charm_name__.app_name == "__charm_name__"
error_message = "__charm_name__ app_name did not match expected"
condition = output.app_name == "mattermost-k8s"
error_message = "mattermost-k8s 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
}
8 changes: 4 additions & 4 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
variable "app_name" {
description = "Name of the application in the Juju model."
type = string
default = "__charm_name__"
default = "mattermost-k8s"
}

variable "base" {
Expand All @@ -20,7 +20,7 @@ variable "channel" {
}

variable "config" {
description = "Application config. Details about available options can be found at https://charmhub.io/__charm_name__/configurations."
description = "Application config. Details about available options can be found at https://charmhub.io/mattermost-k8s/configurations."
type = map(string)
default = {}
}
Expand All @@ -31,8 +31,8 @@ variable "constraints" {
default = ""
}

variable "model" {
description = "Reference to a `juju_model`."
variable "model_uuid" {
description = "UUID of the Juju model to deploy the application into."
type = string
}

Expand Down
3 changes: 2 additions & 1 deletion terraform/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
# See LICENSE file for licensing details.

terraform {
required_version = "~> 1.12"
required_providers {
juju = {
source = "juju/juju"
version = ">= 0.20.0"
version = "~> 1.0"
}
}
}
Loading