output "fargate_task_iam_role_arn" {
  description = "ARN of fargate task role"
  value       = aws_iam_role.fargate_task_role.arn
}

output "fargate_task_iam_role_name" {
  description = "Name of fargate task role"
  value       = aws_iam_role.fargate_task_role.name
}

output "fargate_task_iam_execution_role_arn" {
  description = "ARN of fargate task execution role"
  value       = aws_iam_role.fargate_task_execution_role.arn
}

output "fargate_task_iam_execution_role_name" {
  description = "Name of fargate task execution role"
  value       = aws_iam_role.fargate_task_execution_role.name
}

output "fargate_run_task_role_arn" {
  description = "ARN of fargate run task role"
  value = element(
    concat(aws_iam_role.fargate_run_task_role.*.arn, [""]),
    0,
  )
}

output "fargate_run_task_role_name" {
  description = "Name of fargate run task role"
  value = element(
    concat(aws_iam_role.fargate_run_task_role.*.name, [""]),
    0,
  )
}

output "fargate_security_group_id" {
  description = "ID of fargate task security group"
  value       = var.task_type != "external_worker" ? aws_security_group.task_security_group[0].id : null
}

output "fargate_security_group_arn" {
  description = "ARN of fargate task security group"
  value       = var.task_type != "external_worker" ? aws_security_group.task_security_group[0].arn : null
}

output "fargate_security_group_name" {
  description = "Name of fargate task security group"
  value       = var.task_type != "external_worker" ? aws_security_group.task_security_group[0].name : null
}

output "fargate_load_balancer_security_group_id" {
  description = "ID of load balancer security group"

  value = element(
    concat(aws_security_group.load_balancer_security_group.*.id, [""]),
    0,
  )
}

output "fargate_load_balancer_security_group_arn" {
  description = "ARN of load balancer security group"

  value = element(
    concat(aws_security_group.load_balancer_security_group.*.arn, [""]),
    0,
  )
}

output "fargate_load_balancer_security_group_name" {
  description = "Name of load balancer security group"

  value = element(
    concat(aws_security_group.load_balancer_security_group.*.name, [""]),
    0,
  )
}

output "fargate_task_definition_arn" {
  description = "ARN of fargate task definition"
  value       = aws_ecs_task_definition.fargate_task.arn
}

output "fargate_task_definition_arn_without_revision" {
  description = "ARN of fargate task definition without revision"
  value       = aws_ecs_task_definition.fargate_task.arn_without_revision
}

output "fargate_task_definition_container_definitions" {
  description = "Container definitions JSON content of fargate task definition"
  value       = local.container_definition_file
}

output "fargate_target_group_arn" {
  description = "ARN of fargate target group"
  value = element(
    concat(aws_lb_target_group.fargate_target_group.*.arn, [""]),
    0,
  )
}

output "fargate_load_balancer_arn" {
  description = "ARN of fargate load balancer"
  value       = element(concat(aws_lb.application_load_balancer.*.arn, [""]), 0)
}

output "fargate_load_balancer_id" {
  description = "ID of fargate load balancer"
  value       = element(concat(aws_lb.application_load_balancer.*.id, [""]), 0)
}

output "fargate_load_balancer_dns_name" {
  description = "DNS name(s) for load balancer"
  value       = element(concat(aws_lb.application_load_balancer.*.dns_name, [""]), 0)
}

output "fargate_load_balancer_dns_zone_id" {
  description = "DNS done id for load balancer"
  value       = element(concat(aws_lb.application_load_balancer.*.zone_id, [""]), 0)
}

output "fargate_load_balancer_arn_suffix" {
  description = "ARN suffix of load balancer, for use with CloudWatch Metrics"
  value       = element(concat(aws_lb.application_load_balancer.*.arn_suffix, [""]), 0)
}

output "fargate_load_balancer_http_listener_arn" {
  description = "ARN of fargate load balancer HTTP listener"
  value       = element(concat(aws_lb_listener.load_balancer_http_listener.*.arn, [""]), 0)
}

output "fargate_load_balancer_https_listener_arn" {
  description = "ARN of fargate load balancer HTTPS listener"
  value       = element(concat(aws_lb_listener.load_balancer_https_listener.*.arn, [""]), 0)
}

output "fargate_cluster_name" {
  description = "Name of fargate cluster"
  value       = var.task_type != "external_worker" && var.ecs_cluster_name == "" ? aws_ecs_cluster.fargate_ecs_cluster[0].name : null
}

output "fargate_web_service_id" {
  description = "ID of fargate service (web_service type)"
  value = element(
    concat(
      aws_ecs_service.fargate_service_with_load_balancer.*.id,
      [""],
    ),
    0,
  )
}

output "fargate_web_service_name" {
  description = "Name of fargate service (web_service type)"
  value = element(
    concat(
      aws_ecs_service.fargate_service_with_load_balancer.*.name,
      [""],
    ),
    0,
  )
}

output "fargate_worker_service_id" {
  description = "ID of fargate service (worker type)"
  value = element(
    concat(
      aws_ecs_service.fargate_service_without_load_balancer.*.id,
      [""],
    ),
    0,
  )
}

output "fargate_worker_service_name" {
  description = "Name of fargate service (worker type)"
  value = element(
    concat(
      aws_ecs_service.fargate_service_without_load_balancer.*.name,
      [""],
    ),
    0,
  )
}

output "fargate_secrets_manager_policy_arn_output" {
  value = aws_iam_policy.fargate_secrets_manager_policy.arn
}

output "non_prod_fargate_service_route53_record_fqdn_output" {
  description = "qa or dev fargate service route53 fqdn record"
  value = element(
    concat(
      aws_route53_record.service_route53_record.*.fqdn,
      [""]
  ), 0)
}

output "fargate_service_route53_record_fqdn_output" {
  description = "Fargate service route53 fqdn record"
  value = element(
    concat(
      aws_route53_record.prod_service_route53_record.*.fqdn,
      [""]
  ), 0)
}

output "prod_fargate_service_route53_record_fqdn_output" {
  description = "Prod service fargate service route53 fqdn record"
  value = element(
    concat(
      aws_route53_record.prod_cname_service_route53_record.*.fqdn,
      [""]
  ), 0)
}

output "fargate_cluster_arn" {
  description = "ARN of fargate cluster"
  value       = var.task_type != "external_worker" && var.ecs_cluster_name == "" ? aws_ecs_cluster.fargate_ecs_cluster[0].arn : null
}
