我们的云后端设置包含 5 个用于 Postgres 实例的 Cloud SQL。我们使用 Terraform 管理我们的基础设施。我们使用公共 IP 和Cloud SQL 容器从 GKE 连接它们。
为了简化我们的设置,我们希望通过移动到私有 IP 来摆脱代理容器。我尝试遵循Terraform 指南。虽然创建单个实例可以正常工作,但尝试同时创建 5 个实例会导致 4 个失败和一个成功:
在失败实例上出现在 Google Clod 控制台中的错误是“发生未知错误”:
以下是重现它的代码。注意count = 5
线:
resource "google_compute_network" "private_network" {
provider = "google-beta"
name = "private-network"
}
resource "google_compute_global_address" "private_ip_address" {
provider = "google-beta"
name = "private-ip-address"
purpose = "VPC_PEERING"
address_type = "INTERNAL"
prefix_length = 16
network = "${google_compute_network.private_network.self_link}"
}
resource "google_service_networking_connection" "private_vpc_connection" {
provider = "google-beta"
network = "${google_compute_network.private_network.self_link}"
service = "servicenetworking.googleapis.com"
reserved_peering_ranges = ["${google_compute_global_address.private_ip_address.name}"]
}
resource "google_sql_database_instance" "instance" {
provider = "google-beta"
count = 5
name = "private-instance-${count.index}"
database_version = "POSTGRES_9_6"
depends_on = [
"google_service_networking_connection.private_vpc_connection"
]
settings {
tier = "db-custom-1-3840"
availability_type = "REGIONAL"
ip_configuration {
ipv4_enabled = "false"
private_network = "${google_compute_network.private_network.self_link}"
}
}
}
provider "google-beta" {
version = "~> 2.5"
credentials = "credentials.json"
project = "PROJECT_ID"
region = "us-central1"
zone = "us-central1-a"
}
我尝试了几种选择:
google_service_networking_connection
创建然后同时创建所有实例后等待一分钟,但我得到了同样的错误。- 创建地址范围和
google_service_networking_connection
每个实例,但出现google_service_networking_connection
无法同时创建的错误。 - 为每个实例创建一个地址范围和一个
google_service_networking_connection
链接到所有实例的地址范围,但我遇到了同样的错误。