指标数学警报:如何使用for_each表达式在动态块内循环指标?

时间:2020-09-08 15:59:13

标签: foreach terraform amazon-cloudwatch

我正在尝试创建可通过JSON配置的动态指标数学警报。

我正在用for_each表达式循环度量指标警报,因为这是一个循环中的循环。

以下是我要执行的操作的示例:

R is your typical 3x3 rotation matrix embedded in a 4x4 with 0,0,0,1 on the last line

v is a 3D vector with coordinates (x,y,z)
T is a 4x4 translation matrix, all zeroes except the last column where it has x,y,z,1
L is another 4x4 translation matrix, but now with q instead of v
L' is the inverse transformation of L

M = T * L * R * L'

这是示例JSON

resource "aws_cloudwatch_metric_alarm" "Percentage_Alert" {
  for_each = var.percentage_error_details
  locals { alarm_details = each.value }
  alarm_name          = "${terraform.workspace}-${each.key}"
  comparison_operator = local.alarm_details["Comparison_Operator"]
  evaluation_periods  = "1"
  threshold           = local.alarm_details["Threshold"]
  
  metric_query {
    id          = "e1"
    expression  = local.alarm_details["Expression"]
    label       = local.alarm_details["Label"]
    return_data = "true"
  }
  dynamic "metric_query" {
    for metric in each.value["Metrics"]{
      id = metric.key 

      metric_name = metric.value
      period      = local.alarm_details["Period"]
      stat        = local.alarm_details["Statistic"]
      namespace   = local.full_namespace
      unit        = "Count"
    }
    }
}

这是我收到的错误消息:

{
  "locals": {
      "Name": {
        "Name": "metric_math",
        "Metrics": {
          "m1": "Sucess",
          "m2": "Failure"
        },
        "Expression": "100*(m2/(m1+m2))",
        "Threshold" : 1,
        "Period": 25,
        "Priority": "critical",
        "Statistic": "Sum",
        "Label": "label",
        "Comparison_Operator": "GreaterThanOrEqualToThreshold"
        }  
    }
  }

任何帮助将不胜感激。

0 个答案:

没有答案