未找到 terraform try() 函数

terraform try() function not found

我正在尝试使用 aws_network_interfaces terraform 资源的数据查找来查找 NLB 的 ENI。如果可以找到任何 ENI,这就像一个魅力,但是当您执行第一个计划并且 AWS 帐户仍然为空时,资源会引发错误。

这里是查询:

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"]
  }
}

为了解决这个问题,我想使用 terraform try() function,但出现以下错误:

我是这样实现的:

locals {
  nlb_interface_ids = try(flatten(["${data.aws_network_interfaces.this.ids}"]), [])
}

我是 运行 terraform v0.12.18。有人可以帮忙吗

try 功能是在 0.12.20 版本中添加的。您需要从 0.12.18 更新到至少该版本才能访问 try 功能。请注意与此相关的 release notes