You are always setting a count of 1 so you can instead just output the first element if it’s created:
output "backend_tg_arn" {
value = var.backend_tg_needed ? aws_lb_target_group.backend_tg[0].arn : null
}
CLICK HERE to find out more related problems solutions.