-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Adding Terraform module for UPF (#89)
- Loading branch information
Showing
7 changed files
with
218 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--- | ||
name: Bug report | ||
about: Create a bug report to help us improve | ||
title: "" | ||
labels: ["bug"] | ||
assignees: '' | ||
--- | ||
|
||
#### Describe the bug | ||
<!-- A clear and concise description of what the bug is. --> | ||
|
||
#### To Reproduce | ||
<!-- Steps that can be taken to reproduce the behaviour --> | ||
|
||
1. Go to '...' | ||
2. Click on '....' | ||
3. Scroll down to '....' | ||
4. See error | ||
|
||
#### Expected behavior | ||
<!-- A clear and concise description of what you expected to happen. --> | ||
|
||
#### Screenshots | ||
<!-- If applicable, add screenshots to help explain your problem. --> | ||
|
||
#### Logs | ||
<!-- If applicable, add logs to help explain your problem. --> | ||
|
||
#### Environment | ||
|
||
- Charm / library version (if relevant): <!-- e.g. 1.2 --> | ||
- Juju version (output from `juju --version`): | ||
- Cloud Environment: <!-- e.g. GKE --> | ||
- Kubernetes version (output from `kubectl version --short`): | ||
- Terraform version (output from `terraform version`): | ||
|
||
#### Additional context | ||
|
||
<!-- Add any other context about the problem here. --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# SD-Core UPF K8s Terraform Module | ||
|
||
This folder contains a base [Terraform][Terraform] module for the sdcore-gnbsim-k8s charm. | ||
|
||
The module uses the [Terraform Juju provider][Terraform Juju provider] to model the charm | ||
deployment onto any Kubernetes environment managed by [Juju][Juju]. | ||
|
||
The module can be used to deploy the UPF separately as well as a part of a higher level module, | ||
depending on the deployment architecture. | ||
|
||
## Module structure | ||
|
||
- **main.tf** - Defines the Juju application to be deployed. | ||
- **variables.tf** - Allows customization of the deployment. Except for exposing the deployment | ||
options (Juju model name, channel or application name) also allows overwriting charm's default | ||
configuration. | ||
- **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. | ||
|
||
## Deploying sdcore-upf-k8s base module separately | ||
|
||
### Pre-requisites | ||
|
||
- A Kubernetes host with a CPU supporting AVX2 and RDRAND instructions (Intel Haswell, AMD Excavator or equivalent) | ||
- A Kubernetes cluster with the Multus addon enabled. | ||
- Juju 3.x | ||
- Juju controller bootstrapped onto the K8s cluster | ||
- Terraform | ||
|
||
### Deploying UPF with Terraform | ||
|
||
Clone the `sdcore-upf-k8s-operator` Git repository. | ||
|
||
From inside the `terraform` folder, initialize the provider: | ||
|
||
```shell | ||
terraform init | ||
``` | ||
|
||
Create Terraform plan: | ||
|
||
```shell | ||
terraform plan | ||
``` | ||
|
||
While creating the plan, the default configuration can be overwritten with `-var-file`. To do that, | ||
Terraform `tfvars` file should be prepared prior to the plan creation. | ||
|
||
Deploy UPF: | ||
|
||
```console | ||
terraform apply -auto-approve | ||
``` | ||
|
||
### Cleaning up | ||
|
||
Destroy the deployment: | ||
|
||
```shell | ||
terraform destroy -auto-approve | ||
``` | ||
|
||
## Using sdcore-upf-k8s base module in higher level modules | ||
|
||
If you want to use `sdcore-upf-k8s` base module as part of your Terraform module, import it | ||
like shown below: | ||
|
||
```text | ||
module "upf" { | ||
source = "git::https://github.com/canonical/sdcore-upf-k8s-operator//terraform" | ||
model_name = "juju_model_name" | ||
config = Optional config map | ||
} | ||
``` | ||
|
||
Create integrations, for instance: | ||
|
||
```text | ||
resource "juju_integration" "upf-prometheus" { | ||
model = var.model_name | ||
application { | ||
name = module.upf.app_name | ||
endpoint = module.upf.metrics_endpoint | ||
} | ||
application { | ||
name = module.prometheus.app_name | ||
endpoint = module.prometheus.metrics_endpoint | ||
} | ||
} | ||
``` | ||
|
||
The complete list of available integrations can be found [here][upf-integrations]. | ||
|
||
[Terraform]: https://www.terraform.io/ | ||
[Terraform Juju provider]: https://registry.terraform.io/providers/juju/juju/latest | ||
[Juju]: https://juju.is | ||
[upf-integrations]: https://charmhub.io/sdcore-upf-k8s/integrations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Copyright 2024 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
resource "juju_application" "upf" { | ||
name = var.app_name | ||
model = var.model_name | ||
|
||
charm { | ||
name = "sdcore-upf-k8s" | ||
channel = var.channel | ||
} | ||
config = var.config | ||
units = 1 | ||
trust = true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Copyright 2024 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
output "app_name" { | ||
description = "Name of the deployed application." | ||
value = juju_application.upf.name | ||
} | ||
|
||
# Provided integration endpoints | ||
|
||
output "metrics_endpoint" { | ||
description = "Exposes the Prometheus metrics endpoint providing telemetry about the UPF instance." | ||
value = "metrics-endpoint" | ||
} | ||
|
||
output "fiveg_n3_endpoint" { | ||
description = "Name of the endpoint used to provide information on connectivity to the N3 plane." | ||
value = "fiveg_n3" | ||
} | ||
|
||
output "fiveg_n4_endpoint" { | ||
description = "Name of the endpoint used to provide information on connectivity to the N4 plane." | ||
value = "fiveg_n4" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Copyright 2024 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
terraform { | ||
required_providers { | ||
juju = { | ||
source = "juju/juju" | ||
version = "~> 0.10.1" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# 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 | ||
default = "upf" | ||
} | ||
|
||
variable "channel" { | ||
description = "The channel to use when deploying a charm." | ||
type = string | ||
default = "1.3/edge" | ||
} | ||
|
||
variable "config" { | ||
description = "Application config. Details about available options can be found at https://charmhub.io/sdcore-upf-k8s-operator/configure." | ||
type = map(string) | ||
default = {} | ||
} |