Refacto and add modules

This commit is contained in:
2024-02-06 11:03:20 +01:00
parent 140321f714
commit 1e1cedcaeb
47 changed files with 685 additions and 360 deletions

View File

@@ -1,6 +1,15 @@
output "host" {
value = "${local.app_slug}-redis.${var.namespace}.svc"
}
output "url" {
output "conn_string" {
value = "redis://${local.app_slug}-redis.${var.namespace}.svc:6379"
}
output "service" {
value = "${local.app_slug}-redis.${var.namespace}.svc"
}
output "db_host" {
value = "${local.app_slug}-redis"
}
output "secret_name" {
value = lookup(var.password, "name", "")
}

View File

@@ -1,8 +1,8 @@
terraform {
required_providers {
kubectl = {
source = "gavinbunney/kubectl"
version = "~> 1.14.0"
source = "gavinbunney/kubectl"
version = "~> 1.14.0"
}
}
}

View File

@@ -1,27 +1,27 @@
locals {
app_slug = (var.component == var.instance || var.component=="") ? var.instance : format("%s-%s", var.component, var.instance)
redis-labels = merge(var.labels, {
app_slug = "${var.instance}${var.component == "" ? "" : "-"}${var.component}"
redis_labels = merge(var.labels, {
"app.kubernetes.io/component" = "redis"
})
cfg = merge({
"image" = "${var.images.redis.registry}/${var.images.redis.repository}:${var.images.redis.tag}"
"imagePullPolicy" = "${var.images.redis.pullPolicy}"
},lookup(var.password, "enabled", false)?{
"image" = "${var.images.redis.registry}/${var.images.redis.repository}:${var.images.redis.tag}"
"imagePullPolicy" = "${var.images.redis.pull_policy}"
}, lookup(var.password, "enabled", false) ? {
redisSecret = {
name = lookup(var.password, "name", var.component)
key = lookup(var.password, "key", "redis-password")
}
}:{})
} : {})
}
resource "kubectl_manifest" "redis" {
yaml_body = <<-EOF
yaml_body = <<-EOF
apiVersion: "redis.redis.opstreelabs.in/v1beta1"
kind: "Redis"
metadata:
name: "${local.app_slug}-redis"
namespace: "${var.namespace}"
labels: ${jsonencode(local.redis-labels)}
labels: ${jsonencode(local.redis_labels)}
spec:
kubernetesConfig: ${jsonencode(local.cfg)}
storage:

View File

@@ -11,55 +11,55 @@ variable "labels" {
type = map(string)
}
variable "annotations" {
type = map(string)
type = map(string)
default = {}
}
variable "images" {
type = object({
redis = optional(object({pullPolicy = optional(string), registry = optional(string), repository = optional(string), tag = optional(string)})),
redis_exporter = optional(object({pullPolicy = optional(string), registry = optional(string), repository = optional(string), tag = optional(string)}))
type = object({
redis = optional(object({ pull_policy = optional(string), registry = optional(string), repository = optional(string), tag = optional(string) })),
redis_exporter = optional(object({ pull_policy = optional(string), registry = optional(string), repository = optional(string), tag = optional(string) }))
})
default = {
default = {
"redis" = {
"pullPolicy" = "IfNotPresent"
"registry" = "quay.io"
"repository" = "opstree/redis"
"tag" = "v7.0.12"
"pull_policy" = "IfNotPresent"
"registry" = "quay.io"
"repository" = "opstree/redis"
"tag" = "v7.0.12"
}
"redis_exporter" = {
"pullPolicy" = "IfNotPresent"
"registry" = "quay.io"
"repository" = "opstree/redis-exporter"
"tag" = "v1.44.0"
"pull_policy" = "IfNotPresent"
"registry" = "quay.io"
"repository" = "opstree/redis-exporter"
"tag" = "v1.44.0"
}
}
}
variable "exporter" {
type = object({
type = object({
enabled = optional(bool)
})
default = {
default = {
"enabled" = true
}
}
variable "password" {
type = object({
type = object({
enabled = optional(bool),
name = optional(string),
key = optional(string)
name = optional(string),
key = optional(string)
})
default = {
default = {
"enabled" = false
"name" = ""
"key" = ""
"name" = ""
"key" = ""
}
}
variable "storage" {
type = object({
type = object({
size = optional(string)
})
default = {
default = {
"size" = "2Gi"
}
}
}