【问题标题】:Filters are not filtering subnets in Terraform过滤器不过滤 Terraform 中的子网
【发布时间】:2021-03-01 07:47:08
【问题描述】:

自从我学习 Terraform 以来已经是第四天了,我遇到了一个问题。 我有四个子网 [公共网络公共1,公共网络公共2,公共网络私人1,公共网络私人2] 我只想选择 2subnets Public-web-Public 1,2 但它没有用 另外,我尝试使用标签而不是过滤器 但结果也没有找到匹配的子网 我不知道为什么? 请问你能帮帮我吗?

data "aws_subnet_ids" "test_subnet_ids" {
  vpc_id = "${aws_vpc.vpc1.id}"
}

data "aws_subnet" "test_subnet" {
  count = "${length(data.aws_subnet_ids.test_subnet_ids.ids)}"
        filter {
        name = "tag:Name"
        values = ["Public-web-Pub*"]
        }
  id    = "${tolist(data.aws_subnet_ids.test_subnet_ids.ids)[count.index]}"
}

output "subnet_id" {
  value = "${data.aws_subnet.test_subnet.*.id}"
}

【问题讨论】:

    标签: amazon-web-services terraform terraform-provider-aws


    【解决方案1】:

    您可以使用test_subnet_ids。无需 ``aws_subnet, just to get the ids of your two subnets. But once you get the ids, you can then use aws_subnet` 即可获取搜索中返回的每个子网的完整详细信息。

    data "aws_subnet_ids" "test_subnet_ids" {
    
      vpc_id = "${aws_vpc.vpc1.id}"
      
      filter {
        name   = "tag:Name"
        values = ["Public-web-Pub*"]
      }  
      
    }
    
    output "subnet_ids" {
      value = data.aws_subnet_ids.test_subnet_ids.ids
    }
    

    【讨论】:

    • @HHJ 这个问题是怎么解决的?还没有解决吗?
    猜你喜欢
    • 2021-11-28
    • 1970-01-01
    • 2021-04-29
    • 2023-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-25
    • 2017-05-19
    相关资源
    最近更新 更多