{% set config = merged_configs.get('google_alloydb_cluster', {}) %}
# Compliance: {{ compliance_comments.get('google_alloydb_cluster', []) | join(', ') }}
resource "google_alloydb_cluster" "main" {
  cluster_id = "{{ config.get('cluster_id', '${var.project_id}-alloydb') }}"
  project    = var.project_id
  location   = var.region

  network_config {
    network = "{{ config.get('network', google_compute_network.main.id) }}"
  }

  automated_backup_policy {
    enabled = {{ config.get('backup_enabled', true) | lower }}

    weekly_schedule {
      days_of_week = ["{{ config.get('backup_day', 'SUNDAY') }}"]

      start_times {
        hours = {{ config.get('backup_hour', 2) }}
      }
    }

    quantity_based_retention {
      count = {{ config.get('backup_retention_count', 14) }}
    }
  }
{% if config.get('kms_key_name') %}

  encryption_config {
    kms_key_name = {{ config.get('kms_key_name') }}
  }
{% endif %}
}
