Terraform AWS metric filter and alarm

Viewed 762

Terraform script creates an aws_cloudwatch_log_metric_filter and aws_cloudwatch_metric_alarm. However in the AWS console the aws metric filter does not have an alarm associated with it yet the alarm exists in AWS console. Is there any missing steps to assign the alarm the the cloudwatcch metric? AWS console images attached.

resource "aws_cloudwatch_log_metric_filter" "titleregsubmit-metric-filter" {
  name           = "duplicate-titlregsubmit-filter-metric-${var.environment}"
  pattern        = "Submit transaction exists for VIN"
  log_group_name = var.loggroupname

  metric_transformation {
    name      = "duplicate-titlregsubmit-metric-${var.environment}"
    namespace = "MN DMV Errors 2"
    value     = "1"
  }
}
```
```
#cloud watch metric alarm
resource "aws_cloudwatch_metric_alarm" "duplicate-titleregsubmit-alarm" {
  alarm_name          = "mn-duplicate-titleregsubmit-${var.environment}"
  metric_name         = "duplicate-titlregsubmit-filter-metric-${var.environment}"
  threshold           = "0"
  statistic           = "Sum"
  comparison_operator = "GreaterThanThreshold"
  datapoints_to_alarm = "1"
  evaluation_periods  = "1"
  period              = "300"
  namespace           = "MN DMV Errors 2"
  alarm_actions       = [aws_sns_topic.nomads-alerts-sns.arn]
}
```

[![alarm][1]][1]

[![metric filter with no alarm][2]][2]

  [1]: https://i.stack.imgur.com/u6mDH.jpg
  [2]: https://i.stack.imgur.com/xH3Z8.jpg
0 Answers
Related