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 422 forks source link

Terrform Postgres Module creates MySQL Instance - Clarify documentation #610

Open KiranK-4 opened 2 months ago

KiranK-4 commented 2 months ago

TL;DR

Using the Postgres module creates a MySQL Instance using the same values provided in the README.md

Expected behavior

It should create a POSTGRES_9_6 database instance

Observed behavior

It creates MySQL 8.0 version Instance

Terraform Configuration

module "pg" {
  # checkov:skip=CKV_GCP_62:
  # checkov:skip=CKV_TF_1:
  source                          = "terraform-google-modules/sql-db/google//modules/postgresql"
  version                         = "~> 20.1"
  name                            = var.instance_name
  random_instance_name            = true
  project_id                      = var.project_id
  database_version                = var.db_version
  region                          = var.region
  db_name                         = var.db_name
  disk_size                       = var.db_disk_size
  disk_type                       = var.db_disk_type
  db_charset                      = "UTF8"
  db_collation                    = "en_US.UTF8"
  user_name                       = "${var.prefix}_user"
  user_password                   = var.password
  maintenance_window_day          = 7
  maintenance_window_hour         = 12
  maintenance_window_update_track = "stable"

  database_flags = [
    { name = "log_connections", value = "on" },
    { name = "log_min_duration_statement", value = "-1" },
    { name = "log_disconnections", value = "on" },
    { name = "log_lock_waits", value = "on" },

  ]

  ip_configuration = {
    ipv4_enabled       = false
    require_ssl        = false
    private_network    = var.vpc_network
    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               = 90
    retention_unit                 = "COUNT"
  }
}

Terraform Version

required_version = ">= 0.13"

Additional information

No response

imrannayer commented 2 months ago

@KiranK-4 what are the values passed in var.db_version?

alabdao commented 1 week ago

I see the same issue. I keep getting MYSQL 8.0 created while I have specified POSTGRES_16_3 However, when I just specify 16 as version, I get the correct DB created. Here's the HCL code:

module "sql" {
  providers = {
    google = google.use1
  }
  source  = "terraform-google-modules/sql-db/google//modules/postgresql"
  version = "~> 21.0"
  name             = "${var.folder}-${var.environment}-${var.region_short_name}-db"
  project_id       = local.project_id
  database_version = "POSTGRES_16_3"
  region           = var.region
}
imrannayer commented 1 week ago

I think variable description is misleading. It is expecting

9_6, 10, 11, 12, 13, 14, 15, 16 etc

Here is the logic

can(regex("\\d", substr(var.database_version, 0, 1))) ? format("POSTGRES_%s", var.database_version) : replace(var.database_version, substr(var.database_version, 0, 8), "POSTGRES")