Skip to content

Commit

Permalink
chore: Update Terraform module to follow CC006 (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghislainbourgeois authored Jan 8, 2025
1 parent 971dd3f commit 060c8f7
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 40 deletions.
10 changes: 5 additions & 5 deletions terraform/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ rather serve as a building block for higher level modules.
- **output.tf** - Responsible for integrating the module with other Terraform modules, primarily
by defining potential integration endpoints (charm integrations), but also by exposing
the application name.
- **terraform.tf** - Defines the Terraform provider.
- **versions.tf** - Defines the Terraform provider.

## Using oai-ran-cu-k8s base module in higher level modules

Expand All @@ -28,7 +28,7 @@ like shown below:
module "cu" {
source = "git::https://github.com/canonical/oai-ran-cu-k8s-operator//terraform"
model_name = "juju_model_name"
model = "juju_model_name"
config = Optional config map
}
```
Expand All @@ -37,14 +37,14 @@ Create integrations, for instance:

```text
resource "juju_integration" "cu-amf" {
model = var.model_name
model = var.model
application {
name = module.cu.app_name
endpoint = module.cu.fiveg_n2_endpoint
endpoint = module.cu.requires.fiveg_n2
}
application {
name = module.amf.app_name
endpoint = module.amf.fiveg_n2_endpoint
endpoint = module.amf.provides.fiveg_n2
}
}
```
Expand Down
18 changes: 11 additions & 7 deletions terraform/main.tf
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# Copyright 2024 Canonical Ltd.
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

resource "juju_application" "cu" {
name = var.app_name
model = var.model_name
model = var.model

charm {
name = "oai-ran-cu-k8s"
channel = var.channel
name = "oai-ran-cu-k8s"
channel = var.channel
revision = var.revision
}
config = var.config
units = 1
trust = true

config = var.config
constraints = var.constraints
units = var.units
resources = var.resources
trust = true
}
32 changes: 11 additions & 21 deletions terraform/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,31 +1,21 @@
# Copyright 2024 Canonical Ltd.
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

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

# Required integration endpoints

output "fiveg_n2_endpoint" {
description = "Name of the endpoint used to provide information on connectivity to the N2 plane."
value = "fiveg_n2"
}

output "fiveg_core_gnb_endpoint" {
description = "Name of the endpoint used to provide core network configuration to gNB."
value = "fiveg_core_gnb"
output "provides" {
value = {
"fiveg_f1" = "fiveg_f1"
}
}

output "logging_endpoint" {
description = "Name of the endpoint used to integrate with the Logging provider."
value = "logging"
}

# Provided integration endpoints

output "fiveg_f1_endpoint" {
description = "Name of the endpoint used to provide information about F1 interface."
value = "fiveg_f1"
output "requires" {
value = {
"fiveg_n2" = "fiveg_n2"
"fiveg_core_gnb" = "fiveg_core_gnb"
"logging" = "logging"
}
}
43 changes: 36 additions & 7 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
# Copyright 2024 Canonical Ltd.
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

variable "model_name" {
description = "Name of Juju model to deploy application to."
type = string
default = ""
}

variable "app_name" {
description = "Name of the application in the Juju model."
type = string
Expand All @@ -24,3 +18,38 @@ variable "config" {
type = map(string)
default = {}
}

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

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

variable "resources" {
description = "Resources to use with the application. Details about available options can be found at https://charmhub.io/oai-ran-cu-k8s/configure."
type = map(string)
default = {}
}

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

variable "units" {
description = "Number of units to deploy"
type = number
default = 1

validation {
condition = var.units == 1
error_message = "Scaling is not supported for this charm."
}
}
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ lib_path = {toxinidir}/lib/charms/oai_ran_cu_k8s/v0
all_path = {[vars]src_path} {[vars]unit_test_path} {[vars]integration_test_path} {[vars]lib_path}

[testenv]
runner = uv-venv-lock-runner
with_dev = true
setenv =
PYTHONPATH = {toxinidir}:{toxinidir}/lib:{[vars]src_path}
PYTHONBREAKPOINT=pdb.set_trace
Expand Down

0 comments on commit 060c8f7

Please sign in to comment.