【发布时间】:2020-03-23 11:14:27
【问题描述】:
我正在尝试为我的应用服务设置一个 azurerm_monitor_metric_alert,我想定义一个警报,涵盖 terraform 正在构建的所有应用服务。
我构建的应用服务有两个维度,一个基于区域(最多两个),另一个基于部署到每个应用服务计划的应用服务数量(未知数字,下例中为两个)。
我希望我可以这样做:
resource "azurerm_monitor_metric_alert" "disk1" {
name = "AppService-diskSpace-Sev1"
resource_group_name = azurerm_resource_group.location1[0].name
scopes = ["${azurerm_app_service.location1.*.id}","${azurerm_app_service.location2.*.id}"]
description = "Disk space over 90 percent"
window_size = "PT6H"
frequency = "PT1H"
criteria {
metric_namespace = "Microsoft.Web/sites"
metric_name = "FileSystemUsage"
aggregation = "Average"
operator = "GreaterThan"
threshold = 241591910400 # 90% of 250Gb in bytes
}
severity = 1
}
但我收到如下错误:
Error: Incorrect attribute value type
on ..\..\..\infra\terraform\global\web\main.tf line 343, in resource "azurerm_monitor_metric_alert" "disk1":
343: scopes = ["${azurerm_app_service.location1.*.id}","${azurerm_app_service.location2.*.id}"]
|----------------
| azurerm_app_service.location is tuple with 2 elements
| azurerm_app_service.location2 is tuple with 2 elements
Inappropriate value for attribute "scopes": element 0: string required.
我尝试了许多不同的选项,但都产生错误,文档说
“应应用度量标准的一组资源 ID 字符串”
但我不确定“一组字符串”在这种情况下是什么意思。
-- 编辑 在下面的 cmets 之后,我尝试了我希望得到的建议,但我仍然收到错误:
concat(azurerm_app_service.location.*.id)
返回
Error: scopes: attribute supports 1 item maximum, config has 2 declared.
["${azurerm_app_service.location.*.id}"]
返回
Inappropriate value for attribute "scopes": element 0: string required.
"${azurerm_app_service.web.*.id}"
返回
Error: scopes: attribute supports 1 item maximum, config has 2 declare
【问题讨论】:
-
${azurerm_app_service.location1.*.id}是一个 ID 列表,因此[${azurerm_app_service.location1.*.id}, ...]创建一个列表列表。您不需要额外的括号,只需使用concat函数加入 2 个列表即可。 -
恐怕我仍然无法让它工作:
concat(azurerm_app_service.location.*.id)返回Error: scopes: attribute supports 1 item maximum, config has 2 declared。["${azurerm_app_service.location.*.id}"]返回Inappropriate value for attribute "scopes": element 0: string required.。"${azurerm_app_service.web.*.id}"返回Error: scopes: attribute supports 1 item maximum, config has 2 declare -
您应该编辑您的问题以包含您尝试过的所有内容。
-
我已经尝试了许多不同的方法,但都不起作用,我认为用失败的例子乱扔我的问题没有太大的价值,我只需要一个应该起作用的例子,我可以去从那里开始。
-
你只是试图用这种方式回复,但基本上是不可读的。您应该编辑问题,而不是使用代码块或错误消息进行评论。从评论中很难确定您是否真的尝试连接 2 个列表,或者您只是传递了一个列表,该列表不是该函数的工作方式(然后会被要求连接多个非列表对象)。但是因为你在评论中回复了,所以无法判断。
标签: terraform terraform-provider-azure azure-rm