From 5ecad98c2e6982228c8ecd0b6710c3b533a128fe Mon Sep 17 00:00:00 2001 From: Ghislain Bourgeois Date: Thu, 3 Oct 2024 19:55:50 -0400 Subject: [PATCH] Refactor sdcore-user-plane-k8s to follow spec CC006. --- modules/sdcore-user-plane-k8s/README.md | 8 +++-- modules/sdcore-user-plane-k8s/main.tf | 34 ++++++++++++---------- modules/sdcore-user-plane-k8s/variables.tf | 10 ++----- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/modules/sdcore-user-plane-k8s/README.md b/modules/sdcore-user-plane-k8s/README.md index 6c49064..de5d323 100644 --- a/modules/sdcore-user-plane-k8s/README.md +++ b/modules/sdcore-user-plane-k8s/README.md @@ -11,7 +11,7 @@ The module can be used to deploy the `sdcore-user-plane-k8s` separately as well - **main.tf** - Defines the Juju application to be deployed. - **variables.tf** - Allows customization of the deployment including Juju model name, charm's channel and configuration. - **output.tf** - Responsible for integrating the module with other Terraform modules, primarily by defining potential integration endpoints (charm integrations). -- **terraform.tf** - Defines the Terraform provider. +- **versions.tf** - Defines the Terraform provider. ## Deploying sdcore-user-plane-k8s module separately @@ -74,7 +74,11 @@ Create the `terraform.tfvars` file to specify the name of the Juju model to depl ```console cat << EOF | tee terraform.tfvars -model_name = "put your model-name here" +data "juju_model" "sdcore_upf_k8s" { + name = "sdcore_upf_k8s" +} + +model = data.juju_model.sdcore_upf_k8s.name # Customize the configuration variables here if needed EOF diff --git a/modules/sdcore-user-plane-k8s/main.tf b/modules/sdcore-user-plane-k8s/main.tf index 54f5d32..b21404b 100644 --- a/modules/sdcore-user-plane-k8s/main.tf +++ b/modules/sdcore-user-plane-k8s/main.tf @@ -1,21 +1,21 @@ # Copyright 2024 Canonical Ltd. # See LICENSE file for licensing details. -resource "juju_model" "sdcore" { - count = var.create_model == true ? 1 : 0 - name = var.model_name +data "juju_model" "sdcore_upf" { + name = var.model } module "upf" { - source = "git::https://github.com/canonical/sdcore-upf-k8s-operator//terraform" - model_name = var.create_model == true ? juju_model.sdcore[0].name : var.model_name - channel = var.upf_channel - config = var.upf_config + source = "git::https://github.com/canonical/sdcore-upf-k8s-operator//terraform?ref=chore-cc006" + model = data.juju_model.sdcore_upf.name + channel = var.upf_channel + config = var.upf_config + constraints = "arch=amd64" } module "grafana-agent" { source = "../external/grafana-agent-k8s" - model_name = var.create_model == true ? juju_model.sdcore[0].name : var.model_name + model_name = data.juju_model.sdcore_upf.name channel = var.grafana_agent_channel config = var.grafana_agent_config } @@ -23,11 +23,11 @@ module "grafana-agent" { # Integrations for `metrics` endpoint resource "juju_integration" "upf-metrics" { - model = var.create_model == true ? juju_model.sdcore[0].name : var.model_name + model = data.juju_model.sdcore_upf.name application { name = module.upf.app_name - endpoint = module.upf.metrics_endpoint + endpoint = module.upf.provides.metrics } application { @@ -39,11 +39,11 @@ resource "juju_integration" "upf-metrics" { # Integrations for `logging` endpoint resource "juju_integration" "upf-logging" { - model = var.create_model == true ? juju_model.sdcore[0].name : var.model_name + model = data.juju_model.sdcore_upf.name application { name = module.upf.app_name - endpoint = module.upf.logging_endpoint + endpoint = module.upf.requires.logging } application { @@ -55,13 +55,15 @@ resource "juju_integration" "upf-logging" { # Cross-model integrations resource "juju_offer" "upf-fiveg-n3" { - model = var.model_name + model = data.juju_model.sdcore_upf.name application_name = module.upf.app_name - endpoint = module.upf.fiveg_n3_endpoint + endpoint = module.upf.provides.fiveg_n3 + name = "upf-fiveg-n3" } resource "juju_offer" "upf-fiveg-n4" { - model = var.model_name + model = data.juju_model.sdcore_upf.name application_name = module.upf.app_name - endpoint = module.upf.fiveg_n4_endpoint + endpoint = module.upf.provides.fiveg_n4 + name = "upf-fiveg-n4" } diff --git a/modules/sdcore-user-plane-k8s/variables.tf b/modules/sdcore-user-plane-k8s/variables.tf index 613619a..8492a48 100644 --- a/modules/sdcore-user-plane-k8s/variables.tf +++ b/modules/sdcore-user-plane-k8s/variables.tf @@ -1,18 +1,12 @@ # Copyright 2024 Canonical Ltd. # See LICENSE file for licensing details. -variable "model_name" { - description = "Name of Juju model to deploy application to." +variable "model" { + description = "Reference to a juju_model to deploy application to." type = string default = "" } -variable "create_model" { - description = "Allows to skip Juju model creation and re-use a model created in a higher level module." - type = bool - default = true -} - variable "upf_channel" { description = "The channel to use when deploying `sdcore-upf-k8s` charm." type = string