Amazon web services AWS Cloudwatch警报地形

Amazon web services AWS Cloudwatch警报地形,amazon-web-services,terraform,amazon-cloudwatch,Amazon Web Services,Terraform,Amazon Cloudwatch,我目前正试图通过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: Exact

我目前正试图通过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."
以下是地形代码:

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"
          }
      }
    }
}

你知道为什么会这样吗?

原来是我的配置。按照metric_query嵌套块的编写方式,您需要定义希望作为报警返回的metric query。由于未配置此项,我收到了一个错误,因为默认情况下,度量查询用于多个查询。

看起来您的度量查询返回了多个度量。使用度量查询块时,您还需要定义将哪个查询设置为报警,它不能采用列表。如果将我的评论标记为对那些不知道该做什么的人有用,我将不胜感激。您需要在一个
度量查询
块中添加
return\u data=true