resource "cloudns_dns_zone" "zones" {
  for_each = local.domains
  domain   = each.key
  type     = "master"
}

import {
  for_each = local.domains
  to       = cloudns_dns_zone.zones[each.key]
  id       = each.key
}

resource "cloudns_dns_record" "records" {
  for_each = {
    for i, record in local.records :
    i => record
  }
  name     = each.value.name
  zone     = each.value.zone
  type     = each.value.type
  value    = each.value.value
  priority = lookup(each.value, "priority", null)
  weight   = lookup(each.value, "weight", null)
  port     = lookup(each.value, "port", null)
  ttl      = lookup(each.value, "ttl", local.default_ttl)
}
