package 'bind9'

execute "reload named" do
  command "rndc reconfig"
  action :nothing
end

template "/etc/bind/named.conf" do
  source "named.conf.erb"
  notifies :run, "execute[reload named]", :delayed
end

template "/etc/bind/named.conf.options" do
  source "named.conf.options.erb"
  notifies :run, "execute[reload named]", :delayed
end

service "bind9" do
  action [:enable, :start]
  supports status: true, start: true, stop: true, restart: true
end

node.bind.zones.each do |name, zone|
  execute "update #{name} zone" do
    command "rndc reload #{name}"
    action :nothing
  end

  template "/etc/bind/#{name}" do
    source "zone.erb"
    mode "0660"
    owner "root"
    owner "bind"
    notifies :run, "execute[update #{name} zone]"
    variables(zone: zone, zone_name: name, node: node)
  end
end

