Skip to content

Commit

Permalink
chore: Refactor the Terraform module to follow spec CC006
Browse files Browse the repository at this point in the history
  • Loading branch information
ghislainbourgeois committed Oct 2, 2024
1 parent c82433a commit 6462878
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 47 deletions.
12 changes: 8 additions & 4 deletions terraform/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,20 @@ The base module is not intended to be deployed in separation (it is possible tho
- **main.tf** - Defines the Juju application to be deployed.
- **variables.tf** - Allows customization of the deployment options (Juju model name, channel or application name).
- **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 sdcore-nrf-k8s base module in higher level modules

If you want to use `sdcore-nrf-k8s` base module as part of your Terraform module, import it like shown below.

```text
data "juju_model" "my_model" {
name = "my_model_name"
}
module "sdcore-nrf-k8s" {
source = "git::https://github.com/canonical/sdcore-nrf-k8s-operator//terraform"
model_name = "juju_model_name"
model = juju_model.my_model.name
# Optional Configurations
# channel = "put the Charm channel here"
# app_name = "put the application name here"
Expand All @@ -35,12 +39,12 @@ resource "juju_integration" "nrf-db" {
application {
name = module.nrf.app_name
endpoint = module.nrf.database_endpoint
endpoint = module.nrf.requires.database
}
application {
name = module.mongodb.app_name
endpoint = module.mongodb.database_endpoint
endpoint = module.mongodb.provides.database
}
}
```
Expand Down
17 changes: 11 additions & 6 deletions terraform/main.tf
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

resource "juju_application" "sdcore-nrf-k8s" {
resource "juju_application" "nrf" {
name = var.app_name
model = var.model_name
model = var.model

charm {
name = "sdcore-nrf-k8s"
channel = var.channel
name = "sdcore-nrf-k8s"
channel = var.channel
revision = var.revision
}
units = 1
trust = true

config = var.config
constraints = var.constraints
units = var.units
resources = var.resources
trust = true
}


43 changes: 13 additions & 30 deletions terraform/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,22 @@

output "app_name" {
description = "Name of the deployed application."
value = juju_application.sdcore-nrf-k8s.name
value = juju_application.nrf.name
}

# Required integration endpoints

output "database_endpoint" {
description = "Name of the endpoint to integrate with MongoDB using mongodb_client interface."
value = "database"
output "requires" {
value = {
database = "database"
certificates = "certificates"
sdcore_config = "sdcore_config"
logging = "logging"
}
}

output "certificates_endpoint" {
description = "Name of the endpoint to get the X.509 certificate using tls-certificates interface."
value = "certificates"
output "provides" {
value = {
fiveg_nrf = "fiveg_nrf"
metrics = "metrics-endpoint"
}
}

output "sdcore_config_endpoint" {
description = "Name of the endpoint used to integrate with the NMS."
value = "sdcore_config"
}

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

# Provided integration endpoints

output "fiveg_nrf_endpoint" {
description = "Name of the endpoint to provide fiveg_nrf interface."
value = "fiveg_nrf"
}

output "metrics_endpoint" {
description = "Exposes the Prometheus metrics endpoint providing telemetry about the NRF instance."
value = "metrics-endpoint"
}
50 changes: 43 additions & 7 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

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

variable "channel" {
Expand All @@ -13,8 +13,44 @@ variable "channel" {
default = "1.5/edge"
}

variable "app_name" {
description = "Name of the application in the Juju model"
variable "config" {
description = "Application config. Details about available options can be found at https://charmhub.io/sdcore-nrf-k8s-operator/configure."
type = map(string)
default = {}
}

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

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

variable "resources" {
description = "Resources to use with the application. Details about available options can be found at https://charmhub.io/sdcore-nrf-k8s-operator/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."
}

}
File renamed without changes.

0 comments on commit 6462878

Please sign in to comment.