From 93d25dcd9cf5a81064e85895cf11e615b7322fe6 Mon Sep 17 00:00:00 2001 From: Daniela Plascencia Date: Thu, 19 Sep 2024 00:03:33 +0200 Subject: [PATCH 1/7] feat: add Terraform module for namespace-node-affinity This commit adds the terraform/ directory to the root of the repository to host the Terraform module of this charm. This follows the standard set in CC006. For more information please also refer to canonical/argo-operators/pull/198. Fixes #46 --- .github/workflows/integrate.yaml | 8 ++++ terraform/README.md | 63 ++++++++++++++++++++++++++++++++ terraform/main.tf | 13 +++++++ terraform/variables.tf | 34 +++++++++++++++++ terraform/versions.tf | 9 +++++ tox.ini | 7 ++++ 6 files changed, 134 insertions(+) create mode 100644 terraform/README.md create mode 100644 terraform/main.tf create mode 100644 terraform/variables.tf create mode 100644 terraform/versions.tf diff --git a/.github/workflows/integrate.yaml b/.github/workflows/integrate.yaml index 3ec1063..edc249a 100644 --- a/.github/workflows/integrate.yaml +++ b/.github/workflows/integrate.yaml @@ -51,6 +51,14 @@ jobs: - name: Run unit tests run: tox -e unit + terraform-checks: + name: Terraform + uses: canonical/charmed-kubeflow-workflows/.github/workflows/terraform-checks.yaml@main + with: + charm-path: . + model: kubeflow + channel: latest/edge + deploy: name: Integration Test runs-on: ubuntu-20.04 diff --git a/terraform/README.md b/terraform/README.md new file mode 100644 index 0000000..a1e3800 --- /dev/null +++ b/terraform/README.md @@ -0,0 +1,63 @@ +# Terraform module for namespace-node-affinity + +This is a Terraform module facilitating the deployment of the namespace-node-affinity charm, using the [Terraform juju provider](https://github.com/juju/terraform-provider-juju/). For more information, refer to the provider [documentation](https://registry.terraform.io/providers/juju/juju/latest/docs). + +## Compatibility +This terraform module is compatible with charms of version >= 1.8 due to changes in the charm's relations. + +## Requirements +This module requires a `juju` model to be available. Refer to the [usage section](#usage) below for more details. + +## API + +### Inputs +The module offers the following configurable inputs: + +| Name | Type | Description | Required | +| - | - | - | - | +| `app_name`| string | Application name | False | +| `channel`| string | Channel that the charm is deployed from | False | +| `config`| map(string) | Map of the charm configuration options | False | +| `model_name`| string | Name of the model that the charm is deployed on | True | +| `resources`| map(string) | Map of the charm resources | False | +| `revision`| number | Revision number of the charm name | False | + +### Outputs +Upon applied, the module exports the following outputs: + +| Name | Description | +| - | - | +| `app_name`| Application name | +| `provides`| Map of `provides` endpoints | +| `requires`| Map of `reqruires` endpoints | + +## Usage + +This module is intended to be used as part of a higher-level module. When defining one, users should ensure that Terraform is aware of the `juju_model` dependency of the charm module. There are two options to do so when creating a high-level module: + +### Define a `juju_model` resource +Define a `juju_model` resource and pass to the `model_name` input a reference to the `juju_model` resource's name. For example: + +``` +resource "juju_model" "testing" { + name = namespace-node-affinity-testing +} + +module "namespace-node-affinity" { + source = "" + model_name = juju_model.testing.name +} +``` + +### Define a `data` source +Define a `data` source and pass to the `model_name` input a reference to the `data.juju_model` resource's name. This will enable Terraform to look for a `juju_model` resource with a name attribute equal to the one provided, and apply only if this is present. Otherwise, it will fail before applying anything. +``` +data "juju_model" "testing" { + name = var.model_name +} + +module "namespace-node-affinity" { + source = "" + model_name = data.juju_model.testing.name +} +``` diff --git a/terraform/main.tf b/terraform/main.tf new file mode 100644 index 0000000..443b002 --- /dev/null +++ b/terraform/main.tf @@ -0,0 +1,13 @@ +resource "juju_application" "namespace_node_affinity" { + charm { + name = "namespace-node-affinity" + channel = var.channel + revision = var.revision + } + config = var.config + model = var.model_name + name = var.app_name + resources = var.resources + trust = true + units = 1 +} diff --git a/terraform/variables.tf b/terraform/variables.tf new file mode 100644 index 0000000..f12c968 --- /dev/null +++ b/terraform/variables.tf @@ -0,0 +1,34 @@ +variable "app_name" { + description = "Application name" + type = string + default = "namespace-node-affinity" +} + +variable "channel" { + description = "Charm channel" + type = string + default = null +} + +variable "config" { + description = "Map of charm configuration options" + type = map(string) + default = {} +} + +variable "model_name" { + description = "Model name" + type = string +} + +variable "resources" { + description = "Map of resources" + type = map(string) + default = null +} + +variable "revision" { + description = "Charm revision" + type = number + default = null +} diff --git a/terraform/versions.tf b/terraform/versions.tf new file mode 100644 index 0000000..eb357ca --- /dev/null +++ b/terraform/versions.tf @@ -0,0 +1,9 @@ +terraform { + required_version = ">= 1.6" + required_providers { + juju = { + source = "juju/juju" + version = "~> 0.14.0" + } + } +} diff --git a/tox.ini b/tox.ini index a6a86c6..0a6467c 100644 --- a/tox.ini +++ b/tox.ini @@ -78,3 +78,10 @@ commands = pytest -v --tb native --asyncio-mode=auto {[vars]tst_path}integration deps = -r requirements-integration.txt description = Run integration tests + +[testenv:tflint] +allowlist_externals = + tflint +commands = + tflint --chdir=terraform --recursive +description = Check Terraform code against coding style standards From c7e5e4b45dc03f474e129214d370e51ff15bcd36 Mon Sep 17 00:00:00 2001 From: Daniela Plascencia Date: Thu, 19 Sep 2024 17:40:25 +0200 Subject: [PATCH 2/7] skip: remove compatibility section --- terraform/README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/terraform/README.md b/terraform/README.md index a1e3800..4857aa1 100644 --- a/terraform/README.md +++ b/terraform/README.md @@ -2,9 +2,6 @@ This is a Terraform module facilitating the deployment of the namespace-node-affinity charm, using the [Terraform juju provider](https://github.com/juju/terraform-provider-juju/). For more information, refer to the provider [documentation](https://registry.terraform.io/providers/juju/juju/latest/docs). -## Compatibility -This terraform module is compatible with charms of version >= 1.8 due to changes in the charm's relations. - ## Requirements This module requires a `juju` model to be available. Refer to the [usage section](#usage) below for more details. From 636d331e703f1fe7ca798964016bf2da150a3e0e Mon Sep 17 00:00:00 2001 From: Daniela Plascencia Date: Fri, 20 Sep 2024 01:25:59 +0200 Subject: [PATCH 3/7] skip: remove model name --- .github/workflows/integrate.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/integrate.yaml b/.github/workflows/integrate.yaml index edc249a..19aa45e 100644 --- a/.github/workflows/integrate.yaml +++ b/.github/workflows/integrate.yaml @@ -56,7 +56,6 @@ jobs: uses: canonical/charmed-kubeflow-workflows/.github/workflows/terraform-checks.yaml@main with: charm-path: . - model: kubeflow channel: latest/edge deploy: From 5a931f68ab27b723048ee2119efc527a3d54544e Mon Sep 17 00:00:00 2001 From: Daniela Plascencia Date: Tue, 24 Sep 2024 04:35:37 +0200 Subject: [PATCH 4/7] skip: add outputs --- terraform/outputs.tf | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 terraform/outputs.tf diff --git a/terraform/outputs.tf b/terraform/outputs.tf new file mode 100644 index 0000000..9cc828a --- /dev/null +++ b/terraform/outputs.tf @@ -0,0 +1,3 @@ +output "app_name" { + value = juju_application.namespace_node_affinity.name +} From 15526ad6407e6e6b51b7fe9ace5adc2078b1625b Mon Sep 17 00:00:00 2001 From: Daniela Plascencia Date: Tue, 24 Sep 2024 04:36:34 +0200 Subject: [PATCH 5/7] skip: remove channel from wf --- .github/workflows/integrate.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/integrate.yaml b/.github/workflows/integrate.yaml index 19aa45e..4fb47d6 100644 --- a/.github/workflows/integrate.yaml +++ b/.github/workflows/integrate.yaml @@ -56,7 +56,6 @@ jobs: uses: canonical/charmed-kubeflow-workflows/.github/workflows/terraform-checks.yaml@main with: charm-path: . - channel: latest/edge deploy: name: Integration Test From 0b474ebcc853f5b92e1e8bcee11b125b96db3ccd Mon Sep 17 00:00:00 2001 From: Daniela Plascencia Date: Tue, 24 Sep 2024 04:49:05 +0200 Subject: [PATCH 6/7] skip: add provides/requires for consistency --- terraform/outputs.tf | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/terraform/outputs.tf b/terraform/outputs.tf index 9cc828a..b727271 100644 --- a/terraform/outputs.tf +++ b/terraform/outputs.tf @@ -1,3 +1,11 @@ output "app_name" { value = juju_application.namespace_node_affinity.name } + +output "provides" { + value = {} +} + +output "requires" { + value = {} +} From a68def75c0df65b10d5ca912c7d1eebb98370ceb Mon Sep 17 00:00:00 2001 From: Daniela Plascencia Date: Tue, 24 Sep 2024 13:56:39 +0200 Subject: [PATCH 7/7] skip: add gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..def1e7b --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.terraform* +*.tfstate*