有没有一种方法可以像我用aws_subnet_ids一样列出GCP VPC的所有cidr



https://www.terraform.io/docs/providers/aws/d/subnet_ids.html

AWS提供商使这成为可能:

data "aws_subnet_ids" "example" {
vpc_id = var.vpc_id
}
data "aws_subnet" "example" {
for_each = data.aws_subnet_ids.example.ids
id       = each.value
}
output "subnet_cidr_blocks" {
value = [for s in data.aws_subnet.example : s.cidr_block]
}

但是,有没有办法用谷歌计算网络和谷歌计算子网络来做到这一点?google_compute_subnetwork支持self_link,而google_computer_network有一个属性subnetworks_self_links——我只是不知道如何将它们连接在一起。

好吧,我想我得到了

data "google_compute_network" "vpc" {
name = google_compute_network.default-vpc.name
}
data "google_compute_subnetwork" "subnetworks" {
for_each = toset(data.google_compute_network.vpc.subnetworks_self_links)
self_link       = each.value
}
output "ip-cidr-ranges" {
value = [for s in data.google_compute_subnetwork.default-vpc-subnetworks : s.ip_cidr_range]
}

这似乎有效,但如果有人能证实我没有做傻事,我会很感激。到目前为止,我只有一个子网络。尚未使用多个进行测试

最新更新