Error: Unsupported attribute , each.value is object with 2 attributes
Error: Unsupported attribute , each.value is object with 2 attributes
我正在尝试使用 for_each 和本地人创建多个网络接口,这是我的代码
locals {
network_interfaces = {
a = {
subnet_id = module.vpc.public_subnets[0],
security_group = [aws_security_group.ssh.id],
},
b = {
subnet_id = module.vpc.public_subnets[0],
security_groups = [aws_security_group.ssh.id],
},
c = {
subnet_id = module.vpc.public_subnets[1],
security_groups = [aws_security_group.ssh.id],
},
d = {
subnet_id = module.vpc.public_subnets[1],
security_groups = [aws_security_group.ssh.id],
},
}
}
这里我尝试用 for_each 遍历 local.network_interfaces 所以我可以创建 4 个网络接口
resource "aws_network_interface" "this" {
for_each = local.network_interfaces
subnet_id = each.value.subnet_id
security_groups = each.value.security_groups
tags = {
Name = "${each.key}_network_interface"
}
}
但是当我 运行 Terraform 应用时,它给了我这个错误
│ Error: Unsupported attribute
│
│ on main.tf line 61, in resource "aws_network_interface" "this":
│ 61: security_groups = each.value.security_groups
│ ├────────────────
│ │ each.value is object with 2 attributes
│
│ This object does not have an attribute named "security_groups"
任何帮助将不胜感激
与map
值中的安全组对应的object
键与a
键需要匹配其他object
值中的键地图:
a = {
subnet_id = module.vpc.public_subnets[0],
security_groups = [aws_security_group.ssh.id],
},
我正在尝试使用 for_each 和本地人创建多个网络接口,这是我的代码
locals {
network_interfaces = {
a = {
subnet_id = module.vpc.public_subnets[0],
security_group = [aws_security_group.ssh.id],
},
b = {
subnet_id = module.vpc.public_subnets[0],
security_groups = [aws_security_group.ssh.id],
},
c = {
subnet_id = module.vpc.public_subnets[1],
security_groups = [aws_security_group.ssh.id],
},
d = {
subnet_id = module.vpc.public_subnets[1],
security_groups = [aws_security_group.ssh.id],
},
}
}
这里我尝试用 for_each 遍历 local.network_interfaces 所以我可以创建 4 个网络接口
resource "aws_network_interface" "this" {
for_each = local.network_interfaces
subnet_id = each.value.subnet_id
security_groups = each.value.security_groups
tags = {
Name = "${each.key}_network_interface"
}
}
但是当我 运行 Terraform 应用时,它给了我这个错误
│ Error: Unsupported attribute
│
│ on main.tf line 61, in resource "aws_network_interface" "this":
│ 61: security_groups = each.value.security_groups
│ ├────────────────
│ │ each.value is object with 2 attributes
│
│ This object does not have an attribute named "security_groups"
任何帮助将不胜感激
与map
值中的安全组对应的object
键与a
键需要匹配其他object
值中的键地图:
a = {
subnet_id = module.vpc.public_subnets[0],
security_groups = [aws_security_group.ssh.id],
},