简体   繁体   English

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

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

I was trying to retrieve the su.nets in a given VPC, in my case the default VPC, however I keep getting an error:我试图在给定的 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
}

Error: multiple EC2 Su.nets matched;错误:匹配多个 EC2 Su.net; use additional constraints to reduce matches to a single EC2 Su.net使用额外的约束来减少对单个 EC2 Su.net 的匹配

The first data call works, I get my default VPC id, however the second one fails.第一个数据调用有效,我得到了我的默认 VPC id,但是第二个失败了。

Originally I had 1 su.net in my default VPC and at that time, the second data call worked too but to my surprise it returned the su.net as a map instead of a map within a set.最初我在我的默认 VPC 中有 1 个 su.net,那时,第二个数据调用也有效,但令我惊讶的是它返回 su.net 作为 map 而不是集合中的 map。 So I was curious what would happen if there was more than one su.nets in my VPC but then the data call failed.所以我很好奇,如果我的 VPC 中有多个 su.net,然后数据调用失败,会发生什么情况。

What I find really confusing is that the Terraform documentation says:我发现真正令人困惑的是Terraform 文档说:

This resource can be useful for getting back a set of su.net ID s .此资源可用于取回一su.net ID

If it's supposed to return a set of su.net IDs, then why is it an issue that multiple su.nets were matched?如果它应该返回一组 su.net ID,那么为什么匹配多个 su.net 是个问题?

aws_su.net is a resource for a specific su.net. aws_su.net是特定 su.net 的资源。 Its not for a collection of su.nets.它不是用于 su.net 的集合。 so when you pass the VPC_ID, aws is finding more than one su.net in that VPC.因此,当您传递 VPC_ID 时,aws 会在该 VPC 中找到多个 su.net。 Its not possible to store more than one su.nets in aws_su.net aws_su.net 中不能存储多个aws_su.net

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

aws_su.net provides details about a specific VPC su.net. aws_su.net 提供有关特定 VPC su.net 的详细信息。

It sounds like you should be using aws_su.nets https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/su.nets听起来你应该使用aws_su.nets https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/su.nets

This resource can be useful for getting back a set of su.net IDs.此资源可用于取回一组 su.net ID。

This will return you a list of su.net ID's which you can then use in a foreach in aws_su.net to get the specific details of each su.net这将返回一个 su.net ID 的列表,然后您可以在aws_su.net的 foreach 中使用它来获取每个 su.net 的具体细节

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

相关问题 如何检索实例化模板化对象的类型? - How can I retrieve the type a templated object was instantiated with? 没有给出变量时,如何确定其类型? - How can I determine the type of a variable when it is not given? 如何从给定的字符串导入打字稿文件? - How can I import a typescript file from given string? 给定任何类型的向量,如何获得相同 class 的 NA 值? - Given a vector of any type, how can I get an NA value of the same class? 如何返回作为参数给出的相同Collection类型,但具有不同的元素类型? - How can I return the same Collection type given as a parameter, but with a different element type? 如何检查c#中的两个值是否相等? (给定任何类型的价值) - How can I check if two values in c# are equal? (Given any type of value) 给定一个包含类名称的字符串,然后我如何使用该类作为C#中的类型参数来调用泛型方法? - Given a string which holds the name of a class, how can I then call a generic method using that class as the type parameter in C#? 如何在运行时检索打字稿变量的自定义类型 - How do I retrieve the custom type of a typescript variable at runtime 如何检查给定变量值是否为string类型 - How to I check whether a given variable value is of type string 如何验证给定的输入是否是 Python 中的对象? - How do I validate if the given input is an object in Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM