diff --git a/main.tf b/main.tf index 9e722da..a0486d4 100644 --- a/main.tf +++ b/main.tf @@ -81,6 +81,10 @@ resource "kubernetes_stateful_set" "mariadb" { } } } + env { + name = "MARIADB_EXTRA_FLAGS" + value = var.mariadb_flags + } port { name = "tcp-mariadb" container_port = local.port @@ -89,6 +93,23 @@ resource "kubernetes_stateful_set" "mariadb" { name = "data" mount_path = "/bitnami/mariadb" } + dynamic "volume_mount" { + for_each = var.mariadb_conf != "" ? toset(["config"]) : toset([]) + content { + name = volume_mount.value + mount_path = "/opt/bitnami/mariadb/conf/my_custom.cnf" + sub_path = "my_custom.cnf" + } + } + } + dynamic "volume" { + for_each = var.mariadb_conf != "" ? toset(["config"]) : toset([]) + content { + name = volume.value + config_map { + name = kubernetes_config_map.mariadb_conf[volume.key].metadata.0.name + } + } } } } @@ -156,3 +177,14 @@ resource "kubernetes_config_map" "mariadb" { MARIADB_DATABASE = var.mariadb_db } } + +resource "kubernetes_config_map" "mariadb_conf" { + for_each = var.mariadb_conf != "" ? toset(["config"]) : toset([]) + metadata { + name = "mariadb-conf" + namespace = var.namespace + } + data = { + "my_custom.cnf" = var.mariadb_conf + } +} diff --git a/variables.tf b/variables.tf index 0f8e2d1..3392076 100644 --- a/variables.tf +++ b/variables.tf @@ -34,6 +34,18 @@ variable "mariadb_db" { sensitive = true } +variable "mariadb_conf" { + description = "MariaDB configuration file to enable custom configuration" + type = string + default = "" +} + +variable "mariadb_flags" { + description = "Additional flags to pass to MariaDB startup" + type = string + default = "" +} + variable "stateful_set_name" { description = "Name of StatefulSet" type = string