简体   繁体   English

AWS Cloudwatch Alert Terraform

[英]AWS Cloudwatch Alert Terraform

Im currently attempting to push out an AWS cloudwatch metric Alarm via Terraform but I'm encountering the following error. 我目前正在尝试通过Terraform推出AWS cloudwatch指标警报,但遇到以下错误。

Error applying plan:

1 error(s) occurred:

* aws_cloudwatch_metric_alarm.alarm_name: 1 error(s) occurred:

* aws_cloudwatch_metric_alarm.alarm_name: Creating metric alarm failed: ValidationError: Exactly one element of the metrics list should return data.
    status code: 400, request id: xxxxxxxx-xxxxxxx-xxxxxx\n\nTerraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure."

Here is the Terraform Code: 这是Terraform代码:

resource "aws_cloudwatch_metric_alarm" "elb_monitor" {
  alarm_name                = "openam-elb-monitor"
  comparison_operator       = "GreaterThanOrEqualToThreshold"
  evaluation_periods        = "2"
  threshold                 = "1"
  alarm_description         = "UnHealthyHostCount for openam elbs"
  insufficient_data_actions = []
  metric_query {
      id = "elb_unhealthy_host_count"
      metric {
          metric_name = "UnHealthyHostCount"
          namespace   = "AWS/ELB"
          period      = "120"
          stat        = "Maximum"
          unit        = "Count"
          dimensions  = {
              LoadBalancerName = "development_lb"
          }
      }
    }
}

Any ideas on why this is happening? 为什么会这样?

So it turns out it was my configuration. 原来是我的配置。 The way that the metric_query nested block is written, you need to define which metric query you would like to be returned as the alarm. 编写metric_query嵌套块的方式,您需要定义要作为警报返回的度量查询。 Because this was not configured i was receiving the exactly one error because metric queries by default are used for multiple queries. 因为未配置此选项,所以我收到的exactly one error因为默认情况下指标查询用于多个查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM