data external alb-targetgroups { program = ["bash", "../../modules/ManagementGovernance/Monitoring.ALB/list-alb-targetgroups.sh"] query = { lb = var.load-balancer } } resource aws_cloudwatch_metric_alarm alb-HealthyHostCount { for_each = toset(split(" ", data.external.alb-targetgroups.result.result)) alarm_name = "ALBTG:HealthyHostCount:${split("/", each.value)[1]}/${split("/", each.value)[2]}" comparison_operator = "LessThanThreshold" evaluation_periods = "1" metric_name = "HealthyHostCount" period = "300" statistic = "Minimum" threshold = var.threshold-HealthHostCountMin alarm_description = "ALBTG:HealthyHostCount" namespace = "AWS/ApplicationELB" insufficient_data_actions = [] actions_enabled = "true" alarm_actions = [var.alarm-actions-emergency] ok_actions = [var.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]}" } tags = var.default-tags lifecycle { ignore_changes = [tags] } }