I'm trying to lookup an NLB's ENIs using a data lookup for the aws_network_interfaces terraform resource. This works like a charm if any ENIs can be found, but when you do your first plan and the AWS account is still empty the resource throws an error.
Here is the lookup:
data "aws_network_interfaces" "this" {
filter {
name = "description"
values = ["ELB net/${aws_lb.proxy.name}/*"]
}
filter {
name = "vpc-id"
values = ["${var.vpc_id}"]
}
filter {
name = "status"
values = ["in-use"]
}
filter {
name = "attachment.status"
values = ["attached"]
}
}
To remedy this I want to use the terraform try() function, but I get the following error:
This is how I implemented it:
locals {
nlb_interface_ids = try(flatten(["${data.aws_network_interfaces.this.ids}"]), [])
}
I'm running terraform v0.12.18. Can someone please help.
