How to assign static internal ip to google_sql_database_instance?


how can I assign static ip address (from my VPC) to google_sql_database_instance?

tf docco: Private Ip Instance offers google_service_networking_connection usage, but that doesn’t allow to assign definite ip address to the instance but the range

so, can I somehow get a definite static ip address (perhaps reserved from my VPC addresses with google_compute_address) assigned to google_sql_database_instance?

Admittedly I haven’t tested this but I assume you could associate a /32 address with a service networking connection.

resource "google_compute_global_address" "service_ip_range" {
  project       = var.project_id
  network       = var.network_self_link
  name          = "sql-private-ip"
  purpose       = "VPC_PEERING"
  address       = ""
  address_type  = "INTERNAL"
  prefix_length = 32

resource "google_service_networking_connection" "private_service_connection" {
  network                 = var.network_self_link
  service                 = ""
  reserved_peering_ranges = [,

However, if it’s an option I recommend not worrying about what the IP is and just tying it to a private Cloud DNS record instead. That feels less brittle to me.

resource "google_dns_record_set" "sql_dns" {
  name         = ""
  project      = var.project_id
  managed_zone = var.private_dns_zone_name
  type         = "A"
  ttl          = 300
  rrdatas      = [google_sql_database_instance.main.ip_address[0].ip_address]

thank you for your reply

I’m just wondering, why cann’t I use address/es from my VPC … why the only option is a
resource google_service_networking_connection …