Skip to content

Commit

Permalink
Add terraform module (#412)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelThamm authored Oct 18, 2024
1 parent 9867563 commit 46328af
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ jobs:
name: PR
uses: canonical/observability/.github/workflows/charm-pull-request.yaml@main
secrets: inherit

terraform-checks:
name: Terraform
uses: canonical/observability/.github/workflows/terraform-quality-checks.yaml@main
38 changes: 37 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,40 @@ tests/integration/testers/*/lib
# charmcraft bug: leaves the build folders behind after a pack.
**/parts/
**/prime/
**/stage/
**/stage/

# 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 traefik-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" "traefik" {
name = var.app_name
model = var.model_name
trust = true
charm {
name = "traefik-k8s"
channel = var.channel
revision = var.revision
}
units = var.units
config = var.config
}
22 changes: 22 additions & 0 deletions terraform/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
output "app_name" {
value = juju_application.traefik.name
}

output "requires" {
value = {
certificates = "certificates",
experimental_forward_auth = "experimental-forward-auth",
logging = "logging",
tracing = "tracing",
}
}

output "provides" {
value = {
grafana_dashboard = "grafana-dashboard",
ingress = "ingress",
ingress_per_unit = "ingress-per-unit",
metrics_endpoint = "metrics-endpoint",
traefik_route = "traefik-route",
}
}
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 46328af

Please sign in to comment.