diff --git a/terraform/CONTRIBUTING.md b/terraform/CONTRIBUTING.md deleted file mode 100644 index 9a421a2..0000000 --- a/terraform/CONTRIBUTING.md +++ /dev/null @@ -1,86 +0,0 @@ -# Contributing - -## Development environment - -### Prerequisites - -Make sure the following software and tools are installed in the development -environment. - -- `microk8s` -- `juju` -- `terraform` - -### Prepare Development Environment - -Install Microk8s: - -```console -sudo snap install microk8s --channel=1.27-strict/stable -sudo usermod -a -G snap_microk8s $USER -newgrp snap_microk8s -``` - -Enable `storage` plugin for Microk8s: - -```console -sudo microk8s enable hostpath-storage -``` - -Install Juju: - -```console -sudo snap install juju --channel=3.1/stable -``` - -Install Terraform: - -```console -sudo snap install --classic terraform -``` - -Bootstrap the Juju Controller using Microk8s: - -```console -juju bootstrap microk8s -``` - -Add a Juju model: - -```console -juju add model -```` - -### Terraform provider - -The Terraform module uses the Juju provider to provision Juju resources. Please refer to the [Juju provider documentation](https://registry.terraform.io/providers/juju/juju/latest/docs) for more information. - -A Terraform working directory needs to be initialized at the beginning. - -Initialise the provider: - -```console -terraform init -``` - -## Testing - -Terraform CLI provides various ways to do formatting and validation. - -Formats to a canonical format and style: - -```console -terraform fmt -``` - -Check the syntactical validation: - -```console -terraform validate -``` - -Preview the changes: - -```console -terraform plan -``` diff --git a/terraform/README.md b/terraform/README.md index 5110ef1..e4cb4af 100644 --- a/terraform/README.md +++ b/terraform/README.md @@ -1,73 +1,55 @@ -# SD-Core PCF K8s Terraform Module +# SD-Core PCF K8s Terraform module -This SD-Core PCF K8s Terraform module aims to deploy the [sdcore-pcf-k8s charm](https://charmhub.io/sdcore-pcf-k8s) via Terraform. +This folder contains a base [Terraform][Terraform] module for the sdcore-pcf-k8s charm. -## Getting Started +The module uses the [Terraform Juju provider][Terraform Juju provider] to model the charm +deployment onto any Kubernetes environment managed by [Juju][Juju]. -### Prerequisites +The base module is not intended to be deployed in separation (it is possible though), but should +rather serve as a building block for higher level modules. -The following software and tools needs to be installed and should be running in the local environment. +## Module structure -- `microk8s` -- `juju 3.x` -- `terrafom` +- **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 models the charm 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. -### Deploy the sdcore-pcf-k8s charm using Terraform +## Using sdcore-pcf-k8s base module in higher level modules -Make sure that `storage` plugin is enabled for Microk8s: +If you want to use `sdcore-pcf-k8s` base module as part of your Terraform module, import it +like shown below: -```console -sudo microk8s enable hostpath-storage +```text +module "pcf" { + source = "git::https://github.com/canonical/sdcore-pcf-k8s-operator//terraform" + + model_name = "juju_model_name" +} ``` -Add a Juju model: +Create integrations, for instance: -```console -juju add model +```text +resource "juju_integration" "pcf-nrf" { + model = var.model_name + application { + name = module.pcf.app_name + endpoint = module.pcf.fiveg_nrf_endpoint + } + application { + name = module.nrf.app_name + endpoint = module.nrf.fiveg_nrf_endpoint + } +} ``` -Initialise the provider: +The complete list of available integrations can be found [here][pcf-integrations]. -```console -terraform init -``` - -Customize the configuration inputs under `terraform.tfvars` file according to requirement. - -Replace the values in the `terraform.tfvars` file: - -```yaml -# Mandatory Config Options -model_name = "put your model-name here" -db_application_name = "put your MongoDB app name here" -certs_application_name = "put your Self Signed Certificates app name here" -nrf_application_name = "put your NRF app name here" -``` - -Create the Terraform Plan: - -```console -terraform plan -var-file="terraform.tfvars" -``` - -Deploy the resources: - -```console -terraform apply -auto-approve -``` - -### Check the Output - -Run `juju switch ` to switch to the target Juju model and observe the status of the applications. - -```console -juju status --relations -``` - -### Clean up - -Destroy the deployment: - -```console -terraform destroy -auto-approve -``` +[Terraform]: https://www.terraform.io/ +[Terraform Juju provider]: https://registry.terraform.io/providers/juju/juju/latest +[Juju]: https://juju.is +[pcf-integrations]: https://charmhub.io/sdcore-pcf-k8s/integrations diff --git a/terraform/main.tf b/terraform/main.tf index 63b16a0..00323b8 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -1,5 +1,8 @@ +# Copyright 2024 Canonical Ltd. +# See LICENSE file for licensing details. + resource "juju_application" "pcf" { - name = "pcf" + name = var.app_name model = var.model_name charm { @@ -10,46 +13,3 @@ resource "juju_application" "pcf" { units = 1 trust = true } - -resource "juju_integration" "pcf-db" { - model = var.model_name - - application { - name = juju_application.pcf.name - endpoint = "database" - } - - application { - name = var.db_application_name - endpoint = "database" - } -} - -resource "juju_integration" "pcf-certs" { - model = var.model_name - - application { - name = juju_application.pcf.name - endpoint = "certificates" - } - - application { - name = var.certs_application_name - endpoint = "certificates" - } -} - -resource "juju_integration" "pcf-nrf" { - model = var.model_name - - application { - name = juju_application.pcf.name - endpoint = "fiveg_nrf" - } - - application { - name = var.nrf_application_name - endpoint = "fiveg-nrf" - } -} - diff --git a/terraform/outputs.tf b/terraform/outputs.tf index 7055bf3..4d7b512 100644 --- a/terraform/outputs.tf +++ b/terraform/outputs.tf @@ -1,4 +1,24 @@ -output "pcf_application_name" { +# Copyright 2024 Canonical Ltd. +# See LICENSE file for licensing details. + +output "app_name" { description = "Name of the deployed application." value = juju_application.pcf.name -} \ No newline at end of file +} + +# Required integration endpoints + +output "fiveg_nrf_endpoint" { + description = "Name of the endpoint used to integrate with the NRF." + value = "fiveg-nrf" +} + +output "database_endpoint" { + description = "Name of the endpoint used to integrate with the database." + value = "database" +} + +output "certificates_endpoint" { + description = "Name of the endpoint used to integrate with the TLS certificates provider." + value = "certificates" +} diff --git a/terraform/terraform.tfvars b/terraform/terraform.tfvars deleted file mode 100644 index 48e913e..0000000 --- a/terraform/terraform.tfvars +++ /dev/null @@ -1,8 +0,0 @@ -# Mandatory Config Options -model_name = "put your model-name here" -db_application_name = "put your MongoDB app name here" -certs_application_name = "put your Self Signed Certificates app name here" -nrf_application_name = "put your NRF app name here" - -# Optional Configuration -channel = "put the charm channel here" diff --git a/terraform/variables.tf b/terraform/variables.tf index 2e8271a..3b55565 100644 --- a/terraform/variables.tf +++ b/terraform/variables.tf @@ -1,29 +1,20 @@ +# 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 "channel" { - description = "The channel to use when deploying a charm." - type = string - default = "1.3/edge" -} - -variable "db_application_name" { - description = "The name of the application providing the `database` endpoint." +variable "app_name" { + description = "Name of the application in the Juju model." type = string - default = "" + default = "pcf" } -variable "certs_application_name" { - description = "Name of the application providing the `certificates` integration endpoint." +variable "channel" { + description = "The channel to use when deploying a charm." type = string - default = "" + default = "1.3/edge" } - -variable "nrf_application_name" { - description = "The name of the application providing the `fiveg_nrf` endpoint." - type = string - default = "" -} \ No newline at end of file