terraform-google-modules / terraform-google-sql-db

Creates a Cloud SQL database instance
https://registry.terraform.io/modules/terraform-google-modules/sql-db/google
Apache License 2.0
265 stars 425 forks source link

Binary logging cannot be enabled on instances with a master_instance_name #590

Closed OscarVanL closed 7 months ago

OscarVanL commented 7 months ago

TL;DR

If master_instance_name is set on an instance via this module, it is impossible to create replicas from it.

This is because the backup_configuration config will be ignored. This makes it impossible to set binary_log_enabled = true, which is a pre-requisite for creating replicas.

Expected behavior

If master_instance_name is configured, only enabling backups should be prohibited, as this is not possible on replica instances. Other config-related items should be configurable, such as enabling binary logs.

Observed behavior

Backup configuration provided to the module is ignored.

Terraform Configuration

As you can see in my configuration, I have the master_instance_name set, and I also thought I had set binary_log_enabled = true, but actually once I apply the plan to create a new replica instance, it fails because binary logs had not been enabled on the instance.

module "portal-db" {
  source                  = "GoogleCloudPlatform/sql-db/google//modules/mysql"
  version                 = "20.0.0"
  project_id              = var.project_id
  master_instance_name    = "my-on-prem-source-representation-instance"
  database_version        = "MYSQL_8_0_36"
  deletion_protection     = true
  disk_autoresize         = true
  name                    = "my-database"
  user_name               = "foo"
  user_password           = var.foo_db_password
  zone                    = "europe-west4-a"
  region                  = "europe-west4"
  tier                    = "db-perf-optimized-N-2"
  enable_default_db       = false
  maintenance_window_day  = 6
  maintenance_window_hour = 23
  random_instance_name    = true
  edition                 = "ENTERPRISE_PLUS"
  data_cache_enabled      = false
  ip_configuration = {
    ipv4_enabled        = false
    authorized_networks = []
    require_ssl         = true
    private_network     = data.google_compute_network.network.id
    allocated_ip_range  = "my-allocated-ip-range"
  }
  read_replica_name_suffix = "-"
  read_replicas = [for r in var.replica_configs : {
    name = "my-replica-name"
    tier               = r.tier
    edition            = r.edition
    availability_type  = r.availability_type
    zone               = r.zone
    region             = r.region
    disk_autoresize    = r.disk_autoresize
    data_cache_enabled = r.data_cache_enabled
    user_labels        = {}
    database_flags     = var.database_flags
    backup_configuration = {
      binary_log_enabled             = true
      transaction_log_retention_days = 7
    }
    ip_configuration = {
      ipv4_enabled        = false
      authorized_networks = []
      require_ssl         = true
      private_network     = data.google_compute_network.network.id
      allocated_ip_range  = r.allocated_ip_range
    }
  }]
  backup_configuration = {
    enabled                        = true
    location                       = "eu"
    binary_log_enabled             = true
    retained_backups               = 14
    retention_unit                 = "COUNT"
    start_time                     = "00:00"
    transaction_log_retention_days = 7
  }
  database_flags = var.database_flags
}

Terraform Version

terraform version
Terraform v1.7.5
on darwin_amd64
+ provider registry.terraform.io/hashicorp/google v5.23.0
+ provider registry.terraform.io/hashicorp/google-beta v5.23.0
+ provider registry.terraform.io/hashicorp/null v3.2.2
+ provider registry.terraform.io/hashicorp/random v3.6.0


### Additional information

_No response_
OscarVanL commented 7 months ago

I have a fix in https://github.com/terraform-google-modules/terraform-google-sql-db/pull/589

imrannayer commented 7 months ago

Fixed in #589

OscarVanL commented 7 months ago

Thanks for approving and making a release @imrannayer