[英]How to use for_each referencing to another resource in Terraform?
I want to create a nat_gateway that allocates to all the public_su.net ids and eip nate ids however terraform is erroring我想创建一个分配给所有 public_su.net id 和 eip nate id 的 nat_gateway 但是 terraform 是错误的
│ aws_su.net.su.nets_public is object with 3 attributes
│ │ each.key is "5"
│ │ each.key 是“5”
resource "aws_nat_gateway" "natgw" {
for_each = {
for i, v in var.subnets : i => v
if v.type == "public"
}
allocation_id = aws_eip.nat_eip[each.key].id
subnet_id = aws_subnet.subnets_public[each.key].id
depends_on = [aws_internet_gateway.igw]
}
You are filtering a list in for_each
.您正在过滤
for_each
中的列表。 So that some indexes
is missing.因此缺少一些
indexes
。 Then you are trying to call aws_eip.nat_eip
with non-existing index then you are getting error.然后您尝试使用不存在的索引调用
aws_eip.nat_eip
然后您收到错误。
If you can share your var.su.nets
and terraform error then we can help you to fix the error(s).如果您可以分享您的
var.su.nets
和 terraform 错误,那么我们可以帮助您修复错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.