-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Adding the Terraform module (#53)
Signed-off-by: gatici <gulsum.atici@canonical.com>
- Loading branch information
Showing
10 changed files
with
306 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
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
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,86 @@ | ||
# 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 <model-name> | ||
```` | ||
|
||
### 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 | ||
``` |
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,73 @@ | ||
# 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. | ||
|
||
## Getting Started | ||
|
||
### Prerequisites | ||
|
||
The following software and tools needs to be installed and should be running in the local environment. | ||
|
||
- `microk8s` | ||
- `juju 3.x` | ||
- `terrafom` | ||
|
||
### Deploy the sdcore-pcf-k8s charm using Terraform | ||
|
||
Make sure that `storage` plugin is enabled for Microk8s: | ||
|
||
```console | ||
sudo microk8s enable hostpath-storage | ||
``` | ||
|
||
Add a Juju model: | ||
|
||
```console | ||
juju add model <model-name> | ||
``` | ||
|
||
Initialise the provider: | ||
|
||
```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 | ||
``` |
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,55 @@ | ||
resource "juju_application" "pcf" { | ||
name = "pcf" | ||
model = var.model_name | ||
|
||
charm { | ||
name = "sdcore-pcf-k8s" | ||
channel = var.channel | ||
} | ||
|
||
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" | ||
} | ||
} | ||
|
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,4 @@ | ||
output "pcf_application_name" { | ||
description = "Name of the deployed application." | ||
value = juju_application.pcf.name | ||
} |
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,8 @@ | ||
# 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" |
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,29 @@ | ||
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." | ||
type = string | ||
default = "" | ||
} | ||
|
||
variable "certs_application_name" { | ||
description = "Name of the application providing the `certificates` integration endpoint." | ||
type = string | ||
default = "" | ||
} | ||
|
||
variable "nrf_application_name" { | ||
description = "The name of the application providing the `fiveg_nrf` endpoint." | ||
type = string | ||
default = "" | ||
} |