terraform - 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 的怪癖吗?
解决方案
推荐阅读
- javascript - 为什么当我尝试将 php 变量添加到 sql 查询中时,我在 php 中的 sql 查询不起作用?
- javascript - 如何在javascript中同步运行异步函数?
- android - Is there any specific way to convert the LiveData to ArrayList without using the observer inside the repository while using MVVM with DI in android
- javascript - Reactjs(javascript)我怎么看不到列表为空(之前)api被调用
- angular - 部署时某些路由中不存在“Access-Control-Allow-Origin”标头
- ios - SwiftUI:处理导航和 UINavigationController 的等效方法
- sql-server - SQL Server:设计器不兼容的生成脚本
- javascript - “邮递员 - 如何同时检查任何键的类型是‘字符串’还是‘空’”
- android - 准备 SDK 包 Android Emulator 时出错:无法下载
- openssl - 无法在 centOs 中降级 openssl-libs