From 687a1eeca19ae91926c82aa1b2395cae6037989a Mon Sep 17 00:00:00 2001 From: Aditya Choudhari Date: Wed, 7 May 2025 12:08:26 -0700 Subject: [PATCH] feat: Max db connections --- main.tf | 2 ++ modules/database/main.tf | 8 ++++++++ modules/database/variables.tf | 6 ++++++ variables.tf | 6 ++++++ 4 files changed, 22 insertions(+) diff --git a/main.tf b/main.tf index 999affd..030dd97 100644 --- a/main.tf +++ b/main.tf @@ -31,6 +31,8 @@ module "database" { deletion_protection = var.deletion_protection + max_database_connections = var.max_database_connections + depends_on = [module.networking] } diff --git a/modules/database/main.tf b/modules/database/main.tf index 2774dca..b504c01 100644 --- a/modules/database/main.tf +++ b/modules/database/main.tf @@ -29,6 +29,14 @@ resource "google_sql_database_instance" "this" { insights_config { query_insights_enabled = true } + + dynamic "database_flags" { + for_each = var.max_database_connections != "" ? [1] : [] + content { + name = "max_connections" + value = var.max_database_connections + } + } } } diff --git a/modules/database/variables.tf b/modules/database/variables.tf index a985496..53b6dab 100644 --- a/modules/database/variables.tf +++ b/modules/database/variables.tf @@ -23,3 +23,9 @@ variable "deletion_protection" { description = "Whether to enable deletion protection for the database instance." type = bool } + +variable "max_database_connections" { + description = "The maximum number of connections to the database" + type = string + default = "" +} diff --git a/variables.tf b/variables.tf index 71e7269..d6868fd 100644 --- a/variables.tf +++ b/variables.tf @@ -20,6 +20,12 @@ variable "postgres_version" { default = "POSTGRES_17" } +variable "max_database_connections" { + description = "The maximum number of connections to the database" + type = string + default = "" +} + variable "redis_tier" { description = "The tier for the Redis instance" type = string