Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adding the Terraform module #68

Merged
merged 2 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
55 changes: 48 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,52 @@
*.idea
.vscode/
.coverage
.tox/
venv/
build/
*.charm
.tox/
.coverage
__pycache__/
*.py[cod]
.idea
.vscode/

# Python
**/venv/**
*.pyc
.python-version
.mypy_cache/
__pycache__/

# Charmcraft
*.charm

# Local .terraform directories
**/.terraform/*

# .tfstate files
*.tfstate
*.tfstate.*

# Crash log files
crash.log
crash.*.log

# Exclude all .tfvars files, which are likely to contain sensitive data, such as
# password, private keys, and other secrets. These should not be part of version
# control as they are data points which are potentially sensitive and subject
# to change depending on the environment.
*.tfvars
*.tfvars.json

# Ignore override files as they are usually used to override resources locally and so
# are not checked in
override.tf
override.tf.json
*_override.tf
*_override.tf.json

# Include override files you do wish to add to version control using negated pattern
# !example_override.tf

# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*

# Ignore CLI configuration files
.terraformrc
terraform.rc
.terraform.lock.hcl
53 changes: 53 additions & 0 deletions terraform/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# SD-Core NRF K8s Terraform Module

This folder contains a base [Terraform][Terraform] module for the sdcore-nrf-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 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.

## Module structure

- **main.tf** - Defines the Juju application to be deployed.
- **variables.tf** - Allows customization of the deployment options (Juju model name, channel or application name).
- **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.

## Using sdcore-nrf-k8s base module in higher level modules

If you want to use `sdcore-nrf-k8s` base module as part of your Terraform module, import it like shown below.

```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"
}
```

Create the integrations, for instance:

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

application {
name = module.nrf.app_name
endpoint = module.nrf.database_endpoint
}

application {
name = module.mongodb.app_name
endpoint = module.mongodb.database_endpoint
}
}
```

The complete list of available integrations can be found [here][nrf-integrations].

[Terraform]: https://www.terraform.io/
[Terraform Juju provider]: https://registry.terraform.io/providers/juju/juju/latest
[Juju]: https://juju.is
[nrf-integrations]: https://charmhub.io/sdcore-nrf-k8s/integrations
16 changes: 16 additions & 0 deletions terraform/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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 {
name = "sdcore-nrf-k8s"
channel = var.channel
}
units = 1
trust = true
}


22 changes: 22 additions & 0 deletions terraform/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

output "app_name" {
description = "Name of the deployed application."
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"
}
11 changes: 11 additions & 0 deletions terraform/terraform.tf
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"
}
}
}
20 changes: 20 additions & 0 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +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 "app_name" {
description = "Name of the application in the Juju model"
type = string
default = "nrf"
}
Loading