# Outputs ======================================================================

output "id" {
  description = "Load balancer ID."
  value       = aws_lb.this.id
}

output "arn" {
  description = "Load balancer ARN."
  value       = aws_lb.this.arn
}

output "name" {
  description = "Generated load balancer name."
  value       = aws_lb.this.name
}

output "dns_name" {
  description = "DNS name of the load balancer."
  value       = aws_lb.this.dns_name
}

output "zone_id" {
  description = "Hosted zone ID of the load balancer (for Route53 alias records)."
  value       = aws_lb.this.zone_id
}

output "target_group_arns" {
  description = "Map of target group logical key to ARN."
  value       = { for k, v in aws_lb_target_group.this : k => v.arn }
}

output "target_group_names" {
  description = "Map of target group logical key to generated name."
  value       = local.target_group_names
}

output "listener_arns" {
  description = "Map of listener logical key to ARN."
  value       = { for k, v in aws_lb_listener.this : k => v.arn }
}

output "target_group_health_checks" {
  description = "Map of target group logical key to its resolved health check config, for troubleshooting unhealthy targets without opening the console."
  value = {
    for k, v in var.target_groups :
    k => v.health_check
  }
}

output "target_attachment_ids" {
  description = "Map of flattened attachment key (target_group_key-target_key) to the target_id that was attached."
  value       = { for k, v in aws_lb_target_group_attachment.this : k => v.target_id }
}
