diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 00000000..1d9e946a --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,39 @@ +--- +name: Bug report +about: Create a bug report to help us improve +title: "" +labels: ["bug"] +assignees: '' +--- + +#### Describe the bug + + +#### To Reproduce + + +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +#### Expected behavior + + +#### Screenshots + + +#### Logs + + +#### Environment + +- Charm / library version (if relevant): +- Juju version (output from `juju --version`): +- Cloud Environment: +- Kubernetes version (output from `kubectl version --short`): +- Terraform version (output from `terraform version`): + +#### Additional context + + diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 51293394..11b073ff 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -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 diff --git a/terraform/README.md b/terraform/README.md new file mode 100644 index 00000000..abcb8976 --- /dev/null +++ b/terraform/README.md @@ -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 diff --git a/terraform/main.tf b/terraform/main.tf new file mode 100644 index 00000000..2ed1117e --- /dev/null +++ b/terraform/main.tf @@ -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 +} diff --git a/terraform/outputs.tf b/terraform/outputs.tf new file mode 100644 index 00000000..d3b227c7 --- /dev/null +++ b/terraform/outputs.tf @@ -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" +} diff --git a/terraform/terraform.tf b/terraform/terraform.tf new file mode 100644 index 00000000..4f60bb46 --- /dev/null +++ b/terraform/terraform.tf @@ -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" + } + } +} diff --git a/terraform/variables.tf b/terraform/variables.tf new file mode 100644 index 00000000..2177a591 --- /dev/null +++ b/terraform/variables.tf @@ -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 = {} +}