Skip to content

Commit

Permalink
Add the Github workflow for the Terraform checks
Browse files Browse the repository at this point in the history
Signed-off-by: gatici <[email protected]>
  • Loading branch information
gatici committed Feb 9, 2024
1 parent cfd9304 commit cc28b4e
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 181 deletions.
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ assignees: ''
- 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

Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ jobs:
lint-report:
uses: canonical/sdcore-github-workflows/.github/workflows/lint-report.yaml@main

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

static-analysis:
uses: canonical/sdcore-github-workflows/.github/workflows/static-analysis.yaml@main

Expand Down
86 changes: 0 additions & 86 deletions terraform/CONTRIBUTING.md

This file was deleted.

78 changes: 32 additions & 46 deletions terraform/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,67 +6,53 @@ This SD-Core NRF K8s Terraform module aims to deploy the [sdcore-nrf-k8s charm](

### Prerequisites

The following software and tools needs to be installed and should be running in the local environment.
The following software and tools needs to be installed and should be running in the local environment. Please [set up your environment](https://discourse.charmhub.io/t/set-up-your-development-environment-with-microk8s-for-juju-terraform-provider/13109) before deployment.

- `microk8s`
- `juju 3.x`
- `terrafom`

### Deploy the sdcore-nrf-k8s charm using Terraform
### Module structure

Make sure that `storage` plugin is enabled for Microk8s:
- **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.

```console
sudo microk8s enable hostpath-storage
```

Add a Juju model:

```console
juju add model <model-name>
```

Initialise the provider:

```console
terraform init
```
## Using sdcore-nrf-k8s base module in higher level modules

Customize the configuration inputs under `terraform.tfvars` file according to requirement.
If you want to use `sdcore-nrf-k8s` base module as part of your Terraform module, import it like shown below.

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"
```text
module "sdcore-nrf-k8s" {
source = "git::https://github.com/canonical/sdcore-nrf-k8s-operator//terraform"
model_name = "juju_model_name"
# Optional Configurations
# channel = "put the Charm channel here"
# app_name = "put the application name here"
}
```

Run Terraform Plan by providing var-file:
Create the integrations, for instance:

```console
terraform plan -var-file="terraform.tfvars"
```
```text
resource "juju_integration" "nrf-db" {
model = var.model_name
Deploy the resources, skip the approval:
application {
name = module.nrf.app_name
endpoint = module.nrf.database_endpoint
}
```console
terraform apply -auto-approve
application {
name = module.mongodb.app_name
endpoint = module.mongodb.database_endpoint
}
}
```

### Check the Output
Please check the available [integration pairs](https://charmhub.io/sdcore-nrf-k8s/integrations).

Run `juju switch <juju model>` to switch to the target Juju model and observe the status of the application.

```console
juju status --relations
```
[Terraform](https://www.terraform.io/)

### Clean up

Remove the application:

```console
terraform destroy -auto-approve
```
[Terraform Juju provider](https://registry.terraform.io/providers/juju/juju/latest)
34 changes: 5 additions & 29 deletions terraform/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
resource "juju_application" "nrf" {
name = "nrf"
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

resource "juju_application" "sdcore-nrf-k8s" {
name = var.app_name
model = var.model_name

charm {
Expand All @@ -10,31 +13,4 @@ resource "juju_application" "nrf" {
trust = true
}

resource "juju_integration" "nrf-db" {
model = var.model_name

application {
name = juju_application.nrf.name
endpoint = "database"
}

application {
name = var.db_application_name
endpoint = "database"
}
}

resource "juju_integration" "nrf-certs" {
model = var.model_name

application {
name = juju_application.nrf.name
endpoint = "certificates"
}

application {
name = var.certs_application_name
endpoint = "certificates"
}
}

24 changes: 21 additions & 3 deletions terraform/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
output "nrf_application_name" {
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

output "app_name" {
description = "Name of the deployed application."
value = juju_application.nrf.name
}
value = juju_application.sdcore-nrf-k8s.name
}

output "database_endpoint" {
description = "Name of the endpoint to integrate with MongoDB using mongodb_client interface."
value = "database"
}

output "certificates_endpoint" {
description = "Name of the endpoint to get the X.509 certificate using tls-certificates interface."
value = "certificates"
}

output "fiveg_nrf_endpoint" {
description = "Name of the endpoint to provide fiveg_nrf interface."
value = "fiveg-nrf"
}
7 changes: 0 additions & 7 deletions terraform/terraform.tfvars

This file was deleted.

17 changes: 7 additions & 10 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

variable "model_name" {
description = "Name of Juju model to deploy application to."
type = string
Expand All @@ -10,14 +13,8 @@ variable "channel" {
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 = ""
}

variable "certs_application_name" {
description = "Name of the application providing the `certificates` integration endpoint."
type = string
default = ""
}
default = "nrf"
}

0 comments on commit cc28b4e

Please sign in to comment.