Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add terraform module #325

Merged
merged 7 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
38 changes: 38 additions & 0 deletions terraform/README.md
Original file line number Diff line number Diff line change
@@ -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=<MODEL_NAME>" -auto-approve`
12 changes: 12 additions & 0 deletions terraform/main.tf
Original file line number Diff line number Diff line change
@@ -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
}
24 changes: 24 additions & 0 deletions terraform/outputs.tf
Original file line number Diff line number Diff line change
@@ -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",
}
}
42 changes: 42 additions & 0 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -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
}
9 changes: 9 additions & 0 deletions terraform/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
required_version = ">= 1.5"
required_providers {
juju = {
source = "juju/juju"
version = "~> 0.14"
}
}
}
Loading