Skip to content

Commit

Permalink
upload cloudwatch sns module
Browse files Browse the repository at this point in the history
Cloudwatch and SNS will be used to set a monitoring and notification system in place for idle resources
  • Loading branch information
gmaentz committed Sep 28, 2018
1 parent c894357 commit 70373f9
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions modules/services/cloud-watch/main.tf
@@ -0,0 +1,51 @@
variable "sms_number" {
description = "The SMS number to send CloudWatch Notifications To"
}
variable "autoscaling_group" {
description = "The autoscaling group to monitor"
}

resource "aws_sns_topic" "send_text" {
name = "sendText"
}

resource "aws_sns_topic_subscription" "text_send_text_target" {
topic_arn = "${aws_sns_topic.send_text.arn}"
protocol = "sms"
endpoint = "${var.sms_number}"
}

resource "aws_cloudwatch_metric_alarm" "alarm_minutes" {
alarm_name = "terraform-idle_cpu_5_mins"
comparison_operator = "LessThanOrEqualToThreshold"
evaluation_periods = "5"
metric_name = "CPUUtilization"
namespace = "AWS/EC2"
period = "60"
statistic = "Average"
threshold = "2"

dimensions {
AutoScalingGroupName = "${var.autoscaling_group}"
}

alarm_description = "This metric monitors ec2 cpu utilization every minute for 5 minutes"
alarm_actions = ["${aws_sns_topic.send_text.arn}"]
}
resource "aws_cloudwatch_metric_alarm" "alarm_hours" {
alarm_name = "terraform-idle_cpu_5_hours"
comparison_operator = "LessThanOrEqualToThreshold"
evaluation_periods = "5"
metric_name = "CPUUtilization"
namespace = "AWS/EC2"
period = "3600"
statistic = "Average"
threshold = "2"

dimensions {
AutoScalingGroupName = "${var.autoscaling_group}"
}

alarm_description = "This metric monitors ec2 cpu utilization every hour for 5 hours"
alarm_actions = ["${aws_sns_topic.send_text.arn}"]
}

0 comments on commit 70373f9

Please sign in to comment.