terraform try() function not found

Viewed 1020

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:

enter image description here

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.

1 Answers

The try function was added in version 0.12.20. You will need to update from 0.12.18 to at least that version to have access to the try function. Note the relevant release notes for this.

Related