diff --git a/terraform/README.md b/terraform/README.md index 7f6bb31..2472f6b 100644 --- a/terraform/README.md +++ b/terraform/README.md @@ -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" @@ -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 } } ``` diff --git a/terraform/main.tf b/terraform/main.tf index 3332591..41cbc45 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -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 } diff --git a/terraform/outputs.tf b/terraform/outputs.tf index b49b5d0..da17889 100644 --- a/terraform/outputs.tf +++ b/terraform/outputs.tf @@ -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" -} \ No newline at end of file diff --git a/terraform/variables.tf b/terraform/variables.tf index 29dc071..08e42da 100644 --- a/terraform/variables.tf +++ b/terraform/variables.tf @@ -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" { @@ -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" -} \ No newline at end of file + 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." + } + +} diff --git a/terraform/terraform.tf b/terraform/versions.tf similarity index 100% rename from terraform/terraform.tf rename to terraform/versions.tf