【发布时间】:2020-02-06 22:16:55
【问题描述】:
我正在编写 terraform 代码以在我们在 google 工作的每个区域中保留一些 IP 地址,稍后我将使用这些地址分配给几个特定实例。
所以在我的模块中我有一个
resource "google_compute_address" "reserved_public_ip" {
}
遍历计数并记录项目、地址类型、名称、区域、子网和地址。
所以我最终得到了 google_compute_address.reserved_public_ip 数组。我可以轻松地列出所有名称和 IP 地址
output "public_reservedip" {
value = "${zipmap(
google_compute_address.reserved_public_ip.*.name,
google_compute_address.reserved_public_ip.*.address
)}"
}
但我无法使用 *.region 使用 zipmap 制作 region->ipaddress 的地图,因为每个区域有 3 个 ip,所以我只会得到最后一个 ip 地址,因为区域键重复。
我要构建的是表单的输出
value = {
region1 = [list of ips]
region2 = [list of ips]
etc...
}
所以我可以将其提供给创建适当 gcp 主机的模块,并且它可以获取当前正在创建的区域的列表,但我无法确定可以让我这样做的转换。
我必须使用的示例数据:
module.gcp-network.google_compute_address.reserved_public_ip.0:
id = myproject/northamerica-northeast1/dns-reserve-1-test
address = 10.128.0.2
address_type = INTERNAL
creation_timestamp = 2019-10-08T15:41:08.690-07:00
description =
name = dns-reserve-1-test
network_tier = PREMIUM
project = myproject
purpose = GCE_ENDPOINT
region = northamerica-northeast1
self_link = https://www.googleapis.com/compute/v1/projects/myproject/regions/northamerica-northeast1/addresses/dns-reserve-1-test
subnetwork = https://www.googleapis.com/compute/v1/projects/myproject/regions/northamerica-northeast1/subnetworks/test-northamerica-northeast1-public-subnet
users.# = 0
【问题讨论】:
-
我应该补充一点,我们还没有跳到 .12,我还在使用 .11,在我们审查相当大的代码库之前,我们不能跳到 .12。跨度>
-
每个
google_compute_address.reserved_public_ip.*.name都是一个区域吗?如果没有,区域输入在哪里? -
*.region 是区域... *.name 是标签。
标签: terraform terraform-provider-gcp