我正在尝试在 aws 中为 UnHealthyHostCountmetric 的 NLB 创建 cloudwatch 警报
我将 NLB 定义为:
variable "lb" {
type = list
default = [
"net/lb01/bb087",
"net/lb01/bb088"
]
}
我将目标群体定义为:
variable "lb_tg" {
type = list
default = [
"targetgroup/newtargetlkinjk/3dac",
"targetgroup/newtargetlkinjk/3d0d"
]
}
然后我在它们上使用数据源:
data "aws_lb_target_group" "my_lb_target_group" {
for_each = toset(var.lb_tg)
tags = {
name = each.key
}
}
data "aws_lb" "my_lbs" {
for_each = toset(var.lb)
tags = {
name = each.key
}
}
然后我试图在警报中使用两者
resource "aws_cloudwatch_metric_alarm" "nlb-target-unhealthy-warning" {
for_each = data.aws_lb_target_group.my_lb_target_group
alarm_name = "nlb-target-unhealthy-warning-for-${each.key}"
comparison_operator = "GreaterThanThreshold"
evaluation_periods = "3"
metric_name = "UnHealthyHostCount"
namespace = "AWS/NetworkELB"
dimensions = {
TargetGroup = each.key
LoadBalancer = ???
}
period = "60"
statistic = "Average"
threshold = "0"
alarm_description = "This warning metric monitors unhealthy hosts behind the NLB for ${each.key}"
actions_enabled = true
alarm_actions = [data.aws_sns_topic.my_sns.arn]
insufficient_data_actions = []
treat_missing_data = "notBreaching"
}
由于警报已经在使用 for_each = data.aws_lb_target_group.my_lb_target_group ,我如何同时提供 data.aws_lb.my_lbs 中的值,这是dimentions-LoadBalancer所需要的