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
263 stars 423 forks source link

Error: MySQL HA non-replica instances need to have binary logging enabled while trying to create Postgres instance #562

Closed rrajvans closed 6 months ago

rrajvans commented 9 months ago

TL;DR

Getting this error anytime I try to create PostgreSQL instance: Error: MySQL HA non-replica instances need to have binary logging enabled while trying to create Postgres instance

Expected behavior

Instance should have been created without any issues.

Observed behavior

Error: MySQL HA non-replica instances need to have binary logging enabled while trying to create Postgres instance

Terraform Configuration

module "sql-db" {
  source  = "GoogleCloudPlatform/sql-db/google//modules/postgresql"
  version = "~> 18.0"

  project_id        = var.project_id
  region            = "us-central1"
  zone              = "us-central1-b"
  name              = "test-labelstudio-pgs-instance"
  availability_type = "REGIONAL"
  database_version  = "POSTGRES_16"
  tier              = "db-g1-small"

  deletion_protection = false

  read_replicas = [
    {
      name              = "0"
      user_labels       = {}
      zone              = "us-central1-b"
      availability_type = "REGIONAL"
      tier              = "db-g1-small"
      ip_configuration = {
        allocated_ip_range  = null
        authorized_networks = []
        ipv4_enabled        = true
        private_network     = null
        require_ssl         = false
      }
    },
  ]

  backup_configuration = {
    binary_log_enabled             = true
    enabled                        = true
    start_time                     = "20:55"
    point_in_time_recovery_enabled = true
  }

  # Might create issue
  additional_databases = [{ name : "test-labelstudio-pgs-db"
    charset = "utf8mb4"
  collation = "utf8mb4_0900_ai_ci" }, ]

  disk_type     = "PD_HDD"
  disk_size     = 10
  # Note: https://github.com/terraform-google-modules/terraform-google-sql-db/blob/master/modules/postgresql/README.md#terraform-google-sql-for-postgresql
  disk_autoresize = true

}

Also tried this with some edits. Had to remove database_flags as I was getting error Error: Error, failed to create instance example-labelstudio-pgs-instance-2848869b: googleapi: Error 404: The requested flag is either misspelled or unsupported by Cloud SQL.:

locals {
  read_replica_ip_configuration = {
    ipv4_enabled       = true
    require_ssl        = false
    ssl_mode           = "ENCRYPTED_ONLY"
    private_network    = null
    allocated_ip_range = null
    # authorized_networks = [
    #   {
    #     name  = "${var.project_id}-cidr"
    #     value = var.pg_ha_external_ip_range
    #   },
    # ]
  }
}

module "pg" {
  source  = "GoogleCloudPlatform/sql-db/google//modules/postgresql"
  version = "~> 18.0"

  name                 = "example-labelstudio-pgs-instance"
  random_instance_name = true
  project_id           = var.project_id
  database_version     = "POSTGRES_16"
  region               = "us-central1"

  // Master configurations
  tier                            = "db-g1-small"
  zone                            = "us-central1-c"
  availability_type               = "REGIONAL"
  maintenance_window_day          = 7
  maintenance_window_hour         = 12
  maintenance_window_update_track = "stable"

  deletion_protection = false

  # database_flags = [{ name = "autovacuum", value = "off" }]

  user_labels = {
    foo = "bar"
  }

  ip_configuration = {
    ipv4_enabled       = true
    require_ssl        = true
    private_network    = null
    allocated_ip_range = null
    # authorized_networks = [
    #   {
    #     name  = "${var.project_id}-cidr"
    #     value = var.pg_ha_external_ip_range
    #   },
    # ]
  }

  backup_configuration = {
    enabled                        = true
    start_time                     = "20:55"
    location                       = null
    point_in_time_recovery_enabled = false
    transaction_log_retention_days = null
    retained_backups               = 365
    retention_unit                 = "COUNT"
  }

  // Read replica configurations
  read_replica_name_suffix = "-test-ha"
  read_replicas = [
    {
      name              = "0"
      zone              = "us-central1-a"
      availability_type = "REGIONAL"
      tier              = "db-g1-small"
      ip_configuration  = local.read_replica_ip_configuration
      # database_flags        = [{ name = "autovacuum", value = "off" }]
      disk_autoresize       = null
      disk_autoresize_limit = null
      disk_size             = null
      disk_type             = "PD_HDD"
      user_labels           = { bar = "baz" }
      encryption_key_name   = null
    },
  ]

  db_name      = "test-labelstudio-pgs-db"
  db_charset   = "UTF8"
  db_collation = "en_US.UTF8"

  additional_databases = [
    {
      name      = "test-labelstudio-pgs-db}-additional"
      charset   = "UTF8"
      collation = "en_US.UTF8"
    },
  ]

  user_name     = "tftest"
  user_password = "foobar"

  additional_users = [
    {
      name            = "tftest2"
      password        = "abcdefg"
      host            = "localhost"
      random_password = false
    },
    {
      name            = "tftest3"
      password        = "abcdefg"
      host            = "localhost"
      random_password = false
    },
  ]
}

Terraform Version

This is what I get during `terraform apply`:

.storage.module.pg.google_sql_database_instance.default: Creating...
╷
│ Error: Error, failed to create instance example-labelstudio-pgs-instance-2848869b: googleapi: Error 400: Invalid request: Invalid flag for instance role: MySQL HA non-replica instances need to have binary logging enabled.
│ Details:
│ [
│   {
│     "@type": "type.googleapis.com/google.rpc.DebugInfo",
│     "detail": "[ORIGINAL ERROR] boss::8: Invalid flag for instance role: MySQL HA non-replica instances need to have binary logging enabled [gdata.Errors] { error { domain: \"gdata.CoreErrorDomain\" code: \"INVALID_VALUE\" argument: \"Invalid flag for instance role: MySQL HA non-replica instances need to have binary logging enabled\" location_type: PATH location: \"\" debug_info: \"BossException (INVALID_REQUEST): Invalid flag for instance role: MySQL HA non-replica instances need to have binary logging enabled. {domain: gdata.CoreErrorDomain, code: INVALID_VALUE, arguments, [Invalid flag for instance role: MySQL HA non-replica instances need to have binary logging enabled]}\\n\\tat com.google.storage.speckle.boss.util.exception.BossException.invalidExternalApiRequest(BossException.java:771)\\n\\tat com.google.storage.speckle.boss.internal.InstanceChecker.checkValidMetadata(InstanceChecker.java:2366)\\n\\tat com.google.storage.speckle.boss.internal.InstanceChecker.checkBaseInstanceForCreation(InstanceChecker.java:418)\\n\\tat com.google.storage.speckle.boss.internal.InstanceChecker.checkV2InstanceForCreation(InstanceChecker.java:697)\\n\\tat com.google.storage.speckle.boss.internal.InstanceCreator.lambda$initShadowProjectStrategy$3(InstanceCreator.java:630)\\n\\tat com.google.storage.speckle.boss.metadata.TenancyUnitStrategy.initV2Instance(TenancyUnitStrategy.java:50)\\n\\tat com.google.storage.speckle.boss.internal.InstanceCreator.initShadowProjectStrategy(InstanceCreator.java:626)\\n\\tat com.google.storage.speckle.boss.internal.InstanceCreator.createInstance(InstanceCreator.java:454)\\n\\tat com.google.storage.speckle.boss.internal.InstanceCreator.createInstance(InstanceCreator.java:430)\\n\\tat com.google.storage.speckle.boss.internal.InstanceCrudRequestHandler.createInstance(InstanceCrudRequestHandler.java:527)\\n\\tat com.google.storage.speckle.boss.admin.actions.InstancesServiceHelper.insertSpeckleInstance(InstancesServiceHelper.java:423)\\n\\tat com.google.storage.speckle.boss.admin.actions.InstanceInsertAction.execute(InstanceInsertAction.java:234)\\n\\tat jdk.internal.reflect.GeneratedMethodAccessor1740.invoke(Unknown Source)\\n\\tat java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)\\n\\tat java.base/java.lang.reflect.Method.invoke(Unknown Source)\\n\\tat com.google.storage.speckle.boss.admin.logging.interceptors.ActionLogInterceptor.intercept(ActionLogInterceptor.java:53)\\n\\tat com.google.common.bytecode.ProxyMaker$Callback.intercept(ProxyMaker.java:268)\\n\\tat com.google.storage.speckle.boss.admin.actions.InstanceInsertAction$ByteBuddy$4vpvW2F2.execute(Unknown Source)\\n\\tat com.google.storage.speckle.boss.admin.actions.InstanceInsertAction$ByteBuddy$4vpvW2F2.execute(Unknown Source)\\n\\tat com.google.storage.speckle.boss.admin.framework.impl.RpcImpl.execute(RpcImpl.java:100)\\n\\tat com.google.storage.speckle.boss.admin.V1beta4InstancesServiceImpl.insert(V1beta4InstancesServiceImpl.java:329)\\n\\tat com.google.cloud.sql.v1beta4.SqlInstancesService$ServiceParameters$48.handleBlockingRequest(SqlInstancesService.java:3589)\\n\\tat com.google.cloud.sql.v1beta4.SqlInstancesService$ServiceParameters$48.handleBlockingRequest(SqlInstancesService.java:3587)\\n\\tat com.google.net.rpc3.impl.server.RpcBlockingApplicationHandler.handleRequest(RpcBlockingApplicationHandler.java:28)\\n\\tat com.google.net.rpc3.impl.server.RpcServerInterceptor2Util$RpcApplicationHandlerAdaptor.handleRequest(RpcServerInterceptor2Util.java:82)\\n\\tat com.google.net.rpc3.impl.server.AggregatedRpcServerInterceptors.interceptRpc(AggregatedRpcServerInterceptors.java:100)\\n\\tat com.google.net.rpc3.impl.server.RpcServerInterceptor2Util$InterceptedApplicationHandlerImpl.handleRequest(RpcServerInterceptor2Util.java:67)\\n\\tat com.google.net.rpc.contrib.rpcinjectz2.RpcInjectz2ServerFaultInterceptor.interceptRpc(RpcInjectz2ServerFaultInterceptor.java:57)\\n\\tat com.google.net.rpc3.impl.server.RpcServerInterceptor2Util$InterceptedApplicationHandlerImpl.handleRequest(RpcServerInterceptor2Util.java:67)\\n\\tat com.google.net.rpc3.impl.server.RpcServerInternalContext.runRpcInApplicationWithCancellation(RpcServerInternalContext.java:686)\\n\\tat com.google.net.rpc3.impl.server.RpcServerInternalContext.lambda$runRpcInApplication$0(RpcServerInternalContext.java:651)\\n\\tat io.grpc.Context.run(Context.java:536)\\n\\tat com.google.net.rpc3.impl.server.RpcServerInternalContext.runRpcInApplication(RpcServerInternalContext.java:651)\\n\\tat com.google.net.rpc3.impl.server.RpcServerChannel$4.apply(RpcServerChannel.java:1062)\\n\\tat com.google.net.rpc3.impl.server.RpcServerChannel$4.apply(RpcServerChannel.java:1023)\\n\\tat com.google.common.util.concurrent.AbstractTransformFuture$TransformFuture.doTransform(AbstractTransformFuture.java:253)\\n\\tat com.google.common.util.concurrent.AbstractTransformFuture$TransformFuture.doTransform(AbstractTransformFuture.java:243)\\n\\tat com.google.common.util.concurrent.AbstractTransformFuture.run(AbstractTransformFuture.java:124)\\n\\tat com.google.common.context.ContextRunnable.runInContext(ContextRunnable.java:83)\\n\\tat io.grpc.Context.run(Context.java:536)\\n\\tat com.google.tracing.GenericContextCallback.runInInheritedContext(GenericContextCallback.java:75)\\n\\tat com.google.common.context.ContextRunnable.run(ContextRunnable.java:74)\\n\\tat java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)\\n\\tat java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)\\n\\tat java.base/java.lang.Thread.run(Unknown Source)\\nCaused by: com.google.storage.speckle.common.store.MetadataException$InvalidModelStateException: MySQL HA non-replica instances need to have binary logging enabled\\n\\tat com.google.storage.speckle.metadata.model.BaseChecks.checkState(BaseChecks.java:18)\\n\\tat com.google.storage.speckle.boss.internal.InstanceChecker.checkV2InstanceMetadata(InstanceChecker.java:2442)\\n\\tat com.google.storage.speckle.boss.internal.InstanceChecker.checkValidMetadata(InstanceChecker.java:2346)\\n\\t... 43 more\\n\\n\" } }"
│   }
│ ]
│ , invalid
│ 
│   with module.storage.module.pg.google_sql_database_instance.default,
│   on .terraform/modules/storage.pg/modules/postgresql/main.tf line 53, in resource "google_sql_database_instance" "default":
│   53: resource "google_sql_database_instance" "default" {

Additional information

No response

github-actions[bot] commented 7 months ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

kryptiksage commented 4 months ago

got this error for me too. Fixed - the database_version should be correct Ref: link