首页 > 解决方案 > Terraform 列表需要额外的方括号

问题描述

我有以下地形代码

data "newrelic_application" "app1" {
  name = "app1"
}
data "newrelic_application" "app2" {
  name = "app2"
}

locals {
  apps = [
    "${data.newrelic_application.app1.id}",
    "${data.newrelic_application.app2.id}"
  ]
}

resource "newrelic_alert_condition" "api-response-time-background" {
  policy_id       = "${newrelic_alert_policy.my-policy.id}"
  name            = "API Response Time Background"
  type            = "apm_app_metric"
  entities        = "${local.apps}"  # <<<< Referenced here
  metric          = "response_time_background"
  condition_scope = "application"

  term {
    duration      = 5
    operator      = "above"
    priority      = "critical"
    threshold     = "1"
    time_function = "all"
  }
}

我试图简化它。您可以看到我从新的 relic 提供程序中提取了一些数据,然后我创建了一个应用程序数组,我在 newrelic_alert_condition - 实体中引用了这些应用程序。

这会引发以下错误

Error: newrelic_alert_condition.api-response-time-background: apps:` should be a list

当我修改资源以使实体是这样的数组时

 resource "newrelic_alert_condition" "api-response-time-background" {
  policy_id       = "${newrelic_alert_policy.my-policy.id}"
  name            = "API Response Time Background"
  type            = "apm_app_metric"
  entities        = ["${local.apps}"]  # <<<< Updated here
  metric          = "response_time_background"
  condition_scope = "application"

  term {
    duration      = 5
    operator      = "above"
    priority      = "critical"
    threshold     = "1"
    time_function = "all"
  }
}

这行得通。我想知道的是为什么没有方括号它不起作用,因为local我传入的应该已经是一个列表。有没有办法确保本地收到的是一个列表?这是 terraform 的怪癖吗?

标签: terraform

解决方案


推荐阅读