Skip to content

Commit

Permalink
chore: Updating Terraform module (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gmerold authored Feb 12, 2024
1 parent 0278b89 commit ac54f44
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 217 deletions.
86 changes: 0 additions & 86 deletions terraform/CONTRIBUTING.md

This file was deleted.

100 changes: 41 additions & 59 deletions terraform/README.md
Original file line number Diff line number Diff line change
@@ -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 <model-name>
```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 <juju model>` 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
48 changes: 4 additions & 44 deletions terraform/main.tf
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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"
}
}

24 changes: 22 additions & 2 deletions terraform/outputs.tf
Original file line number Diff line number Diff line change
@@ -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
}
}

# 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"
}
8 changes: 0 additions & 8 deletions terraform/terraform.tfvars

This file was deleted.

27 changes: 9 additions & 18 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -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 = ""
}

0 comments on commit ac54f44

Please sign in to comment.