From d7ed6e1daef7323022dc4edcb2fb0b27e9875102 Mon Sep 17 00:00:00 2001 From: Nabil Houidi <35373676+NabilHouidi@users.noreply.github.com> Date: Sun, 30 Oct 2022 22:50:00 +0100 Subject: [PATCH] feat: add alar to shutdown idle instances --- alarms.tf | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 alarms.tf diff --git a/alarms.tf b/alarms.tf new file mode 100644 index 0000000..b123205 --- /dev/null +++ b/alarms.tf @@ -0,0 +1,15 @@ +resource "aws_cloudwatch_metric_alarm" "shutdown_idle" { + alarm_name = "shutdown idle ec2 : ${var.minikube_instance_name}" + comparison_operator = "LessThanThreshold" + evaluation_periods = "2" + metric_name = "CPUUtilization" + namespace = "AWS/EC2" + period = "3600" # 1 hour + statistic = "Average" + threshold = "10" + alarm_description = "This metric monitors ec2 cpu utilization" + alarm_actions = ["arn:aws:automate:${var.region}:ec2:stop"] + dimensions = { + InstanceId = "${aws_instance.minikube_instance.id}" + } +}