Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
2ed6c81
add terraform module
florentianayuwono Oct 20, 2025
6e9cfa6
add terraform
florentianayuwono Oct 20, 2025
179e3da
add secret
florentianayuwono Oct 21, 2025
5429fd2
change path
florentianayuwono Oct 22, 2025
e88b2d9
modify structure
florentianayuwono Oct 22, 2025
e004e45
addaccess secret
florentianayuwono Oct 22, 2025
7fa5fcb
add vault providers
florentianayuwono Oct 22, 2025
a648578
add vault to test
florentianayuwono Oct 22, 2025
01110bc
remove invalid input
florentianayuwono Oct 22, 2025
67acc09
change provider
florentianayuwono Oct 22, 2025
4a14617
change channel
florentianayuwono Oct 22, 2025
8d2ab54
change channel to strict
florentianayuwono Oct 22, 2025
e2bc8b7
Merge branch 'main' into feat/webhook-terraform-ISD-4341
florentianayuwono Oct 22, 2025
cc53cbe
add steps
florentianayuwono Oct 23, 2025
5b23e73
add tmate
florentianayuwono Oct 23, 2025
728df55
add tmate
florentianayuwono Oct 23, 2025
d753598
remove secret
florentianayuwono Oct 23, 2025
5b0d0e8
remove tmate
florentianayuwono Oct 23, 2025
e21f76e
remove revision
florentianayuwono Oct 23, 2025
c29f3da
fix format
florentianayuwono Oct 23, 2025
af0d387
change app name
florentianayuwono Oct 23, 2025
a2d63bb
add eof
florentianayuwono Oct 23, 2025
7148d93
add cleanup
florentianayuwono Oct 23, 2025
6fa967f
remove vault provider
florentianayuwono Oct 24, 2025
e39e54c
add tmate
florentianayuwono Oct 24, 2025
d607ad4
remove secret
florentianayuwono Oct 24, 2025
775c741
Merge branch 'main' into feat/webhook-terraform-ISD-4341
florentianayuwono Oct 28, 2025
4117bbc
update model to model_uuid
florentianayuwono Oct 28, 2025
fd48d81
remove owner
florentianayuwono Oct 28, 2025
72c2332
reorder workflow
florentianayuwono Oct 28, 2025
726b45b
apply code suggestion
florentianayuwono Oct 28, 2025
7764507
update readme
florentianayuwono Oct 28, 2025
751048e
Revert "update readme"
florentianayuwono Oct 28, 2025
91d6013
update readme
florentianayuwono Oct 28, 2025
614030e
add tests
florentianayuwono Oct 31, 2025
7b1a268
add trivyignore
florentianayuwono Nov 3, 2025
d583a70
add local var
florentianayuwono Nov 6, 2025
f5ee2c9
Merge branch 'main' into feat/webhook-terraform-ISD-4341
florentianayuwono Nov 7, 2025
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/lint_terraform_webhook.yaml
Comment thread
yhaliaw marked this conversation as resolved.
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 lint 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}}
55 changes: 55 additions & 0 deletions .github/workflows/test_terraform_webhook_module.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# 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.34-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
Comment thread
yanksyoon marked this conversation as resolved.
} >> "$GITHUB_ENV"
- run: juju add-model stg-deploy-webhook-gateway
- 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: terraform test
working-directory: ${{env.WORKING_DIR}}
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 = "test-deploy-webhook-gateway"
owner = "admin"
}

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

model_uuid = data.juju_model.my_model.uuid
# (Customize configuration variables here if needed)
}
```

Create integrations, for instance:

```text
resource "juju_integration" "webhook_rabbitmq" {
model_uuid = data.juju_model.my_model.uuid
application {
name = module.github_runner_webhook_gateway.app_name
}
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_uuid = var.model_uuid

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

locals {
webhook_gateway_app_name = "github-runner-webhook-gateway"
webhook_gateway_metrics_port = 9464
juju_model_name = "stg-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 = ">= 1.0.0"
}
}
}

data "juju_model" "webhook" {
name = local.juju_model_name
owner = "admin"
}

resource "juju_application" "rabbitmq" {
name = "rabbitmq"
model_uuid = data.juju_model.webhook.uuid

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

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

resource "juju_integration" "webhook_rabbitmq" {
model_uuid = data.juju_model.webhook.uuid
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_uuid = data.juju_model.webhook.uuid
revision = var.revision
config = {
metrics-port = local.webhook_gateway_metrics_port
}
}

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
}
30 changes: 30 additions & 0 deletions webhook-gateway/charm/terraform/tests/main.tftest.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 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"
}
Comment thread
yhaliaw marked this conversation as resolved.

assert {
condition = juju_application.rabbitmq.name == "rabbitmq"
error_message = "rabbitmq name did not match expected"
}

assert {
condition = contains([for app in juju_integration.webhook_rabbitmq.application : app.name], "rabbitmq")
error_message = "Integration must include the rabbitmq application"
}

assert {
condition = contains([for app in juju_integration.webhook_rabbitmq.application : app.name], "github-runner-webhook-gateway")
error_message = "Integration must include the webhook gateway application"
}
}
56 changes: 56 additions & 0 deletions webhook-gateway/charm/terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# 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"
}

# Change to latest/stable when available
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_uuid" {
description = "Reference to a Juju model UUID."
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 = ">= 1.0.0"
}
}
}
Loading