我有以下代码用于创建eni:
resource "aws_network_interface" "eth0" {
private_ips = "10.10.0.1"
security_groups = ["${aws_security_group.secg1.id}"]
subnet_id = "${element(data.aws_subnet_ids.sub01.ids,0)}"
lifecycle {
ignore_changes = ["subnet_id"]
}
}
上面的代码在.12版本中停止工作,在.11版本中工作。我尝试了以下内容来替换元素:
"tolist(data.aws_subnet_ids.trust-sub01.ids)[0]"
和:
"index(data.aws_subnet_ids.trust-sub01.ids)[0]"
两者都不工作,这给了我一个错误"子网ID不存在">
您不只是使用aws_subnet数据源有什么原因吗。您可以使用筛选器拨入返回的子网,然后使用其中的id
属性:
data "aws_subnet" "default" {
vpc_id = "vpc-0dfc13e14b4e1fa57"
filter {
name = "availability-zone-id"
values = ["use1-az4"]
}
}
resource "aws_network_interface" "eth0" {
private_ips = "172.31.16.1"
subnet_id = data.aws_subnet.default.id
lifecycle {
ignore_changes = ["subnet_id"]
}
}
如果你必须像为每个子网创建网络接口一样使用aws_subnet_ids
,你可以这样做:
data "aws_subnet_ids" "default" {
vpc_id = "vpc-0dfc13e14b4e1fa57"
}
resource "aws_network_interface" "eth0" {
count = length(data.aws_subnet_ids.default.ids)
subnet_id = element(tolist(data.aws_subnet_ids.default.ids),count.index)
lifecycle {
ignore_changes = ["subnet_id"]
}
}