Skip to content

Commit

Permalink
Add terraform module (#350)
Browse files Browse the repository at this point in the history
1. Working terraform apply
2. Requires and provides integrations in outputs 

---------

Signed-off-by: Michael Thamm <[email protected]>
Co-authored-by: Leon <[email protected]>
  • Loading branch information
MichaelThamm and sed-i authored Oct 18, 2024
1 parent d122274 commit 07a52a6
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ jobs:
secrets: inherit
with:
ip-range: 10.64.140.43/30

terraform-checks:
name: Terraform
uses: canonical/observability/.github/workflows/terraform-quality-checks.yaml@main
36 changes: 36 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,39 @@ venv
tests/integration/grafana-tester/lib/charms/grafana_k8s/*
cos-tool*
sqlite-static

# Local .terraform directories
**/.terraform/*

# .tfstate files
*.tfstate
*.tfstate.*

# Crash log files
crash.log
crash.*.log

# Exclude all .tfvars files, which are likely to contain sensitive data, such as
# password, private keys, and other secrets. These should not be part of version
# control as they are data points which are potentially sensitive and subject
# to change depending on the environment.
*.tfvars
*.tfvars.json

# Ignore override files as they are usually used to override resources locally and so
# are not checked in
override.tf
override.tf.json
*_override.tf
*_override.tf.json

# Include override files you do wish to add to version control using negated pattern
# !example_override.tf

# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*

# Ignore CLI configuration files
.terraformrc
terraform.rc
.terraform.lock.hcl
4 changes: 4 additions & 0 deletions terraform/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Terraform module for grafana-k8s


This module is in experimental status. It is not yet ready for production.
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" {
name = var.app_name
model = var.model_name
trust = true
charm {
name = "grafana-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.name
}

output "requires" {
value = {
catalogue = "catalogue",
certificates = "certificates",
database = "database",
grafana_auth = "grafana-auth",
grafana_dashboard = "grafana-dashboard",
grafana_source = "grafana-source",
ingress = "ingress",
oauth = "oauth",
receive_ca_cert = "receive-ca-cert",
tracing = "tracing",
}
}

output "provides" {
value = {
metrics_endpoint = "metrics-endpoint",
}
}
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"
}
}
}

0 comments on commit 07a52a6

Please sign in to comment.