Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
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
41 changes: 41 additions & 0 deletions .github/workflows/test_terraform_webhook_file.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

name: Terraform files test (webhook-gateway)

on:
pull_request:
paths:
- "**/terraform/**"

permissions:
contents: read

jobs:
validate:
name: Validate terraform configuration files
runs-on: ubuntu-latest
env:
WORKING_DIR: "webhook-gateway/charm/terraform"
steps:
- name: Check out code
uses: actions/checkout@v5.0.0

- name: Setup Terraform
uses: hashicorp/setup-terraform@v3.1.2

- name: Run terraform fmt
run: terraform fmt -check -recursive
working-directory: ${{env.WORKING_DIR}}

- name: Setup Tflint
uses: terraform-linters/setup-tflint@v6.2.0
with:
tflint_wrapper_enabled: true

- name: Run tflint
run: |
tflint --version
tflint --init
tflint -f compact --recursive
working-directory: ${{env.WORKING_DIR}}
57 changes: 57 additions & 0 deletions .github/workflows/test_terraform_webhook_module.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

name: Terraform module tests (webhook-gateway)

on:
pull_request:
paths:
- "**/terraform/**"

permissions:
contents: read

jobs:
test-terraform:
name: Test Terraform with Juju
runs-on: ubuntu-latest
env:
WORKING_DIR: "webhook-gateway/charm/terraform/tests"
steps:
- uses: actions/checkout@v5.0.0
- uses: charmed-kubernetes/actions-operator@main
with:
provider: "microk8s"
channel: 1.33-strict/stable
juju-channel: 3.6/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-deploy-webhook-gateway
set -e # Exit on error
terraform test || { echo "Terraform test failed"; exit 1; }
working-directory: ${{env.WORKING_DIR}}
6 changes: 6 additions & 0 deletions webhook-gateway/charm/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" {
enabled = false
}
56 changes: 56 additions & 0 deletions webhook-gateway/charm/terraform/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# github_runner_webhook_gateway Terraform module

This folder contains a base [Terraform][Terraform] module for the github_runner_webhook_gateway charm.

The module uses the [Terraform Juju provider][Terraform Juju provider] to model the charm
deployment onto any Kubernetes environment managed by [Juju][Juju].

## Module structure

- **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
by defining potential integration endpoints (charm integrations), but also by exposing
the Juju application name.
- **versions.tf** - Defines the Terraform provider version.

## Using github_runner_webhook_gateway base module in higher level modules

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

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

module "github_runner_webhook_gateway" {
source = "git::https://github.com/canonical/github-runner-operators/tree/main/webhook-gateway/charm/terraform"

model = juju_model.my_model.name
# (Customize configuration variables here if needed)
}
```

Create integrations, for instance:

```text
resource "juju_integration" "webhook_rabbitmq" {
model = juju_model.my_model.name
application {
name = module.github_runner_webhook_gateway.app_name
endpoint = module.github_runner_webhook_gateway.endpoints.logging
}
application {
name = "rabbitmq"
}
}
```

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

[Terraform]: https://developer.hashicorp.com/terraform
[Terraform Juju provider]: https://registry.terraform.io/providers/juju/juju/latest
[Juju]: https://juju.is
[github_runner_webhook_gateway-integrations]: https://charmhub.io/github_runner_webhook_gateway/integrations
19 changes: 19 additions & 0 deletions webhook-gateway/charm/terraform/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

resource "juju_application" "github_runner_webhook_gateway" {
name = var.app_name
model = var.model

charm {
name = "github-runner-webhook-gateway"
channel = var.channel
revision = var.revision
base = var.base
}

config = var.config
constraints = var.constraints
units = var.units
storage_directives = var.storage
}
13 changes: 13 additions & 0 deletions webhook-gateway/charm/terraform/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

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

output "endpoints" {
value = {
rabbitmq = "rabbitmq"
}
}
6 changes: 6 additions & 0 deletions webhook-gateway/charm/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" {
enabled = false
}
77 changes: 77 additions & 0 deletions webhook-gateway/charm/terraform/tests/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

locals {
webhook_gateway_app_name = "github-runner-webhook-gateway"
juju_model_name = "test-deploy-webhook-gateway"
}

variable "channel" {
description = "The channel to use when deploying a charm."
type = string
default = "latest/edge"
}

variable "revision" {
description = "Revision number of the charm."
type = number
default = null
}

terraform {
required_version = ">= 1.6.6"
required_providers {
juju = {
source = "juju/juju"
version = ">= 0.23.0"
}
}
}

resource "juju_application" "rabbitmq" {
name = "rabbitmq"
model = local.juju_model_name

charm {
name = "rabbitmq-k8s"
channel = "3.12/stable"
}

trust = true
config = {}
constraints = ""
units = 1
}

resource "juju_integration" "webhook_rabbitmq" {
model = local.juju_model_name
application {
name = local.webhook_gateway_app_name
}
application {
name = juju_application.rabbitmq.name
}
}

provider "juju" {}

module "github_runner_webhook_gateway" {
source = "./.."
app_name = local.webhook_gateway_app_name
channel = var.channel
model = local.juju_model_name
revision = var.revision
config = {
metrics-port = 9464
}
}

output "app_name" {
description = "The name of the deployed github_runner_webhook_gateway charm application."
value = module.github_runner_webhook_gateway.app_name
}

output "endpoints" {
description = "Integration endpoints exposed by github_runner_webhook_gateway charm."
value = module.github_runner_webhook_gateway.endpoints
}
15 changes: 15 additions & 0 deletions webhook-gateway/charm/terraform/tests/main.tftest.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

variables {
channel = "latest/edge"
# renovate: depName="github_runner_webhook_gateway"
revision = 1
}

run "basic_deploy" {
assert {
condition = module.github_runner_webhook_gateway.app_name == "github-runner-webhook-gateway"
error_message = "github-runner-webhook-gateway app_name did not match expected"
}
}
55 changes: 55 additions & 0 deletions webhook-gateway/charm/terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# 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 = "github-runner-webhook-gateway"
}

variable "base" {
description = "The operating system on which to deploy"
type = string
default = "ubuntu@24.04"
}

variable "channel" {
description = "The channel to use when deploying a charm."
type = string
default = "latest/edge"
}

variable "config" {
description = "Application config. Details about available options can be found at https://charmhub.io/github-runner-webhook-gateway/configurations."
type = map(string)
default = {}
}

variable "constraints" {
description = "Juju constraints to apply for this application."
type = string
default = ""
}

variable "model" {
description = "Reference to a `juju_model`."
type = string
}

variable "revision" {
description = "Revision number of the charm"
type = number
default = null
}

variable "storage" {
description = "Map of storage used by the application."
type = map(string)
default = {}
}

variable "units" {
description = "Number of units to deploy"
type = number
default = 1
}
12 changes: 12 additions & 0 deletions webhook-gateway/charm/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.6.6"
required_providers {
juju = {
source = "juju/juju"
version = ">= 0.23.0"
}
}
}
Loading