
locals {
  configfile = templatefile("${path.module}/resources/Corefile.tpl", {
    zones               = var.zones
    override_hosts      = length(var.override_hosts) > 0
    hosts               = var.override_hosts
    forward_dns_servers = join(" ", var.forward_dns_servers)
  })
  configfile_checksum = md5(local.configfile)
  db_files = {
    for z in var.zones : z.fqdn => templatefile("${path.module}/resources/db.zone.tpl", {
      fqdn          = z.fqdn
      domain_master = z.domain_master
      timestamp     = formatdate("YYYYMMDD", timestamp())
      refresh_rate  = z.refresh_rate
      retry_rate    = z.retry_rate
      expire_time   = z.expire_time
      ttl           = z.ttl
      records       = z.records
    })
  }
  db_files_checksum = md5(jsonencode(local.db_files))
}
