output "memcached_cluster_address" {
  value = element(
    concat(aws_elasticache_cluster.memcached[*].cluster_address, [""]),
    0,
  )
}

output "redis_cluster_group_id" {
  value = element(
    concat(aws_elasticache_replication_group.redis[*].id, [""]),
    0,
  )
}

output "redis_primary_endpoint_address" {
  value = element(
    concat(
      aws_elasticache_replication_group.redis[*].primary_endpoint_address,
      [""],
    ),
    0,
  )
}

output "cache_notification_sns_topic" {
  value = module.cache_sns_topic.topic_arn
}

output "memcached_cluster_cname_output" {
  description = "The FQDN of the memcached cluster CNAME record"
  value       = var.route53_record_creation_enabled && var.cache_engine == "memcached" ? aws_route53_record.networking_memcached_cluster_cname[*].fqdn : []
}

output "redis_cluster_cname_output" {
  description = "The FQDN of the redis cluster CNAME record"
  value       = var.route53_record_creation_enabled && var.cache_engine == "redis" ? aws_route53_record.networking_redis_cluster_cname[*].fqdn : []
}

output "cache_security_group_id" {
  value = one(coalescelist(
    aws_security_group.elasticache_redis_group[*].id,
    aws_security_group.elasticache_memcached_group[*].id
  ))
}
