Terraform aws retrieve target group and associated load balancer arn suffix

66 views Asked by At

I'm trying to create a standaloone terraform CloudWatch module for various alarms, including one that measures unhealthyhostcount. Most of the alarms have one dimension, but, unfortunately, this one requires both the TargetGroup and the associated LoadBalancer, and I cannot devise a way of extracting this from the data sources. Has anyone managed to create a terraform CloudWatch alarm based on this metric?

The resource is very straightforward:

resource "aws_cloudwatch_metric_alarm" "target_group_unhealthy_hosts_alarms" 

  alarm_name          = "target-group-unhealthy-hosts-alarm"
  comparison_operator = "GreaterThanOrEqualToThreshold"
  evaluation_periods  = 5
  metric_name         = "UnHealthyHostCount"
  namespace           = "AWS/ApplicationELB"
  period              = 300
  statistic           = "Average"
  threshold           = 5
  actions_enabled     = true
  alarm_description   = "Alarm when there are at least five unhealthy hosts in the target group."
  dimensions = {
    LoadBalancer = var.loadbalaner
    TargetGroup  = var.targetgroup
  }
  alarm_actions = local.sns_topic_arn
}

0

There are 0 answers