Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Cloudwatch Alert Terraform

Im currently attempting to push out an AWS cloudwatch metric Alarm via Terraform but I'm encountering the following error.

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:

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?

like image 857
Marvin Avatar asked Dec 14 '25 04:12

Marvin


1 Answers

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. Because this was not configured i was receiving the exactly one error because metric queries by default are used for multiple queries.

like image 82
Marvin Avatar answered Dec 16 '25 02:12

Marvin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!