Skip to content

Commit

Permalink
Refactors COS integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Gmerold committed Sep 30, 2024
1 parent 2b5b034 commit e346178
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 84 deletions.
14 changes: 14 additions & 0 deletions modules/external/cos-lite/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,17 @@ resource "juju_integration" "traefik-metrics" {
endpoint = module.prometheus.metrics_endpoint
}
}

# Cross-model integrations

resource "juju_offer" "prometheus-remote-write" {
model = var.model_name
application_name = module.prometheus.app_name
endpoint = module.prometheus.receive_remote_write_endpoint
}

resource "juju_offer" "loki-logging" {
model = var.model_name
application_name = module.loki.app_name
endpoint = module.loki.logging_endpoint
}
12 changes: 12 additions & 0 deletions modules/external/cos-lite/output.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,15 @@ output "traefik_app_name" {
description = "Name of the Traefik application in the Juju model."
value = module.traefik.app_name
}

# Cross-model integrations

output "prometheus_remote_write_offer_url" {
description = "The URL used to created cross-model relation to Prometheus's `remote-write` interface."
value = juju_offer.prometheus-remote-write.url
}

output "loki_logging_offer_url" {
description = "The URL used to created cross-model relation to Loki's `logging` interface."
value = juju_offer.loki-logging.url
}
23 changes: 8 additions & 15 deletions modules/sdcore-control-plane-k8s/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -786,21 +786,14 @@ resource "juju_integration" "nms-logging" {

# Cross-model integrations

resource "juju_offer" "prometheus-remote-write" {
count = var.deploy_cos ? 1 : 0
model = module.cos-lite[0].model_name
application_name = module.cos-lite[0].prometheus_app_name
endpoint = "receive-remote-write"
}
resource "juju_offer" "loki-logging" {
count = var.deploy_cos ? 1 : 0
model = module.cos-lite[0].model_name
application_name = module.cos-lite[0].loki_app_name
endpoint = "logging"
resource "juju_offer" "amf-fiveg-n2" {
model = var.model_name
application_name = module.amf.app_name
endpoint = module.amf.fiveg_n2_endpoint
}

resource "juju_integration" "prometheus" {
count = var.deploy_cos ? 1 : 0
count = var.deploy_cos || var.use_existing_cos ? 1 : 0
model = var.model_name

application {
Expand All @@ -809,12 +802,12 @@ resource "juju_integration" "prometheus" {
}

application {
offer_url = juju_offer.prometheus-remote-write[0].url
offer_url = length(module.cos-lite) != 0 ? module.cos-lite[0].prometheus_remote_write_offer_url : var.prometheus_remote_write_offer_url
}
}

resource "juju_integration" "loki" {
count = var.deploy_cos ? 1 : 0
count = var.deploy_cos || var.use_existing_cos ? 1 : 0
model = var.model_name

application {
Expand All @@ -823,6 +816,6 @@ resource "juju_integration" "loki" {
}

application {
offer_url = juju_offer.loki-logging[0].url
offer_url = length(module.cos-lite) != 0 ? module.cos-lite[0].loki_logging_offer_url : var.loki_logging_offer_url
}
}
11 changes: 4 additions & 7 deletions modules/sdcore-control-plane-k8s/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

output "amf_app_name" {
description = "Name of the deployed AMF application."
value = module.amf.app_name
}
# Cross-model integrations

output "fiveg_n2_endpoint" {
description = "Name of the endpoint used to provide information on connectivity to the N2 plane."
value = module.amf.fiveg_n2_endpoint
output "amf_fiveg_n2_offer_url" {
description = ""
value = juju_offer.amf-fiveg-n2.url
}

output "nms_app_name" {
Expand Down
2 changes: 1 addition & 1 deletion modules/sdcore-control-plane-k8s/terraform.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ terraform {
required_providers {
juju = {
source = "juju/juju"
version = ">= 0.11.0"
version = ">= 0.12.0"
}
}
}
30 changes: 29 additions & 1 deletion modules/sdcore-control-plane-k8s/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,39 @@ variable "deploy_cos" {
type = bool
default = false
}
variable "use_existing_cos" {
description = ""
type = bool
default = false
}

variable "cos_model_name" {
description = "Name of Juju model to deploy COS to."
description = "Name of COS Juju model. This model will be created if `deploy_cos` is set to true or used as a source when integrating with existing COS deployment."
type = string
default = "cos-lite"
}

variable "prometheus_remote_write_offer_url" {
description = "URL of Prometheus's `remote_write` offer. This variable is used to integrate with an existing COS deployment."
type = string
default = ""

validation {
condition = var.use_existing_cos && length(var.prometheus_remote_write_offer_url) != 0
error_message = "Variable `prometheus_remote_write_offer_url` is required."
}
}
variable "loki_logging_offer_url" {
description = "URL of Loki's `logging` offer. This variable is used to integrate with an existing COS deployment."
type = string
default = ""

validation {
condition = var.use_existing_cos && length(var.loki_logging_offer_url) != 0
error_message = "Variable `loki_logging_offer_url` is required."
}
}

variable "cos_configuration_config" {
description = "COS Configuration application config. Details about available options can be found at https://charmhub.io/cos-configuration-k8s/configure."
type = map(string)
Expand Down
23 changes: 8 additions & 15 deletions modules/sdcore-k8s/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -837,21 +837,14 @@ resource "juju_integration" "upf-nms" {

# Cross-model integrations

resource "juju_offer" "prometheus-remote-write" {
count = var.deploy_cos ? 1 : 0
model = module.cos-lite[0].model_name
application_name = module.cos-lite[0].prometheus_app_name
endpoint = "receive-remote-write"
}
resource "juju_offer" "loki-logging" {
count = var.deploy_cos ? 1 : 0
model = module.cos-lite[0].model_name
application_name = module.cos-lite[0].loki_app_name
endpoint = "logging"
resource "juju_offer" "amf-fiveg-n2" {
model = var.model_name
application_name = module.amf.app_name
endpoint = module.amf.fiveg_n2_endpoint
}

resource "juju_integration" "prometheus" {
count = var.deploy_cos ? 1 : 0
count = var.deploy_cos || var.use_existing_cos ? 1 : 0
model = var.model_name

application {
Expand All @@ -860,12 +853,12 @@ resource "juju_integration" "prometheus" {
}

application {
offer_url = juju_offer.prometheus-remote-write[0].url
offer_url = length(module.cos-lite) != 0 ? module.cos-lite[0].prometheus_remote_write_offer_url : var.prometheus_remote_write_offer_url
}
}

resource "juju_integration" "loki" {
count = var.deploy_cos ? 1 : 0
count = var.deploy_cos || var.use_existing_cos ? 1 : 0
model = var.model_name

application {
Expand All @@ -874,6 +867,6 @@ resource "juju_integration" "loki" {
}

application {
offer_url = juju_offer.loki-logging[0].url
offer_url = length(module.cos-lite) != 0 ? module.cos-lite[0].loki_logging_offer_url : var.loki_logging_offer_url
}
}
31 changes: 3 additions & 28 deletions modules/sdcore-k8s/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

output "amf_app_name" {
description = "Name of the deployed AMF application."
value = module.amf.app_name
}

output "fiveg_n2_endpoint" {
description = "Name of the endpoint used to provide information on connectivity to the N2 plane."
value = module.amf.fiveg_n2_endpoint
output "amf_fiveg_n2_offer_url" {
description = ""
value = juju_offer.amf-fiveg-n2.url
}

output "nms_app_name" {
Expand All @@ -21,21 +16,6 @@ output "fiveg_gnb_identity_endpoint" {
value = module.nms.fiveg_gnb_identity_endpoint
}

output "grafana_agent_app_name" {
description = "Name of the deployed Grafana-agent application."
value = module.grafana-agent.app_name
}

output "send_remote_write_endpoint" {
description = "Name of the endpoint to forward client charms metrics and associated alert rules to Prometheus using prometheus_remote_write interface."
value = module.grafana-agent.send_remote_write_endpoint
}

output "logging_consumer_endpoint" {
description = "Name of the endpoint to send the logs to Loki using loki_push_api interface."
value = module.grafana-agent.logging_consumer_endpoint
}

output "upf_app_name" {
description = "Name of the deployed UPF application."
value = module.upf.app_name
Expand All @@ -45,8 +25,3 @@ output "fiveg_n3_endpoint" {
description = "Name of the endpoint used to provide information on connectivity to the N3 plane."
value = module.upf.fiveg_n3_endpoint
}

output "fiveg_n4_endpoint" {
description = "Name of the endpoint used to provide information on connectivity to the N4 plane."
value = module.upf.fiveg_n4_endpoint
}
2 changes: 1 addition & 1 deletion modules/sdcore-k8s/terraform.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ terraform {
required_providers {
juju = {
source = "juju/juju"
version = ">= 0.11.0"
version = ">= 0.12.0"
}
}
}
30 changes: 29 additions & 1 deletion modules/sdcore-k8s/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,39 @@ variable "deploy_cos" {
type = bool
default = false
}
variable "use_existing_cos" {
description = "Allows integrating with an existing COS deployment. When set to `true`, `cos_model_name`, `prometheus_remote_write_offer_url` and `loki_logging_offer_url` are required."
type = bool
default = false
}

variable "cos_model_name" {
description = "Name of Juju model to deploy COS to."
description = "Name of COS Juju model. This model will be created if `deploy_cos` is set to true or used as a source when integrating with existing COS deployment."
type = string
default = "cos-lite"
}

variable "prometheus_remote_write_offer_url" {
description = "URL of Prometheus's `remote_write` offer. This variable is used to integrate with an existing COS deployment."
type = string
default = ""

validation {
condition = var.use_existing_cos && length(var.prometheus_remote_write_offer_url) != 0
error_message = "Variable `prometheus_remote_write_offer_url` is required."
}
}
variable "loki_logging_offer_url" {
description = "URL of Loki's `logging` offer. This variable is used to integrate with an existing COS deployment."
type = string
default = ""

validation {
condition = var.use_existing_cos && length(var.loki_logging_offer_url) != 0
error_message = "Variable `loki_logging_offer_url` is required."
}
}

variable "cos_configuration_config" {
description = "COS Configuration application config. Details about available options can be found at https://charmhub.io/cos-configuration-k8s/configure."
type = map(string)
Expand Down
17 changes: 2 additions & 15 deletions modules/sdcore-user-plane-k8s/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,6 @@ resource "juju_integration" "upf-logging" {

# Cross-model integrations

resource "juju_offer" "prometheus-remote-write" {
count = var.deploy_cos ? 1 : 0
model = module.cos-lite[0].model_name
application_name = module.cos-lite[0].prometheus_app_name
endpoint = "receive-remote-write"
}
resource "juju_offer" "loki-logging" {
count = var.deploy_cos ? 1 : 0
model = module.cos-lite[0].model_name
application_name = module.cos-lite[0].loki_app_name
endpoint = "logging"
}

resource "juju_integration" "prometheus" {
count = var.deploy_cos ? 1 : 0
model = var.model_name
Expand All @@ -85,7 +72,7 @@ resource "juju_integration" "prometheus" {
}

application {
offer_url = juju_offer.prometheus-remote-write[0].url
offer_url = module.cos-lite[0].prometheus_remote_write_offer_url
}
}

Expand All @@ -99,6 +86,6 @@ resource "juju_integration" "loki" {
}

application {
offer_url = juju_offer.loki-logging[0].url
offer_url = module.cos-lite[0].loki_logging_offer_url
}
}

0 comments on commit e346178

Please sign in to comment.