Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cloudwatch and SNS will be used to set a monitoring and notification system in place for idle resources
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}"] | ||
} |