地形列表需要其他方括号

时间:2018-12-17 23:26:08

标签: terraform terraform-provider-newrelic

我有以下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"
  }
}

我试图简化它。您可以看到我有一些数据是从新的文物提供程序中提取的,然后创建了一组应用程序,这些数据在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应该已经是列表了。有没有办法确保本地收到的清单?这是一个怪癖吗?

0 个答案:

没有答案