Skip to content

Commit

Permalink
first implementation of terraform module (#200)
Browse files Browse the repository at this point in the history
* first implementation of terraform module

* add terraform lines in .gitignore
  • Loading branch information
Abuelodelanada authored Nov 11, 2024
1 parent 6da23c0 commit e509330
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,13 @@ __pycache__/
.idea/
tests/integration/*-tester/lib/
.env

# Terraform
*.tfstate
*.tfstate.*
*.tfplan
.terraform.lock.hcl
crash.log
.terraform/
terraform.tfvars
terraform.tfvars.json
37 changes: 37 additions & 0 deletions terraform/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Terraform module for grafana-agent


This is a Terraform module facilitating the deployment of grafana-agent 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 |
| `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`
13 changes: 13 additions & 0 deletions terraform/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
resource "juju_application" "grafana_agent" {
name = var.app_name
model = var.model_name
trust = true # We always need this variable to be true in order to be able to apply resources limits.

charm {
name = "grafana-agent"
channel = var.channel
revision = var.revision
}
units = var.units
config = var.config
}
3 changes: 3 additions & 0 deletions terraform/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "app_name" {
value = juju_application.grafana_agent.name
}
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
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.15.0"
}
}
}

0 comments on commit e509330

Please sign in to comment.