data "cloudflare_zone" "orch_stream_cloudflare_zone" {
  name       = var.orch_stream_cloudflare_zone
  account_id = var.cloudflare_account_id
}

resource "cloudflare_record" "orch_stream_apex_record" {
  name    = "@"
  comment = "Apex record to use orch.stream as a custom hostname"
  proxied = false
  ttl     = 1
  type    = "A"
  value   = "104.18.100.36"
  zone_id = data.cloudflare_zone.orch_stream_cloudflare_zone.id
}

resource "cloudflare_record" "orch_stream_wildcard_cname" {
  name    = "*"
  comment = "CNAME record to point *.orch.stream to domains.songwhip.com"
  proxied = false
  ttl     = 1
  type    = "CNAME"
  value   = "domains.songwhip.com"
  zone_id = data.cloudflare_zone.orch_stream_cloudflare_zone.id
}

resource "cloudflare_record" "orch_stream_custom_hostname_ownership_txt" {
  name    = "_cf-custom-hostname.orch.stream"
  comment = "TXT record required to verify the ownership of the orch.stream domain"
  type    = "TXT"
  value   = "e52b9148-ad2b-4fd8-b106-7c6193f427f3"
  zone_id = data.cloudflare_zone.orch_stream_cloudflare_zone.id
}

resource "cloudflare_record" "staging_orch_stream_record" {
  name    = "staging"
  comment = "CNAME record to point staging.orch.stream to domains.songwhip.com"
  proxied = false
  ttl     = 1
  type    = "CNAME"
  value   = "domains.songwhip.com"
  zone_id = data.cloudflare_zone.orch_stream_cloudflare_zone.id
}

resource "cloudflare_record" "staging_orch_stream_wildcard_cname" {
  name    = "*.staging"
  comment = "CNAME record to point *.staging.orch.stream to domains.songwhip.com"
  proxied = false
  ttl     = 1
  type    = "CNAME"
  value   = "domains.songwhip.com"
  zone_id = data.cloudflare_zone.orch_stream_cloudflare_zone.id
}

resource "cloudflare_record" "staging_orch_stream_custom_hostname_ownership_txt" {
  name    = "_cf-custom-hostname.staging.orch.stream"
  comment = "TXT record required to verify the ownership of the staging.orch.stream domain"
  type    = "TXT"
  value   = cloudflare_custom_hostname.staging_orch_stream.ownership_verification.value
  zone_id = data.cloudflare_zone.orch_stream_cloudflare_zone.id
}
