diff --git a/charms/worker/k8s/terraform/README.md b/charms/worker/k8s/terraform/README.md new file mode 100644 index 00000000..d97cc25e --- /dev/null +++ b/charms/worker/k8s/terraform/README.md @@ -0,0 +1,61 @@ +# Terraform module for k8s + +This is a Terraform module facilitating the deployment of the k8s 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 | Default | +| - | - | - | - | - | +| `app_name`| string | Application name | False | k8s | +| `base` | string | Ubuntu base to deploy the carm onto | False | ubuntu@24.04 | +| `channel`| string | Channel that the charm is deployed from | False | 1.30/edge | +| `config`| map(string) | Map of the charm configuration options | False | {} | +| `constraints` | string | Juju constraints to apply for this application | False | arch=amd64 | +| `model`| string | Name of the model that the charm is deployed on | True | null | +| `resources`| map(string) | Map of the charm resources | False | {} | +| `revision`| number | Revision number of the charm name | False | null | +| `units` | number | Number of units to deploy | False | 1 | + +### Outputs +Upon applied, the module exports the following outputs: + +| Name | Description | +| - | - | +| `app_name`| Application name | +| `provides`| Map of `provides` endpoints | +| `requires`| Map of `requires` 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 = canonical-k8s +} +module "k8s" { + source = "" + model = juju_model.testing.name +} +``` + +### Define a `data` source +Define a `data` source and pass a reference to the `model_name` input to the `data.juju_model` resource's name. Terraform will look for a `juju_model` resource with a matching model name and only apply resources if the names match. +``` +data "juju_model" "testing" { + name = var.model_name +} +module "k8s" { + source = "" + model = data.juju_model.testing.name +} +``` diff --git a/charms/worker/k8s/terraform/main.tf b/charms/worker/k8s/terraform/main.tf new file mode 100644 index 00000000..30cb8187 --- /dev/null +++ b/charms/worker/k8s/terraform/main.tf @@ -0,0 +1,19 @@ +# Copyright 2024 Canonical Ltd. +# See LICENSE file for licensing details. + +resource "juju_application" "k8s" { + name = var.app_name + model = var.model + + charm { + name = "k8s" + channel = var.channel + revision = var.revision + base = var.base + } + + config = var.config + constraints = var.constraints + units = var.units + resources = var.resources +} diff --git a/charms/worker/k8s/terraform/outputs.tf b/charms/worker/k8s/terraform/outputs.tf new file mode 100644 index 00000000..f38d2d66 --- /dev/null +++ b/charms/worker/k8s/terraform/outputs.tf @@ -0,0 +1,28 @@ +# Copyright 2024 Canonical Ltd. +# See LICENSE file for licensing details. + +output "app_name" { + description = "Name of the deployed application." + value = juju_application.k8s.name +} + +output "requires" { + value = { + aws = "aws" + azure = "azure" + etcd = "etcd" + external_cloud_provider = "external-cloud-provider" + gcp = "gcp" + } +} + +output "provides" { + value = { + cos_agent = "cos-agent" + cos_worker_tokens = "cos-worker-tokens" + containerd = "containerd" + ceph_k8s_info = "ceph-k8s-info" + k8s_cluster = "k8s-cluster" + kube_control = "kube-control" + } +} diff --git a/charms/worker/k8s/terraform/variables.tf b/charms/worker/k8s/terraform/variables.tf new file mode 100644 index 00000000..4585b9a2 --- /dev/null +++ b/charms/worker/k8s/terraform/variables.tf @@ -0,0 +1,60 @@ +# Copyright 2024 Canonical Ltd. +# See LICENSE file for licensing details. + +variable "app_name" { + description = "Name of the application in the Juju model." + type = string + default = "k8s" +} + +variable "base" { + description = "Ubuntu base to deploy the charm onto" + type = string + default = "ubuntu@24.04" + + validation { + condition = contains(["ubuntu@20.04", "ubuntu@22.04", "ubuntu@24.04"], var.base) + error_message = "Base must be one of ubuntu@20.04, ubuntu@22.04, ubuntu@24.04" + } +} + +variable "channel" { + description = "The channel to use when deploying a charm." + type = string + default = "1.30/edge" +} + +variable "config" { + description = "Application config. Details about available options can be found at https://charmhub.io/k8s/configurations." + type = map(string) + default = {} +} + +variable "constraints" { + description = "Juju constraints to apply for this application." + type = string + default = "arch=amd64" +} + +variable "model" { + description = "Reference to a `juju_model`." + type = string +} + +variable "resources" { + description = "Resources to use with the application. Details about available options can be found at https://charmhub.io/k8s/configurations." + type = map(string) + default = {} +} + +variable "revision" { + description = "Revision number of the charm" + type = number + default = null +} + +variable "units" { + description = "Number of units to deploy" + type = number + default = 1 +} diff --git a/charms/worker/k8s/terraform/versions.tf b/charms/worker/k8s/terraform/versions.tf new file mode 100644 index 00000000..269e8508 --- /dev/null +++ b/charms/worker/k8s/terraform/versions.tf @@ -0,0 +1,12 @@ +terraform { + # Copyright 2024 Canonical Ltd. + # See LICENSE file for licensing details. + + required_version = ">= 1.6" + required_providers { + juju = { + source = "juju/juju" + version = "~> 0.14.0" + } + } +} diff --git a/charms/worker/terraform/README.md b/charms/worker/terraform/README.md new file mode 100644 index 00000000..67a31560 --- /dev/null +++ b/charms/worker/terraform/README.md @@ -0,0 +1,61 @@ +# Terraform module for k8s-worker + +This is a Terraform module facilitating the deployment of the k8s-worker 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 | Default | +| - | - | - | - | - | +| `app_name`| string | Application name | False | k8s-worker | +| `base` | string | Ubuntu base to deploy the carm onto | False | ubuntu@24.04 | +| `channel`| string | Channel that the charm is deployed from | False | 1.30/edge | +| `config`| map(string) | Map of the charm configuration options | False | {} | +| `constraints` | string | Juju constraints to apply for this application | False | arch=amd64 | +| `model`| 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 | null | +| `units` | number | Number of units to deploy | False | 1 | + +### Outputs +Upon applied, the module exports the following outputs: + +| Name | Description | +| - | - | +| `app_name`| Application name | +| `provides`| Map of `provides` endpoints | +| `requires`| Map of `requires` 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 = canonical-k8s +} +module "k8s_worker" { + source = "" + model = 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 "k8s_worker" { + source = "" + model = data.juju_model.testing.name +} +``` diff --git a/charms/worker/terraform/main.tf b/charms/worker/terraform/main.tf new file mode 100644 index 00000000..1e0ca267 --- /dev/null +++ b/charms/worker/terraform/main.tf @@ -0,0 +1,19 @@ +# Copyright 2024 Canonical Ltd. +# See LICENSE file for licensing details. + +resource "juju_application" "k8s_worker" { + name = var.app_name + model = var.model + + charm { + name = "k8s-worker" + channel = var.channel + revision = var.revision + base = var.base + } + + config = var.config + constraints = var.constraints + units = var.units + resources = var.resources +} diff --git a/charms/worker/terraform/outputs.tf b/charms/worker/terraform/outputs.tf new file mode 100644 index 00000000..a4ce7759 --- /dev/null +++ b/charms/worker/terraform/outputs.tf @@ -0,0 +1,24 @@ +# Copyright 2024 Canonical Ltd. +# See LICENSE file for licensing details. + +output "app_name" { + description = "Name of the deployed application." + value = juju_application.k8s_worker.name +} + +output "requires" { + value = { + aws = "aws" + azure = "azure" + cluster = "cluster" + cos_tokens = "cos-tokens" + containerd = "containerd" + gcp = "gcp" + } +} + +output "provides" { + value = { + cos_agent = "cos-agent" + } +} diff --git a/charms/worker/terraform/variables.tf b/charms/worker/terraform/variables.tf new file mode 100644 index 00000000..d60a1c1f --- /dev/null +++ b/charms/worker/terraform/variables.tf @@ -0,0 +1,60 @@ +# Copyright 2024 Canonical Ltd. +# See LICENSE file for licensing details. + +variable "app_name" { + description = "Name of the application in the Juju model." + type = string + default = "k8s-worker" +} + +variable "base" { + description = "Ubuntu bases to deploy the charm onto" + type = string + default = "ubuntu@24.04" + + validation { + condition = contains(["ubuntu@20.04", "ubuntu@22.04", "ubuntu@24.04"], var.base) + error_message = "Base must be one of ubuntu@20.04, ubuntu@22.04, ubuntu@24.04" + } +} + +variable "channel" { + description = "The channel to use when deploying a charm." + type = string + default = "1.30/edge" +} + +variable "config" { + description = "Application config. Details about available options can be found at https://charmhub.io/k8s-worker/configurations." + type = map(string) + default = {} +} + +variable "constraints" { + description = "Juju constraints to apply for this application." + type = string + default = "arch=amd64" +} + +variable "model" { + description = "Reference to a `juju_model`." + type = string +} + +variable "resources" { + description = "Resources to use with the application. Details about available options can be found at https://charmhub.io/k8s-worker/configurations." + type = map(string) + default = {} +} + +variable "revision" { + description = "Revision number of the charm" + type = number + default = null +} + +variable "units" { + description = "Number of units to deploy" + type = number + default = 1 +} diff --git a/charms/worker/terraform/versions.tf b/charms/worker/terraform/versions.tf new file mode 100644 index 00000000..269e8508 --- /dev/null +++ b/charms/worker/terraform/versions.tf @@ -0,0 +1,12 @@ +terraform { + # Copyright 2024 Canonical Ltd. + # See LICENSE file for licensing details. + + required_version = ">= 1.6" + required_providers { + juju = { + source = "juju/juju" + version = "~> 0.14.0" + } + } +}