Silvia Rotari
Silvia Rotari

Reputation: 11

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

Upvotes: 1

Views: 822

Answers (1)

Mahesh
Mahesh

Reputation: 269

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

Upvotes: 2

Related Questions