【问题标题】:Dynamic Block in Terraform - No more than 1 "dynamic_criteria" blocks are allowedTerraform 中的动态块 - 不允许超过 1 个“dynamic_criteria”块
【发布时间】:2021-07-28 09:58:36
【问题描述】:

我正在使用 terraform 在 Azure 中创建警报并遇到错误

resource "azurerm_monitor_metric_alert" "alertrule"{
  
for_each = var.triggermap 
  
    name = each.key
    resource_group_name = var.resource_group_name
    scopes              = [data.azurerm_function_app.funcapp.id]
    description = each.value


  dynamic "dynamic_criteria" {
    for_each = local.metric_name
    content {
    metric_namespace   = "Microsoft.Web/sites"
    metric_name        = dynamic_criteria.value
    aggregation        = "Total"
    operator           = "GreaterThan"
    alert_sensitivity  = "Medium" 
    ignore_data_before = timestamp() 

    dimension {
      name     = "Instance"
      operator = "Include"
      values   = ["*"]
    }
  

  action {
    action_group_id = azurerm_monitor_action_group.ag.id
  }
  }

}
} 

我遇到了错误,我试图通过创建多个动态条件在​​ azure 中创建多个警报,但是当我添加动态块时,它给了我以下问题,上面是我的 main.tf,而在本地我使用的是简单的地图和列表。请帮忙


│ Error: Too many dynamic_criteria blocks
│
│   on ../module/alert.tf line 58, in resource "azurerm_monitor_metric_alert" "alertrule":
│   58:     content {
│
│ No more than 1 "dynamic_criteria" blocks are allowed
╵
╷
│ Error: Unsupported block type
│
│   on ../module/alert.tf line 73, in resource "azurerm_monitor_metric_alert" "alertrule":
│   73:   action {
│
│ Blocks of type "action" are not expected here.
╵
╷
│ Error: Unsupported block type
│
│   on ../module/alert.tf line 73, in resource "azurerm_monitor_metric_alert" "alertrule":
│   73:   action {
│
│ Blocks of type "action" are not expected here.

【问题讨论】:

    标签: azure-devops terraform terraform-provider-azure


    【解决方案1】:

    您在dynamic_criteria 中定义了action,这是不受支持的,它应该在它之外。您也可以只有一个 dynamic_criteria,而不是像您想要的那样拥有多个。请查看docs:

    必须指定一个标准,dynamic_criteria 或 application_insights_web_test_location_availability_criteria。

    【讨论】:

    • 感谢您的帮助,解决了问题,我的问题陈述是我需要创建多个警报。我应该在资源块中使用计数吗?任何建议
    • @rohitsardana 两者都可以使用。这取决于你喜欢如何做到这一点。从长远来看,for_each 可能更容易管理。
    猜你喜欢
    • 1970-01-01
    • 2022-07-07
    • 2020-08-18
    • 1970-01-01
    • 2021-08-11
    • 2020-10-12
    • 2020-10-13
    • 1970-01-01
    相关资源
    最近更新 更多