From 1e126e4a769dc27fe3f4e9abd8a55675a762c50a Mon Sep 17 00:00:00 2001 From: Orfeas Kourkakis Date: Tue, 24 Sep 2024 15:06:29 +0300 Subject: [PATCH 1/3] feat: Add terraform modules for jupyter-{controller,ui} (#407) Create a `terraform/` directory for each of the charms that hosts their individual Terraform modules. It follows the structure proposed in [this spec](https://docs.google.com/document/d/1EG71A2pJ244PQRaGVzGj7Mx2B_bzE4U_OSqx4eeVI1E/edit) and it is based on what was done in canonical/argo-operators#198. Ref #405 Ref #404 --- .github/workflows/integrate.yaml | 9 +++ .gitignore | 3 + charms/jupyter-controller/terraform/README.md | 60 +++++++++++++++++++ charms/jupyter-controller/terraform/main.tf | 13 ++++ .../jupyter-controller/terraform/outputs.tf | 16 +++++ .../jupyter-controller/terraform/variables.tf | 34 +++++++++++ .../jupyter-controller/terraform/versions.tf | 9 +++ charms/jupyter-controller/tox.ini | 7 +++ charms/jupyter-ui/terraform/README.md | 60 +++++++++++++++++++ charms/jupyter-ui/terraform/main.tf | 13 ++++ charms/jupyter-ui/terraform/outputs.tf | 15 +++++ charms/jupyter-ui/terraform/variables.tf | 34 +++++++++++ charms/jupyter-ui/terraform/versions.tf | 9 +++ charms/jupyter-ui/tox.ini | 7 +++ 14 files changed, 289 insertions(+) create mode 100644 charms/jupyter-controller/terraform/README.md create mode 100644 charms/jupyter-controller/terraform/main.tf create mode 100644 charms/jupyter-controller/terraform/outputs.tf create mode 100644 charms/jupyter-controller/terraform/variables.tf create mode 100644 charms/jupyter-controller/terraform/versions.tf create mode 100644 charms/jupyter-ui/terraform/README.md create mode 100644 charms/jupyter-ui/terraform/main.tf create mode 100644 charms/jupyter-ui/terraform/outputs.tf create mode 100644 charms/jupyter-ui/terraform/variables.tf create mode 100644 charms/jupyter-ui/terraform/versions.tf diff --git a/.github/workflows/integrate.yaml b/.github/workflows/integrate.yaml index f5bcdf38..d439d84c 100644 --- a/.github/workflows/integrate.yaml +++ b/.github/workflows/integrate.yaml @@ -64,6 +64,15 @@ jobs: - run: sudo apt install tox - run: tox -e ${{ matrix.charm }}-lint + terraform-checks: + name: Terraform + uses: canonical/charmed-kubeflow-workflows/.github/workflows/terraform-checks.yaml@main + strategy: + matrix: + charm: [controller, ui] + with: + charm-path: ./charms/jupyter-${{ matrix.charm }} + bundle-integration: name: Bundle Integration runs-on: ubuntu-20.04 diff --git a/.gitignore b/.gitignore index 932895d0..9eaff386 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,6 @@ __pycache__ .coverage .idea geckodriver.log +venv/ +.terraform* +*.tfstate* diff --git a/charms/jupyter-controller/terraform/README.md b/charms/jupyter-controller/terraform/README.md new file mode 100644 index 00000000..d4daad85 --- /dev/null +++ b/charms/jupyter-controller/terraform/README.md @@ -0,0 +1,60 @@ +# Terraform module for jupyter-controller + +This is a Terraform module facilitating the deployment of the jupyter-controller 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). + +## 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 = kubeflow +} + +module "jupyter-controller" { + 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 "jupyter-controller" { + source = "" + model_name = data.juju_model.testing.name +} +``` diff --git a/charms/jupyter-controller/terraform/main.tf b/charms/jupyter-controller/terraform/main.tf new file mode 100644 index 00000000..becfc96d --- /dev/null +++ b/charms/jupyter-controller/terraform/main.tf @@ -0,0 +1,13 @@ +resource "juju_application" "jupyter_controller" { + charm { + name = "jupyter-controller" + 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/charms/jupyter-controller/terraform/outputs.tf b/charms/jupyter-controller/terraform/outputs.tf new file mode 100644 index 00000000..522b4459 --- /dev/null +++ b/charms/jupyter-controller/terraform/outputs.tf @@ -0,0 +1,16 @@ +output "app_name" { + value = juju_application.jupyter_controller.name +} + +output "provides" { + value = { + metrics_endpoint = "metrics-endpoint", + grafana_dashboard = "grafana-dashboard", + } +} + +output "requires" { + value = { + logging = "logging" + } +} diff --git a/charms/jupyter-controller/terraform/variables.tf b/charms/jupyter-controller/terraform/variables.tf new file mode 100644 index 00000000..4b1f2166 --- /dev/null +++ b/charms/jupyter-controller/terraform/variables.tf @@ -0,0 +1,34 @@ +variable "app_name" { + description = "Application name" + type = string + default = "jupyter-controller" +} + +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/charms/jupyter-controller/terraform/versions.tf b/charms/jupyter-controller/terraform/versions.tf new file mode 100644 index 00000000..eb357ca6 --- /dev/null +++ b/charms/jupyter-controller/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/charms/jupyter-controller/tox.ini b/charms/jupyter-controller/tox.ini index bc882ce9..f629b08e 100644 --- a/charms/jupyter-controller/tox.ini +++ b/charms/jupyter-controller/tox.ini @@ -64,6 +64,13 @@ deps = -r requirements-lint.txt description = Check code against coding style standards +[testenv:tflint] +allowlist_externals = + tflint +commands = + tflint --chdir=terraform --recursive +description = Check Terraform code against coding style standards + [testenv:unit] commands = coverage run --source={[vars]src_path} \ diff --git a/charms/jupyter-ui/terraform/README.md b/charms/jupyter-ui/terraform/README.md new file mode 100644 index 00000000..d497d5aa --- /dev/null +++ b/charms/jupyter-ui/terraform/README.md @@ -0,0 +1,60 @@ +# Terraform module for jupyter-ui + +This is a Terraform module facilitating the deployment of the jupyter-ui 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). + +## 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 = kubeflow +} + +module "jupyter-ui" { + 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 "jupyter-ui" { + source = "" + model_name = data.juju_model.testing.name +} +``` diff --git a/charms/jupyter-ui/terraform/main.tf b/charms/jupyter-ui/terraform/main.tf new file mode 100644 index 00000000..d5d97825 --- /dev/null +++ b/charms/jupyter-ui/terraform/main.tf @@ -0,0 +1,13 @@ +resource "juju_application" "jupyter_ui" { + charm { + name = "jupyter-ui" + 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/charms/jupyter-ui/terraform/outputs.tf b/charms/jupyter-ui/terraform/outputs.tf new file mode 100644 index 00000000..6f16874f --- /dev/null +++ b/charms/jupyter-ui/terraform/outputs.tf @@ -0,0 +1,15 @@ +output "app_name" { + value = juju_application.jupyter_ui.name +} + +output "provides" { + value = {} +} + +output "requires" { + value = { + ingress = "ingress", + dashboard_links = "dashboard-links", + logging = "logging", + } +} diff --git a/charms/jupyter-ui/terraform/variables.tf b/charms/jupyter-ui/terraform/variables.tf new file mode 100644 index 00000000..3d6c288a --- /dev/null +++ b/charms/jupyter-ui/terraform/variables.tf @@ -0,0 +1,34 @@ +variable "app_name" { + description = "Application name" + type = string + default = "jupyter-ui" +} + +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/charms/jupyter-ui/terraform/versions.tf b/charms/jupyter-ui/terraform/versions.tf new file mode 100644 index 00000000..eb357ca6 --- /dev/null +++ b/charms/jupyter-ui/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/charms/jupyter-ui/tox.ini b/charms/jupyter-ui/tox.ini index bc882ce9..f629b08e 100644 --- a/charms/jupyter-ui/tox.ini +++ b/charms/jupyter-ui/tox.ini @@ -64,6 +64,13 @@ deps = -r requirements-lint.txt description = Check code against coding style standards +[testenv:tflint] +allowlist_externals = + tflint +commands = + tflint --chdir=terraform --recursive +description = Check Terraform code against coding style standards + [testenv:unit] commands = coverage run --source={[vars]src_path} \ From 52e3b818bea2505dd143a4c412b818cf3410d8c1 Mon Sep 17 00:00:00 2001 From: Orfeas Kourkakis Date: Tue, 24 Sep 2024 16:01:16 +0300 Subject: [PATCH 2/3] ci(terraform): Deploy charm from 1.9/stable --- .github/workflows/integrate.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/integrate.yaml b/.github/workflows/integrate.yaml index d439d84c..b787a860 100644 --- a/.github/workflows/integrate.yaml +++ b/.github/workflows/integrate.yaml @@ -72,6 +72,7 @@ jobs: charm: [controller, ui] with: charm-path: ./charms/jupyter-${{ matrix.charm }} + channel: 1.9/stable bundle-integration: name: Bundle Integration From 0a0d68fc3a4f6da3f3b0bf699fd373bf4171cf12 Mon Sep 17 00:00:00 2001 From: Orfeas Kourkakis Date: Tue, 24 Sep 2024 17:38:28 +0300 Subject: [PATCH 3/3] terraform: set channel variables default to 1.9/stable --- charms/jupyter-controller/terraform/variables.tf | 2 +- charms/jupyter-ui/terraform/variables.tf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/charms/jupyter-controller/terraform/variables.tf b/charms/jupyter-controller/terraform/variables.tf index 4b1f2166..84ca0a5f 100644 --- a/charms/jupyter-controller/terraform/variables.tf +++ b/charms/jupyter-controller/terraform/variables.tf @@ -7,7 +7,7 @@ variable "app_name" { variable "channel" { description = "Charm channel" type = string - default = null + default = "1.9/stable" } variable "config" { diff --git a/charms/jupyter-ui/terraform/variables.tf b/charms/jupyter-ui/terraform/variables.tf index 3d6c288a..0a6bc80c 100644 --- a/charms/jupyter-ui/terraform/variables.tf +++ b/charms/jupyter-ui/terraform/variables.tf @@ -7,7 +7,7 @@ variable "app_name" { variable "channel" { description = "Charm channel" type = string - default = null + default = "1.9/stable" } variable "config" {