diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 584d35d..1d9e946 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -32,6 +32,7 @@ assignees: '' - Juju version (output from `juju --version`): - Cloud Environment: - Kubernetes version (output from `kubectl version --short`): +- Terraform version (output from `terraform version`): #### Additional context diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 097cc01..08050c2 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -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 diff --git a/.gitignore b/.gitignore index 2aa0330..ef310eb 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/terraform/README.md b/terraform/README.md new file mode 100644 index 0000000..7f6bb31 --- /dev/null +++ b/terraform/README.md @@ -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 diff --git a/terraform/main.tf b/terraform/main.tf new file mode 100644 index 0000000..3332591 --- /dev/null +++ b/terraform/main.tf @@ -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 +} + + diff --git a/terraform/outputs.tf b/terraform/outputs.tf new file mode 100644 index 0000000..9d5ec52 --- /dev/null +++ b/terraform/outputs.tf @@ -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" +} diff --git a/terraform/terraform.tf b/terraform/terraform.tf new file mode 100644 index 0000000..4f60bb4 --- /dev/null +++ b/terraform/terraform.tf @@ -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" + } + } +} diff --git a/terraform/variables.tf b/terraform/variables.tf new file mode 100644 index 0000000..67614d7 --- /dev/null +++ b/terraform/variables.tf @@ -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" +} \ No newline at end of file