Adding storage modules

This commit is contained in:
2024-01-27 00:03:20 +01:00
parent c39cc31bc6
commit 2c066b9049
17 changed files with 451 additions and 1 deletions

3
pvc/outputs.tf Normal file
View File

@@ -0,0 +1,3 @@
output "name" {
value = local.app_slug
}

8
pvc/providers.tf Normal file
View File

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

27
pvc/pvc.tf Normal file
View File

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

26
pvc/variables.tf Normal file
View File

@@ -0,0 +1,26 @@
variable "component" {
type = string
}
variable "instance" {
type = string
}
variable "namespace" {
type = string
}
variable "labels" {
type = map(string)
}
variable "storage" {
type = object({
accessMode = optional(string),
class = optional(string),
size = optional(string),
type = optional(string)
})
default = {
"accessMode" = "ReadWriteOnce"
"class" = ""
"size" = "10Gi"
"type" = "Filesystem"
}
}