[英]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.