繁体   English   中英

如何使用 Terraform 检索给定 VPC 中的 su.net?

[英]How can I retrieve the subnets in a given VPC with Terraform?

我试图在给定的 VPC 中检索 su.net,在我的例子中是默认 VPC,但是我不断收到错误消息:

data "aws_vpc" "default_vpc" {
  default = true
}

data "aws_subnet" "subnets" {
  vpc_id = data.aws_vpc.default_vpc.id
}

output "subnets_out" {
  value = data.aws_subnet.subnets
}

错误:匹配多个 EC2 Su.net; 使用额外的约束来减少对单个 EC2 Su.net 的匹配

第一个数据调用有效,我得到了我的默认 VPC id,但是第二个失败了。

最初我在我的默认 VPC 中有 1 个 su.net,那时,第二个数据调用也有效,但令我惊讶的是它返回 su.net 作为 map 而不是集合中的 map。 所以我很好奇,如果我的 VPC 中有多个 su.net,然后数据调用失败,会发生什么情况。

我发现真正令人困惑的是Terraform 文档说:

此资源可用于取回一su.net ID

如果它应该返回一组 su.net ID,那么为什么匹配多个 su.net 是个问题?

aws_su.net是特定 su.net 的资源。 它不是用于 su.net 的集合。 因此,当您传递 VPC_ID 时,aws 会在该 VPC 中找到多个 su.net。 aws_su.net 中不能存储多个aws_su.net

https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/su.net

aws_su.net 提供有关特定 VPC su.net 的详细信息。

听起来你应该使用aws_su.nets https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/su.nets

此资源可用于取回一组 su.net ID。

这将返回一个 su.net ID 的列表,然后您可以在aws_su.net的 foreach 中使用它来获取每个 su.net 的具体细节

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM