For , I need to be able to provision multiple SQL DBs in GCP. These DBs also need to be on a VPC with a private IP address.
Config
resource "google_compute_network" "container_network" {
name = "container-network"
}
resource "google_compute_global_address" "sql" {
name = "sql-private-ip"
purpose = "VPC_PEERING"
address_type = "INTERNAL"
prefix_length = 16
network = google_compute_network.container_network.self_link
}
resource "google_service_networking_connection" "sql" {
network = google_compute_network.container_network.self_link
service = "servicenetworking.googleapis.com"
reserved_peering_ranges = [google_compute_global_address.sql.name]
}
resource "google_sql_database_instance" "master" {
provider = google-beta
count = 1
database_version = "MYSQL_5_7"
depends_on = [google_service_networking_connection.sql]
settings {
tier = "db-f1-micro"
ip_configuration {
ipv4_enabled = false
private_network = google_compute_network.container_network.id
}
}
}
When I use this config for a single database, this works fine. If I then change count = 2, that works fine as well. However, if I destroy the infrastructure and set count = 2, it fails.
Error: Error waiting for Create Instance: Failed to create subnetwork. <eye3 title='INVALID_ARGUMENT'/> generic::INVALID_ARGUMENT: New subnetwork overlaps with an IP range (10.28.0.0/24) in one of the active peers of an active peer (consumer-311061328248).
To me, this seems that the two databases are being created simultaneously and try to assign the same IP range.
Is there a way to create the databases sequentially instead or simultaneously? I suspect this will be a Terraform issue, rather than a GCP one although I'm open to ideas on this.