2022-10-25 19:51:04 +08:00
|
|
|
/*
|
|
|
|
data "external" "nlb-targetgroups" {
|
|
|
|
program = ["bash", "${path.module}/list-nlb-targetgroups.sh"]
|
2022-10-25 14:21:37 +08:00
|
|
|
query = {
|
2022-10-25 19:51:04 +08:00
|
|
|
parameter = var.load-balancer
|
2022-10-25 14:21:37 +08:00
|
|
|
}
|
|
|
|
}
|
2022-10-25 19:51:04 +08:00
|
|
|
*/
|
2023-05-23 13:10:16 +08:00
|
|
|
locals {
|
|
|
|
nlb-name = "net/${split("/", var.load-balancer)[2]}/${split("/", var.load-balancer)[3]}"
|
|
|
|
}
|
2022-10-25 14:21:37 +08:00
|
|
|
|
2023-05-23 13:10:16 +08:00
|
|
|
resource "aws_cloudwatch_metric_alarm" "nlb-TCP_Target_Reset_Count" {
|
|
|
|
alarm_name = "${var.settings.TCP_Target_Reset_Count.ecccode}-NLB_${local.nlb-name}-TCP_Target_Reset_Count"
|
|
|
|
comparison_operator = var.settings.TCP_Target_Reset_Count.comparison_operator
|
|
|
|
evaluation_periods = var.settings.TCP_Target_Reset_Count.evaluation_periods
|
|
|
|
metric_name = "TCP_Target_Reset_Count"
|
|
|
|
period = var.settings.TCP_Target_Reset_Count.period
|
|
|
|
statistic = var.settings.TCP_Target_Reset_Count.statistic
|
|
|
|
threshold = var.settings.TCP_Target_Reset_Count.threshold
|
|
|
|
alarm_description = "NLB:TCP_Target_Reset_Count"
|
|
|
|
namespace = "AWS/NetworkELB"
|
|
|
|
insufficient_data_actions = []
|
|
|
|
actions_enabled = var.actions-enabled
|
|
|
|
alarm_actions = [var.settings.TCP_Target_Reset_Count.action]
|
|
|
|
ok_actions = [var.settings.TCP_Target_Reset_Count.action]
|
|
|
|
dimensions = {
|
|
|
|
LoadBalancer = local.nlb-name
|
|
|
|
}
|
|
|
|
tags = var.default-tags
|
|
|
|
}
|
2022-10-25 19:51:04 +08:00
|
|
|
|
2023-05-23 13:10:16 +08:00
|
|
|
/*
|
2022-10-25 19:51:04 +08:00
|
|
|
module "nlb-targetgroups" {
|
|
|
|
source = "../../util/resource-list"
|
|
|
|
resource-type = "nlb-targetgroups"
|
|
|
|
query-input = var.load-balancer
|
2023-05-23 13:10:16 +08:00
|
|
|
asrolearn = var.asrolearn
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
// causes Rate exceeded error, maybe because of adaptive AWS_RETRY_MODE?
|
|
|
|
|
|
|
|
module "nlb_tgs" {
|
|
|
|
assume_role_arn = var.asrolearn
|
|
|
|
role_session_name = "terraform-resource-list"
|
|
|
|
source = "../../util/terraform-aws-cli"
|
|
|
|
aws_cli_commands = ["elbv2", "describe-target-groups", "--load-balancer-arn", var.load-balancer]
|
|
|
|
aws_cli_query = "TargetGroups[*].TargetGroupArn"
|
2022-10-25 19:51:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_cloudwatch_metric_alarm" "nlb-HealthyHostCount" {
|
2023-05-23 13:10:16 +08:00
|
|
|
# for_each = module.nlb-targetgroups.result-set
|
|
|
|
for_each = toset(flatten(module.nlb_tgs.result))
|
|
|
|
alarm_name = "${var.settings.HealthHostCountMin.ecccode}-NLBTG_${split(":", each.value)[5]}-HealthyHostCount"
|
2023-01-05 23:35:31 +08:00
|
|
|
comparison_operator = var.settings.HealthHostCountMin.comparison_operator
|
|
|
|
evaluation_periods = var.settings.HealthHostCountMin.evaluation_periods
|
2022-10-25 19:51:04 +08:00
|
|
|
metric_name = "HealthyHostCount"
|
2023-01-05 23:35:31 +08:00
|
|
|
period = var.settings.HealthHostCountMin.period
|
|
|
|
statistic = var.settings.HealthHostCountMin.statistic
|
|
|
|
threshold = var.settings.HealthHostCountMin.threshold
|
2022-10-25 19:51:04 +08:00
|
|
|
alarm_description = "NLBTG:HealthyHostCount"
|
|
|
|
namespace = "AWS/NetworkELB"
|
2022-10-25 14:21:37 +08:00
|
|
|
insufficient_data_actions = []
|
2022-10-26 11:13:56 +08:00
|
|
|
actions_enabled = var.actions-enabled
|
2023-01-05 23:35:31 +08:00
|
|
|
alarm_actions = [var.settings.HealthHostCountMin.action]
|
|
|
|
ok_actions = [var.settings.HealthHostCountMin.action]
|
2022-10-25 14:21:37 +08:00
|
|
|
dimensions = {
|
2022-10-25 19:51:04 +08:00
|
|
|
TargetGroup = split(":", each.value)[5]
|
|
|
|
LoadBalancer = "net/${split("/", var.load-balancer)[2]}/${split("/", var.load-balancer)[3]}"
|
2022-10-25 14:21:37 +08:00
|
|
|
}
|
|
|
|
tags = var.default-tags
|
|
|
|
}
|