简体   繁体   中英

It is possible to create multiple conditions for the same CloudWatch alarm for AutoScaling group with Terraform?

This is my resource and I need it to follow 2 conditions:

ASG min size > threshold

ASG min size < threshold


resource "aws_cloudwatch_metric_alarm" "GroupMinSize" {
  count               = 1
  alarm_name          = "Autoscaling_Group_Min_Size"
  comparison_operator = "GreaterThanThreshold"
  evaluation_periods  = "2"
  metric_name         = "GroupMinSize"
  namespace           = "AWS/AutoScaling"
  statistic           = "Minimum"
  period              = "120"
  threshold           = 1

  dimensions = {
    AutoScalingGroupName = aws_autoscaling_group.asg[count.index].name
  }

  alarm_description = "The minimum size of the Auto Scaling group"
}

According to AWS cloudformation documentation, comparison_operator is a string, therefore you cannot have multiple conditions. If cloudformation cannot do it, Terraform cannot do it either.

ComparisonOperator
The arithmetic operation to use when comparing the specified statistic and threshold. The specified statistic value is used as the first operand.

You can specify the following values: GreaterThanThreshold, GreaterThanOrEqualToThreshold, LessThanThreshold, or LessThanOrEqualToThreshold.

Required: Yes

Type: String

Allowed values: GreaterThanOrEqualToThreshold | GreaterThanThreshold | GreaterThanUpperThreshold | LessThanLowerOrGreaterThanUpperThreshold | LessThanLowerThreshold | LessThanOrEqualToThreshold | LessThanThreshold

However, you can combine multiple alarms to make a composite.

Cloudformation-documentation Terraform-documentation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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