Refacto Oauht2
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
terraform {
|
||||
required_version = ">= 1.0"
|
||||
required_providers {
|
||||
kubectl = {
|
||||
source = "gavinbunney/kubectl"
|
||||
version = "~> 1.14.0"
|
||||
kubernetes = {
|
||||
source = "hashicorp/kubernetes"
|
||||
version = "~> 2.20.0"
|
||||
}
|
||||
# kubectl = {
|
||||
# source = "gavinbunney/kubectl"
|
||||
# version = "~> 1.14.0"
|
||||
# }
|
||||
}
|
||||
}
|
||||
|
||||
80
pvc/pvc.tf
80
pvc/pvc.tf
@@ -3,30 +3,60 @@ locals {
|
||||
pvc_labels = merge(var.labels, {
|
||||
"app.kubernetes.io/component" = "pvc"
|
||||
})
|
||||
pvc_spec = merge({
|
||||
"accessModes" = [var.storage.access_mode]
|
||||
"volumeMode" = var.storage.type
|
||||
"resources" = {
|
||||
"requests" = {
|
||||
"storage" = var.storage.size
|
||||
pvc_annotations = {
|
||||
"k8up.io/backup" = var.backup
|
||||
"resize.kubesphere.io/storage_limit" = var.storage.max_size
|
||||
}
|
||||
# pvc_spec = merge({
|
||||
# "accessModes" = [var.storage.access_mode]
|
||||
# "volumeMode" = var.storage.type
|
||||
# "resources" = {
|
||||
# "requests" = {
|
||||
# "storage" = var.storage.size
|
||||
# }
|
||||
# }
|
||||
# }, var.storage.class != "" ? {
|
||||
# "storageClassName" = var.storage.class
|
||||
# } : {})
|
||||
}
|
||||
# resource "kubectl_manifest" "pvc" {
|
||||
# ignore_fields = [
|
||||
# "spec.resources.requests.storage",
|
||||
# "spec.storageClassName",
|
||||
# ]
|
||||
# yaml_body = <<-EOF
|
||||
# apiVersion: v1
|
||||
# kind: PersistentVolumeClaim
|
||||
# metadata:
|
||||
# name: ${local.app_slug}
|
||||
# namespace: "${var.namespace}"
|
||||
# annotations:
|
||||
# k8up.io/backup: "${var.backup}"
|
||||
# resize.kubesphere.io/storage_limit: "${var.storage.max_size}"
|
||||
# labels: ${jsonencode(local.pvc_labels)}
|
||||
# spec: ${jsonencode(local.pvc_spec)}
|
||||
# EOF
|
||||
# }
|
||||
resource "kubernetes_persistent_volume_claim_v1" "pvc" {
|
||||
metadata {
|
||||
name = local.app_slug
|
||||
namespace = var.namespace
|
||||
annotations = local.pvc_annotations
|
||||
labels = local.pvc_labels
|
||||
}
|
||||
spec {
|
||||
access_modes = [var.storage.access_mode]
|
||||
resources {
|
||||
requests = {
|
||||
storage = var.storage.size
|
||||
}
|
||||
}
|
||||
}, var.storage.class != "" ? {
|
||||
"storageClassName" = var.storage.class
|
||||
} : {})
|
||||
}
|
||||
resource "kubectl_manifest" "pvc" {
|
||||
ignore_fields = ["spec.resources.requests.storage"]
|
||||
yaml_body = <<-EOF
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: ${local.app_slug}
|
||||
namespace: "${var.namespace}"
|
||||
annotations:
|
||||
k8up.io/backup: "${var.backup}"
|
||||
resize.kubesphere.io/storage_limit: "${var.storage.max_size}
|
||||
labels: ${jsonencode(local.pvc_labels)}
|
||||
spec: ${jsonencode(local.pvc_spec)}
|
||||
EOF
|
||||
}
|
||||
storage_class_name = var.storage.class
|
||||
}
|
||||
lifecycle {
|
||||
ignore_changes = [
|
||||
spec[0].resources[0].requests[0],
|
||||
spec[0].storage_class_name,
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -12,19 +12,12 @@ variable "labels" {
|
||||
}
|
||||
variable "storage" {
|
||||
type = object({
|
||||
access_mode = optional(string),
|
||||
class = optional(string),
|
||||
size = optional(string),
|
||||
max_size = optional(string),
|
||||
type = optional(string)
|
||||
access_mode = optional(string, "ReadWriteOnce"),
|
||||
class = optional(string, ""),
|
||||
size = optional(string, "2Gi"),
|
||||
max_size = optional(string, "10Gi"),
|
||||
type = optional(string, "Filesystem")
|
||||
})
|
||||
default = {
|
||||
"access_mode" = "ReadWriteOnce"
|
||||
"class" = ""
|
||||
"size" = "2Gi"
|
||||
"max_size" = "10Gi"
|
||||
"type" = "Filesystem"
|
||||
}
|
||||
}
|
||||
|
||||
variable "backup" {
|
||||
|
||||
Reference in New Issue
Block a user