【问题标题】:Is there a way to a list of all cidrs for a GCP VPC like I can with aws_subnet_ids?有没有办法像使用 aws_subnet_ids 一样列出 GCP VPC 的所有 cidr?
【发布时间】:2020-04-07 15:00:11
【问题描述】:

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_network 和 google_compute_subnetwork 做到这一点? google_compute_subnetwork 支持 self_link 并且 google_compute_network 有一个属性 subnetworks_self_links - 我只是不确定如何将它们连接在一起。

【问题讨论】:

    标签: terraform terraform-provider-gcp


    【解决方案1】:

    好吧,我明白了

    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]
    }
    

    这似乎可行,但如果有人能确认我没有做愚蠢的事情,我将不胜感激。截至目前,我只有 一个 子网。还没有用多个测试过

    【讨论】:

      猜你喜欢
      • 2014-03-28
      • 2010-10-21
      • 2012-01-12
      • 1970-01-01
      • 1970-01-01
      • 2018-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多