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 58a46ad commit e943363
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 40 deletions.
12 changes: 8 additions & 4 deletions terraform/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,22 @@ 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 sdcore-pcf-k8s base module in higher level modules

If you want to use `sdcore-pcf-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 "pcf" {
source = "git::https://github.com/canonical/sdcore-pcf-k8s-operator//terraform"
model_name = "juju_model_name"
model = juju_model.my_model.name
}
```

Expand All @@ -38,11 +42,11 @@ resource "juju_integration" "pcf-nrf" {
model = var.model_name
application {
name = module.pcf.app_name
endpoint = module.pcf.fiveg_nrf_endpoint
endpoint = module.pcf.requires.fiveg_nrf
}
application {
name = module.nrf.app_name
endpoint = module.nrf.fiveg_nrf_endpoint
endpoint = module.nrf.provides.fiveg_nrf
}
}
```
Expand Down
14 changes: 9 additions & 5 deletions terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@

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

charm {
name = "sdcore-pcf-k8s"
channel = var.channel
name = "sdcore-pcf-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
}
36 changes: 11 additions & 25 deletions terraform/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,17 @@ output "app_name" {
value = juju_application.pcf.name
}

# Required integration endpoints

output "fiveg_nrf_endpoint" {
description = "Name of the endpoint used to integrate with the NRF."
value = "fiveg_nrf"
}

output "certificates_endpoint" {
description = "Name of the endpoint used to integrate with the TLS certificates provider."
value = "certificates"
output "requires" {
value = {
fiveg_nrf = "fiveg_nrf"
certificates = "certificates"
logging = "logging"
sdcore_config = "sdcore_config"
}
}

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

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

# Provided integration endpoints

output "metrics_endpoint" {
description = "Exposes the Prometheus metrics endpoint providing telemetry about the PCF instance."
value = "metrics-endpoint"
}
48 changes: 42 additions & 6 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
# Copyright 2024 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 @@ -18,3 +12,45 @@ variable "channel" {
type = string
default = "1.5/edge"
}

variable "config" {
description = "Application config. Details about available options can be found at https://charmhub.io/sdcore-pcf-k8s-operator/configure."
type = map(string)
default = {}
}

variable "constraints" {
description = "Juju constraints to apply for this application."
type = string
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-pcf-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 e943363

Please sign in to comment.