UPD: get sns targets from root module variable

This commit is contained in:
xpk 2022-11-10 11:16:24 +08:00
parent bc995f7ac8
commit a348848966
Signed by: xpk
GPG Key ID: CD4FF6793F09AB86
18 changed files with 65 additions and 199 deletions

View File

@ -18,8 +18,8 @@ resource "aws_cloudwatch_metric_alarm" "alb-HealthyHostCount" {
namespace = "AWS/ApplicationELB"
insufficient_data_actions = []
actions_enabled = var.actions-enabled
alarm_actions = [var.alarm-actions-emergency]
ok_actions = [var.alarm-actions-emergency]
alarm_actions = [var.sns-targets.alarm-actions-emergency]
ok_actions = [var.sns-targets.alarm-actions-emergency]
dimensions = {
TargetGroup = "targetgroup/${split("/", each.value)[1]}/${split("/", each.value)[2]}"
LoadBalancer = "app/${split("/", var.load-balancer)[2]}/${split("/", var.load-balancer)[3]}"

View File

@ -2,20 +2,5 @@ variable cw-alarm-prefix {}
variable actions-enabled {}
variable load-balancer {}
variable threshold-HealthHostCountMin {}
variable alarm-actions-urgent {
type = string
default = "arn:aws:sns:ap-east-1:843733946244:rackspace-support-urgent"
}
variable alarm-actions-emergency {
type = string
default = "arn:aws:sns:ap-east-1:843733946244:rackspace-support-emergency"
}
variable alarm-actions-standard {
type = string
default = "arn:aws:sns:ap-east-1:843733946244:rackspace-support-standard"
}
variable alarm-actions-general {
type = string
default = "arn:aws:sns:ap-east-1:843733946244:rackspace-support"
}
variable sns-targets {}
variable default-tags {}

View File

@ -10,8 +10,8 @@ resource "aws_cloudwatch_metric_alarm" "asg-CPUUtilization" {
namespace = "AWS/EC2"
insufficient_data_actions = []
actions_enabled = var.actions-enabled
alarm_actions = [var.alarm-actions-urgent]
ok_actions = [var.alarm-actions-urgent]
alarm_actions = [var.sns-targets.alarm-actions-urgent]
ok_actions = [var.sns-targets.alarm-actions-urgent]
dimensions = {
AutoScalingGroupName = var.asg-name
}

View File

@ -1,22 +1,7 @@
variable cw-alarm-prefix {}
variable actions-enabled {}
variable asg-name {}
variable alarm-actions-urgent {
type = string
default = "arn:aws:sns:ap-east-1:843733946244:rackspace-support-urgent"
}
variable alarm-actions-emergency {
type = string
default = "arn:aws:sns:ap-east-1:843733946244:rackspace-support-emergency"
}
variable alarm-actions-standard {
type = string
default = "arn:aws:sns:ap-east-1:843733946244:rackspace-support-standard"
}
variable alarm-actions-general {
type = string
default = "arn:aws:sns:ap-east-1:843733946244:rackspace-support"
}
variable sns-targets {}
variable default-tags {}
variable threshold-CPUUtilization {}

View File

@ -10,8 +10,8 @@ resource "aws_cloudwatch_metric_alarm" "ec2-StatusCheckFailed_System" {
namespace = "AWS/EC2"
insufficient_data_actions = []
actions_enabled = var.actions-enabled
alarm_actions = [var.alarm-actions-emergency]
ok_actions = [var.alarm-actions-emergency]
alarm_actions = [var.sns-targets.alarm-actions-emergency]
ok_actions = [var.sns-targets.alarm-actions-emergency]
dimensions = {
InstanceId = var.ec2-instance-id
}
@ -33,8 +33,8 @@ resource "aws_cloudwatch_metric_alarm" "ec2-StatusCheckFailed_Instance" {
namespace = "AWS/EC2"
insufficient_data_actions = []
actions_enabled = var.actions-enabled
alarm_actions = [var.alarm-actions-emergency]
ok_actions = [var.alarm-actions-emergency]
alarm_actions = [var.sns-targets.alarm-actions-emergency]
ok_actions = [var.sns-targets.alarm-actions-emergency]
dimensions = {
InstanceId = var.ec2-instance-id
}
@ -56,8 +56,8 @@ resource "aws_cloudwatch_metric_alarm" "ec2-CPUUtilization" {
namespace = "AWS/EC2"
insufficient_data_actions = []
actions_enabled = var.actions-enabled
alarm_actions = [var.alarm-actions-urgent]
ok_actions = [var.alarm-actions-urgent]
alarm_actions = [var.sns-targets.alarm-actions-urgent]
ok_actions = [var.sns-targets.alarm-actions-urgent]
treat_missing_data = "notBreaching"
dimensions = {
InstanceId = var.ec2-instance-id
@ -85,8 +85,8 @@ resource "aws_cloudwatch_metric_alarm" "ec2-mem_free" {
namespace = "CWAgent"
insufficient_data_actions = []
actions_enabled = var.actions-enabled
alarm_actions = [var.alarm-actions-standard]
ok_actions = [var.alarm-actions-standard]
alarm_actions = [var.sns-targets.alarm-actions-standard]
ok_actions = [var.sns-targets.alarm-actions-standard]
dimensions = {
InstanceId = var.ec2-instance-id
ImageId = data.aws_instance.ec2-instance.ami
@ -107,8 +107,8 @@ resource "aws_cloudwatch_metric_alarm" "ec2-swap_free" {
alarm_description = "EC2:swap_free"
insufficient_data_actions = []
actions_enabled = var.actions-enabled
alarm_actions = [var.alarm-actions-standard]
ok_actions = [var.alarm-actions-standard]
alarm_actions = [var.sns-targets.alarm-actions-standard]
ok_actions = [var.sns-targets.alarm-actions-standard]
metric_query {
id = "m1"
metric {
@ -157,8 +157,8 @@ resource "aws_cloudwatch_metric_alarm" "ec2-disk_free" {
namespace = "CWAgent"
insufficient_data_actions = []
actions_enabled = var.actions-enabled
alarm_actions = [var.alarm-actions-urgent]
ok_actions = [var.alarm-actions-urgent]
alarm_actions = [var.sns-targets.alarm-actions-urgent]
ok_actions = [var.sns-targets.alarm-actions-urgent]
dimensions = {
InstanceId = var.ec2-instance-id
ImageId = data.aws_instance.ec2-instance.ami
@ -186,8 +186,8 @@ resource "aws_cloudwatch_metric_alarm" "ec2-disk_inodes_free" {
namespace = "CWAgent"
insufficient_data_actions = []
actions_enabled = var.actions-enabled
alarm_actions = [var.alarm-actions-urgent]
ok_actions = [var.alarm-actions-urgent]
alarm_actions = [var.sns-targets.alarm-actions-urgent]
ok_actions = [var.sns-targets.alarm-actions-urgent]
dimensions = {
InstanceId = var.ec2-instance-id
ImageId = data.aws_instance.ec2-instance.ami
@ -214,8 +214,8 @@ resource "aws_cloudwatch_metric_alarm" "ec2-processes_total" {
namespace = "CWAgent"
insufficient_data_actions = []
actions_enabled = var.actions-enabled
alarm_actions = [var.alarm-actions-urgent]
ok_actions = [var.alarm-actions-urgent]
alarm_actions = [var.sns-targets.alarm-actions-urgent]
ok_actions = [var.sns-targets.alarm-actions-urgent]
dimensions = {
InstanceId = var.ec2-instance-id
ImageId = data.aws_instance.ec2-instance.ami

View File

@ -1,22 +1,8 @@
variable "cw-alarm-prefix" {}
variable "actions-enabled" {}
variable "ec2-instance-id" {}
variable "alarm-actions-urgent" {
type = string
default = "arn:aws:sns:ap-east-1:843733946244:rackspace-support-urgent"
}
variable "alarm-actions-emergency" {
type = string
default = "arn:aws:sns:ap-east-1:843733946244:rackspace-support-emergency"
}
variable "alarm-actions-standard" {
type = string
default = "arn:aws:sns:ap-east-1:843733946244:rackspace-support-standard"
}
variable "alarm-actions-general" {
type = string
default = "arn:aws:sns:ap-east-1:843733946244:rackspace-support"
}
variable sns-targets {}
variable "default-tags" {}
variable "threshold-CPUUtilization" {}

View File

@ -10,8 +10,8 @@ resource "aws_cloudwatch_metric_alarm" "emr-AppsPending" {
namespace = "AWS/ElasticMapReduce"
insufficient_data_actions = []
actions_enabled = var.actions-enabled
alarm_actions = [var.alarm-actions-standard]
ok_actions = [var.alarm-actions-standard]
alarm_actions = [var.sns-targets.alarm-actions-standard]
ok_actions = [var.sns-targets.alarm-actions-standard]
dimensions = {
JobFlowId = var.job-flow-id
}
@ -33,8 +33,8 @@ resource "aws_cloudwatch_metric_alarm" "emr-CapacityRemainingGB" {
namespace = "AWS/ElasticMapReduce"
insufficient_data_actions = []
actions_enabled = var.actions-enabled
alarm_actions = [var.alarm-actions-urgent]
ok_actions = [var.alarm-actions-urgent]
alarm_actions = [var.sns-targets.alarm-actions-urgent]
ok_actions = [var.sns-targets.alarm-actions-urgent]
dimensions = {
JobFlowId = var.job-flow-id
}

View File

@ -4,20 +4,5 @@ variable job-flow-id {}
variable threshold-AppsPending {}
variable threshold-CapacityRemainingGB {}
variable alarm-actions-urgent {
type = string
default = "arn:aws:sns:ap-east-1:843733946244:rackspace-support-urgent"
}
variable alarm-actions-emergency {
type = string
default = "arn:aws:sns:ap-east-1:843733946244:rackspace-support-emergency"
}
variable alarm-actions-standard {
type = string
default = "arn:aws:sns:ap-east-1:843733946244:rackspace-support-standard"
}
variable alarm-actions-general {
type = string
default = "arn:aws:sns:ap-east-1:843733946244:rackspace-support"
}
variable sns-targets {}
variable default-tags {}

View File

@ -10,8 +10,8 @@ resource "aws_cloudwatch_metric_alarm" "Kafka-ZooKeeperRequestLatencyMsMean" {
namespace = "AWS/Kafka"
insufficient_data_actions = []
actions_enabled = var.actions-enabled
alarm_actions = [var.alarm-actions-urgent]
ok_actions = [var.alarm-actions-urgent]
alarm_actions = [var.sns-targets.alarm-actions-urgent]
ok_actions = [var.sns-targets.alarm-actions-urgent]
dimensions = {
"Cluster Name" = var.cluster-name
}

View File

@ -1,22 +1,7 @@
variable cw-alarm-prefix {}
variable actions-enabled {}
variable cluster-name {}
variable alarm-actions-urgent {
type = string
default = "arn:aws:sns:ap-east-1:843733946244:rackspace-support-urgent"
}
variable alarm-actions-emergency {
type = string
default = "arn:aws:sns:ap-east-1:843733946244:rackspace-support-emergency"
}
variable alarm-actions-standard {
type = string
default = "arn:aws:sns:ap-east-1:843733946244:rackspace-support-standard"
}
variable alarm-actions-general {
type = string
default = "arn:aws:sns:ap-east-1:843733946244:rackspace-support"
}
variable sns-targets {}
variable default-tags {}
variable threshold-ZooKeeperRequestLatencyMsMean {}

View File

@ -17,7 +17,7 @@ module "nlb-targetgroups" {
resource "aws_cloudwatch_metric_alarm" "nlb-HealthyHostCount" {
for_each = module.nlb-targetgroups.result-set
alarm_name = "${var.cw-alarm-prefix}:NLBTG:HealthyHostCount:${split(":", each.value)[5]}"
comparison_operator = "LessThanOrEqualToThreshold"
comparison_operator = "LessThanThreshold"
evaluation_periods = "1"
metric_name = "HealthyHostCount"
period = "300"
@ -27,8 +27,8 @@ resource "aws_cloudwatch_metric_alarm" "nlb-HealthyHostCount" {
namespace = "AWS/NetworkELB"
insufficient_data_actions = []
actions_enabled = var.actions-enabled
alarm_actions = [var.alarm-actions-emergency]
ok_actions = [var.alarm-actions-emergency]
alarm_actions = [var.sns-targets.alarm-actions-emergency]
ok_actions = [var.sns-targets.alarm-actions-emergency]
dimensions = {
TargetGroup = split(":", each.value)[5]
LoadBalancer = "net/${split("/", var.load-balancer)[2]}/${split("/", var.load-balancer)[3]}"

View File

@ -2,20 +2,5 @@ variable cw-alarm-prefix {}
variable actions-enabled {}
variable load-balancer {}
variable threshold-HealthHostCountMin {}
variable alarm-actions-urgent {
type = string
default = "arn:aws:sns:ap-east-1:843733946244:rackspace-support-urgent"
}
variable alarm-actions-emergency {
type = string
default = "arn:aws:sns:ap-east-1:843733946244:rackspace-support-emergency"
}
variable alarm-actions-standard {
type = string
default = "arn:aws:sns:ap-east-1:843733946244:rackspace-support-standard"
}
variable alarm-actions-general {
type = string
default = "arn:aws:sns:ap-east-1:843733946244:rackspace-support"
}
variable sns-targets {}
variable default-tags {}

View File

@ -12,8 +12,8 @@ resource "aws_cloudwatch_metric_alarm" "ES-CPUUtilization" {
namespace = "AWS/ES"
insufficient_data_actions = []
actions_enabled = var.actions-enabled
alarm_actions = [var.alarm-actions-urgent]
ok_actions = [var.alarm-actions-urgent]
alarm_actions = [var.sns-targets.alarm-actions-urgent]
ok_actions = [var.sns-targets.alarm-actions-urgent]
dimensions = {
DomainName = var.domain-name
ClientId = data.aws_caller_identity.this.id
@ -36,8 +36,8 @@ resource "aws_cloudwatch_metric_alarm" "ES-SearchLatency" {
namespace = "AWS/ES"
insufficient_data_actions = []
actions_enabled = var.actions-enabled
alarm_actions = [var.alarm-actions-urgent]
ok_actions = [var.alarm-actions-urgent]
alarm_actions = [var.sns-targets.alarm-actions-urgent]
ok_actions = [var.sns-targets.alarm-actions-urgent]
dimensions = {
DomainName = var.domain-name
ClientId = data.aws_caller_identity.this.id
@ -60,8 +60,8 @@ resource "aws_cloudwatch_metric_alarm" "ES-IndexingLatency" {
namespace = "AWS/ES"
insufficient_data_actions = []
actions_enabled = var.actions-enabled
alarm_actions = [var.alarm-actions-urgent]
ok_actions = [var.alarm-actions-urgent]
alarm_actions = [var.sns-targets.alarm-actions-urgent]
ok_actions = [var.sns-targets.alarm-actions-urgent]
dimensions = {
DomainName = var.domain-name
ClientId = data.aws_caller_identity.this.id
@ -84,8 +84,8 @@ resource "aws_cloudwatch_metric_alarm" "ES-ClusterStatusRed" {
namespace = "AWS/ES"
insufficient_data_actions = []
actions_enabled = var.actions-enabled
alarm_actions = [var.alarm-actions-urgent]
ok_actions = [var.alarm-actions-urgent]
alarm_actions = [var.sns-targets.alarm-actions-urgent]
ok_actions = [var.sns-targets.alarm-actions-urgent]
dimensions = {
DomainName = var.domain-name
ClientId = data.aws_caller_identity.this.id

View File

@ -1,22 +1,7 @@
variable cw-alarm-prefix {}
variable actions-enabled {}
variable domain-name {}
variable alarm-actions-urgent {
type = string
default = "arn:aws:sns:ap-east-1:843733946244:rackspace-support-urgent"
}
variable alarm-actions-emergency {
type = string
default = "arn:aws:sns:ap-east-1:843733946244:rackspace-support-emergency"
}
variable alarm-actions-standard {
type = string
default = "arn:aws:sns:ap-east-1:843733946244:rackspace-support-standard"
}
variable alarm-actions-general {
type = string
default = "arn:aws:sns:ap-east-1:843733946244:rackspace-support"
}
variable sns-targets {}
variable default-tags {}
variable threshold-CPUUtilization {}

View File

@ -10,8 +10,8 @@ resource "aws_cloudwatch_metric_alarm" "rds-cpu" {
namespace = "AWS/RDS"
insufficient_data_actions = []
actions_enabled = var.actions-enabled
alarm_actions = [var.alarm-actions-urgent]
ok_actions = [var.alarm-actions-urgent]
alarm_actions = [var.sns-targets.alarm-actions-urgent]
ok_actions = [var.sns-targets.alarm-actions-urgent]
dimensions = {
DBInstanceIdentifier = var.rds-instance-name
}
@ -33,8 +33,8 @@ resource "aws_cloudwatch_metric_alarm" "rds-storage" {
namespace = "AWS/RDS"
insufficient_data_actions = []
actions_enabled = var.actions-enabled
alarm_actions = [var.alarm-actions-urgent]
ok_actions = [var.alarm-actions-urgent]
alarm_actions = [var.sns-targets.alarm-actions-urgent]
ok_actions = [var.sns-targets.alarm-actions-urgent]
dimensions = {
DBInstanceIdentifier = var.rds-instance-name
}
@ -56,8 +56,8 @@ resource "aws_cloudwatch_metric_alarm" "rds-memory" {
namespace = "AWS/RDS"
insufficient_data_actions = []
actions_enabled = var.actions-enabled
alarm_actions = [var.alarm-actions-urgent]
ok_actions = [var.alarm-actions-urgent]
alarm_actions = [var.sns-targets.alarm-actions-urgent]
ok_actions = [var.sns-targets.alarm-actions-urgent]
dimensions = {
DBInstanceIdentifier = var.rds-instance-name
}
@ -79,8 +79,8 @@ resource "aws_cloudwatch_metric_alarm" "rds-DiskQueueDepth" {
namespace = "AWS/RDS"
insufficient_data_actions = []
actions_enabled = var.actions-enabled
alarm_actions = [var.alarm-actions-urgent]
ok_actions = [var.alarm-actions-urgent]
alarm_actions = [var.sns-targets.alarm-actions-urgent]
ok_actions = [var.sns-targets.alarm-actions-urgent]
dimensions = {
DBInstanceIdentifier = var.rds-instance-name
}
@ -102,8 +102,8 @@ resource "aws_cloudwatch_metric_alarm" "rds-ReadLatency" {
namespace = "AWS/RDS"
insufficient_data_actions = []
actions_enabled = var.actions-enabled
alarm_actions = [var.alarm-actions-urgent]
ok_actions = [var.alarm-actions-urgent]
alarm_actions = [var.sns-targets.alarm-actions-urgent]
ok_actions = [var.sns-targets.alarm-actions-urgent]
dimensions = {
DBInstanceIdentifier = var.rds-instance-name
}
@ -125,8 +125,8 @@ resource "aws_cloudwatch_metric_alarm" "rds-WriteLatency" {
namespace = "AWS/RDS"
insufficient_data_actions = []
actions_enabled = var.actions-enabled
alarm_actions = [var.alarm-actions-urgent]
ok_actions = [var.alarm-actions-urgent]
alarm_actions = [var.sns-targets.alarm-actions-urgent]
ok_actions = [var.sns-targets.alarm-actions-urgent]
dimensions = {
DBInstanceIdentifier = var.rds-instance-name
}

View File

@ -1,22 +1,7 @@
variable cw-alarm-prefix {}
variable actions-enabled {}
variable rds-instance-name {}
variable alarm-actions-urgent {
type = string
default = "arn:aws:sns:ap-east-1:843733946244:rackspace-support-urgent"
}
variable alarm-actions-emergency {
type = string
default = "arn:aws:sns:ap-east-1:843733946244:rackspace-support-emergency"
}
variable alarm-actions-standard {
type = string
default = "arn:aws:sns:ap-east-1:843733946244:rackspace-support-standard"
}
variable alarm-actions-general {
type = string
default = "arn:aws:sns:ap-east-1:843733946244:rackspace-support"
}
variable sns-targets {}
variable default-tags {}
variable threshold-FreeableMemory {}

View File

@ -10,8 +10,8 @@ resource "aws_cloudwatch_metric_alarm" "redis-EngineCPUUtilization" {
namespace = "AWS/ElastiCache"
insufficient_data_actions = []
actions_enabled = var.actions-enabled
alarm_actions = [var.alarm-actions-urgent]
ok_actions = [var.alarm-actions-urgent]
alarm_actions = [var.sns-targets.alarm-actions-urgent]
ok_actions = [var.sns-targets.alarm-actions-urgent]
dimensions = {
CacheClusterId = var.redis-cluster-id
}
@ -33,8 +33,8 @@ resource "aws_cloudwatch_metric_alarm" "redis-DatabaseMemoryUsagePercentage" {
namespace = "AWS/ElastiCache"
insufficient_data_actions = []
actions_enabled = var.actions-enabled
alarm_actions = [var.alarm-actions-urgent]
ok_actions = [var.alarm-actions-urgent]
alarm_actions = [var.sns-targets.alarm-actions-urgent]
ok_actions = [var.sns-targets.alarm-actions-urgent]
dimensions = {
CacheClusterId = var.redis-cluster-id
}
@ -56,8 +56,8 @@ resource "aws_cloudwatch_metric_alarm" "redis-CacheHitRate" {
namespace = "AWS/ElastiCache"
insufficient_data_actions = []
actions_enabled = var.actions-enabled
alarm_actions = [var.alarm-actions-standard]
ok_actions = [var.alarm-actions-standard]
alarm_actions = [var.sns-targets.alarm-actions-standard]
ok_actions = [var.sns-targets.alarm-actions-standard]
dimensions = {
CacheClusterId = var.redis-cluster-id
# CacheNodeId = each.value

View File

@ -1,22 +1,7 @@
variable cw-alarm-prefix {}
variable "actions-enabled" {}
variable "redis-cluster-id" {}
variable "alarm-actions-urgent" {
type = string
default = "arn:aws:sns:ap-east-1:843733946244:rackspace-support-urgent"
}
variable "alarm-actions-emergency" {
type = string
default = "arn:aws:sns:ap-east-1:843733946244:rackspace-support-emergency"
}
variable "alarm-actions-standard" {
type = string
default = "arn:aws:sns:ap-east-1:843733946244:rackspace-support-standard"
}
variable "alarm-actions-general" {
type = string
default = "arn:aws:sns:ap-east-1:843733946244:rackspace-support"
}
variable sns-targets {}
variable "default-tags" {}
variable "threshold-EngineCPUUtilization" {}