Reputation: 3256
I have following code for creating an 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"]
}
}
Above code stopped working in version .12, it was working in .11. I tried following to replace element:
"tolist(data.aws_subnet_ids.trust-sub01.ids)[0]"
and:
"index(data.aws_subnet_ids.trust-sub01.ids)[0]"
both are not working it is giving me an error "The subnet ID does not exist"
Upvotes: 1
Views: 108
Reputation: 718
Is there any reason you're not just using the aws_subnet data source. You can dial in which subnet gets returned using filters and then use the id
attribute from that:
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"]
}
}
If you have to use aws_subnet_ids
like creating a network interface for each subnet you could do something like this:
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"]
}
}
Upvotes: 1