Adding storage modules
This commit is contained in:
3
pvc/outputs.tf
Normal file
3
pvc/outputs.tf
Normal file
@@ -0,0 +1,3 @@
|
||||
output "name" {
|
||||
value = local.app_slug
|
||||
}
|
||||
8
pvc/providers.tf
Normal file
8
pvc/providers.tf
Normal file
@@ -0,0 +1,8 @@
|
||||
terraform {
|
||||
required_providers {
|
||||
kubectl = {
|
||||
source = "gavinbunney/kubectl"
|
||||
version = "~> 1.14.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
27
pvc/pvc.tf
Normal file
27
pvc/pvc.tf
Normal 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
26
pvc/variables.tf
Normal 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"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user