在terraform azurerm\u监视器\u度量\u警报范围设置中使用splat运算符

在terraform azurerm\u监视器\u度量\u警报范围设置中使用splat运算符,terraform,terraform-provider-azure,azure-rm,Terraform,Terraform Provider Azure,Azure Rm,我正在尝试为我的应用程序服务设置azurerm_monitor_metric_警报,我想定义一个警报,涵盖terraform正在构建的所有应用程序服务 我构建的应用程序服务有两个维度,一个基于区域(最多两个),另一个基于部署到每个应用程序服务计划的应用程序服务数量(未知数量,下例中为两个) 我希望我能做一些类似的事情: resource "azurerm_monitor_metric_alert" "disk1" { name = "AppService-dis

我正在尝试为我的应用程序服务设置azurerm_monitor_metric_警报,我想定义一个警报,涵盖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字符串”

但我不确定“一组字符串”在这个上下文中是什么意思

--编辑 在下面的评论之后,我尝试了我希望得到的建议,但仍有错误:

concat(azurerm_app_service.location.*.id)
返回

Error: scopes: attribute supports 1 item maximum, config has 2 declared. 
返回

Inappropriate value for attribute "scopes": element 0: string required.
Error: scopes: attribute supports 1 item maximum, config has 2 declare
返回

Inappropriate value for attribute "scopes": element 0: string required.
Error: scopes: attribute supports 1 item maximum, config has 2 declare

这个问题已经很老了,但仍然没有答案,我也有一个类似的问题,所以我给你我的研究结果:

首先,terraform 0.12中的splat表达式语法发生了更改,因此resource.*.attribute现在是resource[*].attribute。这将返回一个列表,这就是为什么会出现“不适当的值”错误:

这是正确的

另一个错误:“scopes:attribute最多支持1项,config有2个declare”是因为其他必需的属性,如果您对scopes使用多个值。在属性target_resource_type和target_resource_location处查看此资源的提供程序文档。如果使用多个作用域,则需要这两个:


我无法在azure上测试这一点,因为我们没有使用它,但我希望它能有所帮助。

${azurerm_app_service.location1.*.id}是一个id列表,所以
[${azurerm_app_service.location1.*.id},…
创建了一个列表。您不需要额外的括号,只需使用
concat
函数将两个列表连接起来即可。恐怕我仍然无法实现这一点:
concat(azurerm\u app\u service.location.*.id)
返回
错误:范围:属性最多支持1项,配置已声明2项
[“${azurerm\u app\u service.location.*.id}”]
为属性“scopes”返回
不适当的值:元素0:需要字符串。
“${azurerm_app_service.web.*.id}”
返回
错误:作用域:属性最多支持1项,配置有2个declare
您应该编辑您的问题,以包含您尝试过的所有内容。我尝试过许多不同的方法,但都不起作用,我看不到用失败的示例乱扔问题的巨大价值,我只需要一个例子,说明什么应该有效,我可以从那里开始。你只是试图用一种基本上无法理解的方式回答。您应该编辑问题,而不是用代码块或错误消息进行注释。从注释中很难看出您是真的试图连接两个列表,还是只传递了一个列表,而该列表不是函数的工作方式(然后会被要求连接多个非列表对象)。但是因为你在评论中回复了,所以很难说。
scopes = concat(azurerm_app_service.location1[*].id, azurerm_app_service.location2[*].id)