【发布时间】:2019-07-01 23:27:54
【问题描述】:
我们保留了静态(列入白名单)IP 地址,需要通过 terraform 将其分配给 GCP 上的 CloudNAT。 IP 被保留并在服务提供商处注册,这需要数周时间才能获得批准并添加到他们的防火墙中,因此动态分配不是一种选择。
对我们来说主要问题是 google_compute_router_nat 部分需要 nat_ip_allocate_option,但在这种情况下,IP 地址已经分配,因此它会失败并出现错误说明。分配的唯一选项是 AUTO_ONLY 和 MANUAL_ONLY,但似乎可能需要 EXISTING 或 RESERVED,除非我遗漏了一些明显的东西。
这是失败的配置:
resource "google_compute_address" "static_ip" {
name = "whitelisted-static-ip"
region = "${var.project_region}"
}
resource "google_compute_router_nat" "cluster-nat" {
name = "cluster-stg-nat"
router = "${google_compute_router.router.name}"
region = "${google_compute_router.router.region}"
nat_ip_allocate_option = "MANUAL_ONLY"
nat_ips = ["${google_compute_address.static_ip.self_link}"]
source_subnetwork_ip_ranges_to_nat = "LIST_OF_SUBNETWORKS"
subnetwork {
name = "${google_compute_subnetwork.service.self_link}"
source_ip_ranges_to_nat = ["ALL_IP_RANGES"]
}
}
导致以下错误:
Error: Error creating Address: googleapi: Error 409: The resource 'projects/staging-cluster/regions/us-central1/addresses/whitelisted-static-ip' already exists, alreadyExists
因为静态 IP 资源已经在 GCP 外部 IP 地址中保留并在服务提供商处注册。
【问题讨论】:
-
我并不完全清楚您描述的是什么错误。您能否粘贴您正在运行的确切 terraform 和完整的错误输出?
-
已编辑以删除配置的注释掉部分。希望这更清楚一点。
标签: terraform