# Cloudflare DNS for API subdomain
data "cloudflare_zone" "domain" {
  count = var.domain_name != "" && var.cloudflare_api_token != "" ? 1 : 0
  name  = var.domain_name
}

# CNAME record for api.filamenteka.rs pointing to ALB
resource "cloudflare_record" "api" {
  count   = var.domain_name != "" && var.cloudflare_api_token != "" ? 1 : 0
  zone_id = data.cloudflare_zone.domain[0].id
  name    = "api"
  type    = "CNAME"
  value   = aws_lb.api.dns_name
  ttl     = 1
  proxied = false
  comment = "ALB API endpoint with HTTPS"
}

