Skip to content

Commit

Permalink
feat: Adding Terraform module for UPF (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gmerold authored Feb 12, 2024
1 parent f5de921 commit 64215b4
Show file tree
Hide file tree
Showing 7 changed files with 218 additions and 0 deletions.
39 changes: 39 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
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. -->
3 changes: 3 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ jobs:
static-analysis:
uses: canonical/sdcore-github-workflows/.github/workflows/static-analysis.yaml@main

terraform-check:
uses: canonical/sdcore-github-workflows/.github/workflows/terraform.yaml@main

unit-tests-with-coverage:
uses: canonical/sdcore-github-workflows/.github/workflows/unit-test.yaml@main

Expand Down
100 changes: 100 additions & 0 deletions terraform/README.md
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
15 changes: 15 additions & 0 deletions terraform/main.tf
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
}
24 changes: 24 additions & 0 deletions terraform/outputs.tf
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"
}
11 changes: 11 additions & 0 deletions terraform/terraform.tf
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"
}
}
}
26 changes: 26 additions & 0 deletions terraform/variables.tf
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 = {}
}

0 comments on commit 64215b4

Please sign in to comment.