initial commit
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
# Monitoring module
|
||||
This module deploys the default cloudwatch metric monitoring
|
||||
|
||||
## Notes
|
||||
Terraform lifecycle ignores tags to speed up terraform subsequent update. Cloudwatch alarm tags cannot be read on aws console anyway.
|
||||
|
||||
## Example
|
||||
```terraform
|
||||
module "asg" {
|
||||
source = "../../modules/util/resource-list"
|
||||
resource-type = "asg"
|
||||
}
|
||||
|
||||
module "asg-monitoring" {
|
||||
cw-alarm-prefix = local.cw-alarm-prefix
|
||||
for_each = module.asg.result-set
|
||||
source = "../../modules/ManagementGovernance/Monitoring.ASG"
|
||||
default-tags = local.default-tags
|
||||
asg-name = each.value
|
||||
threshold-CPUUtilization = 90
|
||||
actions-enabled = var.actions-enabled
|
||||
sns-targets = var.sns-targets
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,41 @@
|
||||
data "aws_autoscaling_group" "asg" {
|
||||
name = var.asg-name
|
||||
}
|
||||
|
||||
resource "aws_cloudwatch_metric_alarm" "asg-CPUUtilization" {
|
||||
alarm_name = "${var.settings.CPUUtilization.ecccode}-ASG_${var.asg-name}-CPUUtilization"
|
||||
comparison_operator = var.settings.CPUUtilization.comparison_operator
|
||||
evaluation_periods = var.settings.CPUUtilization.evaluation_periods
|
||||
metric_name = "CPUUtilization"
|
||||
period = var.settings.CPUUtilization.period
|
||||
statistic = var.settings.CPUUtilization.statistic
|
||||
threshold = var.settings.CPUUtilization.threshold
|
||||
alarm_description = "ASG:CPUUtilization"
|
||||
namespace = "AWS/EC2"
|
||||
insufficient_data_actions = []
|
||||
actions_enabled = var.actions-enabled
|
||||
alarm_actions = [var.settings.CPUUtilization.action]
|
||||
ok_actions = [var.settings.CPUUtilization.action]
|
||||
dimensions = {
|
||||
AutoScalingGroupName =var.asg-name
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_cloudwatch_metric_alarm" "asg-GroupInServiceCapacity" {
|
||||
alarm_name = "${var.settings.GroupInServiceCapacity.ecccode}-ASG_${var.asg-name}-GroupInServiceCapacity"
|
||||
comparison_operator = "LessThanThreshold"
|
||||
evaluation_periods = var.settings.GroupInServiceCapacity.evaluation_periods
|
||||
metric_name = "GroupInServiceCapacity"
|
||||
period = var.settings.GroupInServiceCapacity.period
|
||||
statistic = "Minimum"
|
||||
threshold = data.aws_autoscaling_group.asg.min_size
|
||||
alarm_description = "ASG:GroupInServiceCapacity"
|
||||
namespace = "AWS/AutoScaling"
|
||||
insufficient_data_actions = []
|
||||
actions_enabled = var.actions-enabled
|
||||
alarm_actions = [var.settings.GroupInServiceCapacity.action]
|
||||
ok_actions = [var.settings.GroupInServiceCapacity.action]
|
||||
dimensions = {
|
||||
AutoScalingGroupName = var.asg-name
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
terraform {
|
||||
required_version = "~> 1.3.0"
|
||||
required_providers {
|
||||
aws = {
|
||||
source = "hashicorp/aws"
|
||||
version = ">= 4.36.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
variable cw-alarm-prefix {}
|
||||
variable actions-enabled {}
|
||||
variable asg-name {}
|
||||
variable settings {}
|
||||
variable ecccode {}
|
||||
Reference in New Issue
Block a user