From 7a399a0f041953c6bd41355e6beb3e8a3909ce45 Mon Sep 17 00:00:00 2001 From: Trystan Schneider Date: Mon, 2 Sep 2024 17:39:53 +0200 Subject: [PATCH] Refactor shards-related variables --- .../onpremise/mongodb-sharded/example/main.tf | 14 ++++---- storage/onpremise/mongodb-sharded/main.tf | 12 +++---- storage/onpremise/mongodb-sharded/outputs.tf | 2 +- storage/onpremise/mongodb-sharded/secrets.tf | 5 +-- .../onpremise/mongodb-sharded/variables.tf | 32 ++++++++----------- 5 files changed, 30 insertions(+), 35 deletions(-) diff --git a/storage/onpremise/mongodb-sharded/example/main.tf b/storage/onpremise/mongodb-sharded/example/main.tf index a4050c054..bcfc114aa 100644 --- a/storage/onpremise/mongodb-sharded/example/main.tf +++ b/storage/onpremise/mongodb-sharded/example/main.tf @@ -15,12 +15,12 @@ module "sharded_mongodb" { image_pull_secrets = [""] node_selector = {} registry = "docker.io" - replicas = 1 tag = "7.0.14-debian-12-r0" } sharding = { shards = { + quantity = 1 replicas = 1 } @@ -79,11 +79,11 @@ module "sharded_mongodb" { } } - router = { - requests = { - "cpu" = "400m" - "memory" = "700Mi" - } - } + # router = { + # requests = { + # "cpu" = "400m" + # "memory" = "700Mi" + # } + # } } } diff --git a/storage/onpremise/mongodb-sharded/main.tf b/storage/onpremise/mongodb-sharded/main.tf index 0c99bea19..1756a317b 100644 --- a/storage/onpremise/mongodb-sharded/main.tf +++ b/storage/onpremise/mongodb-sharded/main.tf @@ -19,7 +19,7 @@ resource "helm_release" "mongodb" { values = [ yamlencode({ "commonLabels" = var.labels - "shards" = var.sharding.shards + "shards" = var.sharding.shards.quantity "image" = { "registry" = var.mongodb.registry @@ -75,7 +75,7 @@ resource "helm_release" "mongodb" { ] : [] "podLabels" = var.labels - "resources" = try(var.resources.configsvr, {}) + "resources" = var.resources.configsvr "persistentVolumeClaimRetentionPolicy" = { "enabled" = true @@ -96,12 +96,12 @@ resource "helm_release" "mongodb" { ] : [] "podLabels" = var.labels - "resources" = try(var.resources.router, null) + "resources" = var.resources.router } "shardsvr" = { "dataNode" = { - "replicaCount" = var.mongodb.replicas + "replicaCount" = var.sharding.shards.replicas "mongodbExtraFlags" = local.mongodb_extra_flags "nodeSelector" = local.shards_node_selector @@ -113,7 +113,7 @@ resource "helm_release" "mongodb" { ] : [] "podLabels" = var.labels - "resources" = try(var.resources.shards, null) + "resources" = var.resources.shards } "persistentVolumeClaimRetentionPolicy" = { @@ -140,7 +140,7 @@ resource "helm_release" "mongodb" { }] "podLabels" = var.labels - "resources" = try(var.resources.arbiter, null) + "resources" = var.resources.arbiter } # "metrics" = { diff --git a/storage/onpremise/mongodb-sharded/outputs.tf b/storage/onpremise/mongodb-sharded/outputs.tf index 6e9269316..f9b100a55 100644 --- a/storage/onpremise/mongodb-sharded/outputs.tf +++ b/storage/onpremise/mongodb-sharded/outputs.tf @@ -15,7 +15,7 @@ output "url" { output "number_of_replicas" { description = "Number of replicas for each shard" - value = var.mongodb.replicas + value = var.sharding.shards.replicas } output "number_of_shards" { diff --git a/storage/onpremise/mongodb-sharded/secrets.tf b/storage/onpremise/mongodb-sharded/secrets.tf index e743be768..4015a25b7 100644 --- a/storage/onpremise/mongodb-sharded/secrets.tf +++ b/storage/onpremise/mongodb-sharded/secrets.tf @@ -1,6 +1,6 @@ data "kubernetes_secret" "mongodb_credentials" { metadata { - name = "${helm_release.mongodb.name}" + name = helm_release.mongodb.name namespace = var.namespace } } @@ -41,6 +41,7 @@ resource "kubernetes_secret" "mongodb" { host = local.mongodb_dns port = var.mongodb.service_port url = local.mongodb_url - number_of_replicas = var.mongodb.replicas + number_of_replicas = var.sharding.shards.replicas + number_of_shards = var.sharding.shards.quantity } } diff --git a/storage/onpremise/mongodb-sharded/variables.tf b/storage/onpremise/mongodb-sharded/variables.tf index 1f672552a..74eceac03 100644 --- a/storage/onpremise/mongodb-sharded/variables.tf +++ b/storage/onpremise/mongodb-sharded/variables.tf @@ -32,7 +32,6 @@ variable "mongodb" { image_pull_secrets = optional(any, [""]) # can be a string or a list of strings node_selector = optional(map(string), {}) registry = optional(string) - replicas = optional(number, 2) service_port = optional(number, 27017) tag = string }) @@ -47,9 +46,13 @@ variable "sharding" { description = "Parameters specific to the sharded architecture" type = object({ shards = optional(object({ - replicas = optional(number, 2) + quantity = optional(number, 2) + replicas = optional(number, 1) node_selector = optional(map(string)) - })) + }), { + quantity = 2 + replicas = 1 + }) arbiter = optional(object({ node_selector = optional(map(string)) @@ -71,7 +74,8 @@ variable "sharding" { }) default = { shards = { - replicas = 2 + replicas = 1 + quantity = 2 } router = { replicas = 1 @@ -88,22 +92,22 @@ variable "resources" { shards = optional(object({ limits = optional(map(string)) requests = optional(map(string)) - })) + }), null) arbiter = optional(object({ limits = optional(map(string)) requests = optional(map(string)) - })) + }), null) configsvr = optional(object({ limits = optional(map(string)) requests = optional(map(string)) - })) + }), null) router = optional(object({ limits = optional(map(string)) requests = optional(map(string)) - })) + }), null) }) default = null } @@ -160,18 +164,8 @@ variable "security_context" { } } -# variable "mtls" { -# description = "Whether to deploy MongoDB with mTLS" -# type = bool -# default = false -# validation { -# condition = !var.mtls -# error_message = "For now, 'mTLSEnabled' must be false as mTLS is not supported yet" -# } -# } - variable "timeout" { - description = "Timeout limit in seconds per replica for the helm release creation" + description = "Timeout limit in seconds per replica (shards.quantity/) for the helm release creation" type = number default = 480 # 8 minutes }