diff --git a/.gitignore b/.gitignore index b8ae2d8..09a8664 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,13 @@ __pycache__/ tests/integration/*-tester/lib/ .env cos-tool* + +# Terraform +*.tfstate +*.tfstate.* +*.tfplan +.terraform.lock.hcl +crash.log +.terraform/ +terraform.tfvars +terraform.tfvars.json \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 7c16514..ad38b9b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,7 +20,7 @@ ignore-words-list = "assertIn" # Linting tools configuration [tool.ruff] line-length = 99 -exclude = ["__pycache__", "*.egg_info"] +exclude = ["__pycache__", "*.egg_info", "prometheus-tester", "loki-tester"] [tool.ruff.lint] select = ["E", "W", "F", "C", "N", "R", "D", "I001"] diff --git a/terraform/README.md b/terraform/README.md new file mode 100644 index 0000000..acdae36 --- /dev/null +++ b/terraform/README.md @@ -0,0 +1,38 @@ +# Terraform module for grafana-agent + + +This is a Terraform module facilitating the deployment of grafana-agent-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 | +| - | - | - | - | +| `app_name`| string | Application name | mimir-worker | +| `channel`| string | Channel that the charm is deployed from | latest/edge | +| `config`| map(any) | Map of the charm configuration options | {} | +| `constraints`| string | Constraints for the Juju deployment| "" | +| `model_name`| string | Name of the model that the charm is deployed on | | +| `revision`| number | Revision number of the charm name | null | +| `units`| number | Number of units to deploy | 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 + +Users should ensure that Terraform is aware of the `juju_model` dependency of the charm module. + +To deploy this module with its needed dependency, you can run `terraform apply -var="model_name=" -auto-approve` diff --git a/terraform/main.tf b/terraform/main.tf new file mode 100644 index 0000000..6628dbb --- /dev/null +++ b/terraform/main.tf @@ -0,0 +1,12 @@ +resource "juju_application" "grafana_agent" { + name = var.app_name + model = var.model_name + trust = true + charm { + name = "grafana-agent-k8s" + channel = var.channel + revision = var.revision + } + units = var.units + config = var.config +} diff --git a/terraform/outputs.tf b/terraform/outputs.tf new file mode 100644 index 0000000..6b9442c --- /dev/null +++ b/terraform/outputs.tf @@ -0,0 +1,24 @@ +output "app_name" { + value = juju_application.grafana_agent.name +} + +output "requires" { + value = { + certificates = "certificates", + send_remote_write = "send-remote-write", + metrics_endpoint = "metrics-endpoint", + logging_consumer = "logging-consumer", + grafana_dashboards_consumer = "grafana-dashboards-consumer", + grafana_cloud_config = "grafana-cloud-config", + receive_ca_cert = "receive-ca-cert", + tracing = "tracing", + } +} + +output "provides" { + value = { + tracing_provider = "tracing-provider", + logging_provider = "logging-provider", + grafana_dashboards_provider = "grafana-dashboards-provider", + } +} diff --git a/terraform/variables.tf b/terraform/variables.tf new file mode 100644 index 0000000..ac8d649 --- /dev/null +++ b/terraform/variables.tf @@ -0,0 +1,42 @@ +variable "app_name" { + description = "Application name" + type = string +} + +variable "channel" { + description = "Charm channel" + type = string + default = "latest/stable" +} + +variable "config" { + description = "Config options as in the ones we pass in juju config" + type = map(string) + default = {} +} + +# We use constraints to set AntiAffinity in K8s +# https://discourse.charmhub.io/t/pod-priority-and-affinity-in-juju-charms/4091/13?u=jose +variable "constraints" { + description = "Constraints to be applied" + type = string + default = "" +} + +variable "model_name" { + description = "Model name" + type = string +} + +variable "revision" { + description = "Charm revision" + type = number + nullable = true + default = null +} + +variable "units" { + description = "Number of units" + type = number + default = 1 +} \ No newline at end of file diff --git a/terraform/versions.tf b/terraform/versions.tf new file mode 100644 index 0000000..77b6440 --- /dev/null +++ b/terraform/versions.tf @@ -0,0 +1,9 @@ +terraform { + required_version = ">= 1.5" + required_providers { + juju = { + source = "juju/juju" + version = "~> 0.14" + } + } +} \ No newline at end of file