Simplify Cloud SQL backup enablement logic

This commit is contained in:
apichick
2025-05-20 13:24:18 +02:00
committed by GitHub
parent 2a5e5833a9
commit bf2814653e

View File

@@ -20,13 +20,6 @@ locals {
is_postgres = can(regex("^POSTGRES", var.database_version))
has_replicas = length(var.replicas) > 0
is_regional = var.availability_type == "REGIONAL" ? true : false
# enable backup if the user asks for it or if the user is deploying
# MySQL in HA configuration (regional or with specified replicas)
enable_backup = (
var.backup_configuration.enabled ||
(local.is_mysql && local.has_replicas) ||
(local.is_mysql && local.is_regional)
)
users = {
for k, v in coalesce(var.users, {}) : k =>
local.is_mysql
@@ -109,7 +102,7 @@ resource "google_sql_database_instance" "primary" {
}
dynamic "backup_configuration" {
for_each = local.enable_backup ? { 1 = 1 } : {}
for_each = var.backup_configuration.enabled ? { 1 = 1 } : {}
content {
enabled = true
// enable binary log if the user asks for it or we have replicas (default in regional),