diff --git a/.github/workflows/integrate.yaml b/.github/workflows/integrate.yaml index cd668fa..f6d3968 100644 --- a/.github/workflows/integrate.yaml +++ b/.github/workflows/integrate.yaml @@ -37,6 +37,14 @@ jobs: sudo apt install tox - run: tox -vve argo-controller-unit + terraform-checks: + name: Terraform + uses: canonical/charmed-kubeflow-workflows/.github/workflows/terraform-checks.yaml@main + with: + charm-path: ./charms/argo-controller + model: kubeflow + channel: latest/edge + integration: name: Integration Test runs-on: ubuntu-20.04 diff --git a/.gitignore b/.gitignore index d25fe35..76907c8 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,6 @@ __pycache__ operators/argo-controller/build .tox .idea +venv/ +.terraform* +*.tfstate* diff --git a/charms/argo-controller/terraform/README.md b/charms/argo-controller/terraform/README.md new file mode 100644 index 0000000..f538621 --- /dev/null +++ b/charms/argo-controller/terraform/README.md @@ -0,0 +1,60 @@ +# Terraform module for argo-controller + +This is a Terraform module facilitating the deployment of argo-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(number) | Map of charm resources revisions | 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 "argo-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 "argo-controller" { + source = "" + model_name = data.juju_model.testing.name +} +``` diff --git a/charms/argo-controller/terraform/main.tf b/charms/argo-controller/terraform/main.tf new file mode 100644 index 0000000..1e28d6b --- /dev/null +++ b/charms/argo-controller/terraform/main.tf @@ -0,0 +1,13 @@ +resource "juju_application" "argo_controller" { + charm { + name = "argo-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/argo-controller/terraform/outputs.tf b/charms/argo-controller/terraform/outputs.tf new file mode 100644 index 0000000..a79f4bf --- /dev/null +++ b/charms/argo-controller/terraform/outputs.tf @@ -0,0 +1,17 @@ +output "app_name" { + value = juju_application.argo_controller.name +} + +output "provides" { + value = { + metrics_endpoint = "metrics-endpoint", + grafana_dashboard = "grafana-dashboard" + } +} + +output "requires" { + value = { + object_storage = "object-storage", + logging = "logging" + } +} diff --git a/charms/argo-controller/terraform/variables.tf b/charms/argo-controller/terraform/variables.tf new file mode 100644 index 0000000..67367c5 --- /dev/null +++ b/charms/argo-controller/terraform/variables.tf @@ -0,0 +1,35 @@ +variable "app_name" { + description = "Application name" + type = string + default = "argo-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 +} + +# TODO: Update to a map of strings, once juju provider 0.14 is released +variable "resources" { + description = "Map of resources revisions" + type = map(number) + default = null +} + +variable "revision" { + description = "Charm revision" + type = number + default = null +} diff --git a/charms/argo-controller/terraform/versions.tf b/charms/argo-controller/terraform/versions.tf new file mode 100644 index 0000000..3e770f3 --- /dev/null +++ b/charms/argo-controller/terraform/versions.tf @@ -0,0 +1,9 @@ +terraform { + required_version = ">= 1.6" + required_providers { + juju = { + source = "juju/juju" + version = "~> 0.13.0" + } + } +} diff --git a/charms/argo-controller/tox.ini b/charms/argo-controller/tox.ini index bc882ce..f629b08 100644 --- a/charms/argo-controller/tox.ini +++ b/charms/argo-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} \