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,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,30 @@
locals {
app_slug = (var.component == var.instance || var.component=="") ? var.instance : format("%s-%s", var.component, var.instance)
app_slug = "${var.instance}${var.component == "" ? "" : "-"}${var.component}"
pvc_labels = merge(var.labels, {
"app.kubernetes.io/component" = "pvc"
})
pvc_spec = merge({
"accessModes" = [var.storage.accessMode]
"volumeMode" = var.storage.type
"accessModes" = [var.storage.access_mode]
"volumeMode" = var.storage.type
"resources" = {
"requests" = {
"storage" = "${var.storage.size}"
}
}
}, var.storage.volume.class != "" ?{
}, var.storage.class != "" ? {
"storageClassName" = var.storage.class
}:{})
} : {})
}
resource "kubectl_manifest" "pvc" {
yaml_body = <<-EOF
yaml_body = <<-EOF
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: ${local.app_slug}
namespace: "${var.namespace}"
annotations:
k8up.io/backup: "true"
labels: ${jsonencode(local.labels)}
k8up.io/backup: "${var.backup}"
labels: ${jsonencode(local.pvc_labels)}
spec: ${jsonencode(local.pvc_spec)}
EOF
}

View File

@@ -11,16 +11,21 @@ variable "labels" {
type = map(string)
}
variable "storage" {
type = object({
accessMode = optional(string),
class = optional(string),
size = optional(string),
type = optional(string)
type = object({
access_mode = optional(string),
class = optional(string),
size = optional(string),
type = optional(string)
})
default = {
"accessMode" = "ReadWriteOnce"
"class" = ""
"size" = "10Gi"
"type" = "Filesystem"
default = {
"access_mode" = "ReadWriteOnce"
"class" = ""
"size" = "10Gi"
"type" = "Filesystem"
}
}
}
variable "backup" {
type = bool
default = true
}