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

42
backup/backup.tf Normal file
View File

@@ -0,0 +1,42 @@
locals {
app_slug = (var.component == var.instance || var.component=="") ? var.instance : format("%s-%s", var.component, var.instance)
}
resource "kubectl_manifest" "backup_schedule" {
count = var.backups.enable ? 1 : 0
yaml_body = <<-EOF
apiVersion: k8up.io/v1
kind: Schedule
metadata:
name: "${var.app_slug}-backup"
namespace: "${var.namespace}"
labels: ${jsonencode(local.labels)}
spec:
backend:
repoPasswordSecretRef:
key: "${var.backups.restic_key}"
name: "${var.backups.secret_name}"
s3:
accessKeyIDSecretRef:
key: "${var.backups.key_id_key}"
name: "${var.backups.secret_name}"
bucket: "${var.app_slug}-${var.namespace}"
endpoint: "${var.backups.endpoint}/restic"
secretAccessKeySecretRef:
key: "${var.backups.secret_key}"
name: "${var.backups.secret-name}"
backup:
schedule: "${var.backups.schedule.backup}"
failedJobsHistoryLimit: 2
successfulJobsHistoryLimit: 2
check:
schedule: "${var.backups.schedule.check}"
prune:
retention:
keepDaily: ${var.backups.retention.keepDaily}
keepMonthly: ${var.backups.retention.keepMonthly}
keepWeekly: ${var.backups.retention.keepWeekly}
keepYearly: ${var.backups.retention.keepYearly}
schedule: "${var.backups.schedule.prune}"
EOF
}

3
backup/outputs.tf Normal file
View File

@@ -0,0 +1,3 @@
output "schedule_name" {
value = kubectl_manifest.backup_schedule.name
}

8
backup/providers.tf Normal file
View File

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

55
backup/variables.tf Normal file
View File

@@ -0,0 +1,55 @@
variable "component" {
type = string
}
variable "instance" {
type = string
}
variable "namespace" {
type = string
}
variable "labels" {
type = map(string)
}
variable "backups" {
default = {
"enable" = false
"endpoint" = ""
"key_id_key" = "s3-id"
"restic_key" = "bck-password"
"retention" = {
"keepDaily" = 14
"keepMonthly" = 12
"keepWeekly" = 6
"keepYearly" = 12
}
"schedule" = {
"backup" = "30 3 * * *"
"check" = "30 5 * * 1"
"db" = "30 3 * * *"
"prune" = "30 1 * * 0"
}
"secret_key" = "s3-secret"
"secret_name" = "backup-settings"
"use_barman" = false
}
type = object({
enable = optional(bool),
endpoint = optional(string),
key_id_key = optional(string),
restic_key = optional(string),
retention = optional(object({
keepDaily = optional(number),
keepMonthly = optional(number),
keepWeekly = optional(number),
keepYearly = optional(number)
})),
schedule = optional(object({
backup = optional(string),
check = optional(string),
prune = optional(string)
})),
secret_key = optional(string),
secret_name = optional(string),
use_barman = optional(bool)
})
}