Skip to content

Commit

Permalink
Merge pull request #46 from gcmalloc/master
Browse files Browse the repository at this point in the history
Adding a forward option for a zone.
  • Loading branch information
solarkennedy committed Apr 14, 2014
2 parents 1db29b4 + b2ca148 commit 09176e3
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 2 deletions.
1 change: 1 addition & 0 deletions Modulefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ author 'Adam Jahn'
project_page 'https://github.com/ajjahn/puppet-dns'
source 'https://github.com/ajjahn/puppet-dns'
dependency 'puppetlabs/concat', '>=1.0.0'
dependency 'puppetlabs/stdlib', '>= 2.4.0'
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ Tweak and add the following to your site manifest:
}
}

You can also declare forwarders for a specific zone, if you don't have one in the dns::option.

dns::zone { 'example.com':
soa => "ns1.example.com",
soa_email => 'admin.example.com',
allow_forwarder => ['8.8.8.8'],
forward_policy => 'first'
nameservers => ["ns1"]
}

### Exported resource patterns
node default {
# Other nodes export an A record for thier hostname
Expand Down
10 changes: 10 additions & 0 deletions manifests/zone.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,22 @@
$reverse = false,
$zone_type = 'master',
$allow_transfer = [],
$allow_forwarder = [],
$forward_policy = 'first',
$slave_masters = undef,
$zone_notify = false,
$ensure = present
) {

validate_array($allow_transfer)
validate_array($allow_forwarder)
if $dns::options::forwarder and $allow_forwarder {
fatal("You cannot specify a global forwarder and \
a zone forwarder for zone ${soa}")
}
if !member(['first', 'only'], $forward_policy) {
error('The forward policy can only be set to either first or only')
}

$zone_serial = $serial ? {
false => inline_template('<%= Time.now.to_i %>'),
Expand Down
45 changes: 44 additions & 1 deletion spec/defines/dns_zone_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
context 'passing an array to data' do
let :facts do { :concat_basedir => '/dne', } end
let :params do
{ :allow_transfer => [ '192.0.2.0', '2001:db8::/32' ] }
{ :allow_transfer => [ '192.0.2.0', '2001:db8::/32' ],
:allow_forwarder => ['8.8.8.8', '208.67.222.222']
}
end

it 'should pass input validation' do
Expand All @@ -31,12 +33,53 @@
should contain_concat__fragment('named.conf.local.test.com.include').
with_content(/192\.0\.2\.0/)
}

it {
should contain_concat__fragment('named.conf.local.test.com.include').
with_content(/forwarders/)
}

it {
should contain_concat__fragment('named.conf.local.test.com.include').
with_content(/forward first;/)
}

it {
should contain_concat__fragment('named.conf.local.test.com.include').
with_content(/8.8.8.8/)
}

it {
should contain_concat__fragment('named.conf.local.test.com.include').
with_content(/2001:db8::\/32/)
}
end

context 'when ask to have a only forward policy' do
let :facts do { :concat_basedir => '/dne', } end
let :params do
{ :allow_transfer => [],
:allow_forwarder => ['8.8.8.8', '208.67.222.222'],
:forward_policy => 'only'
}
end
it 'should have a forward only policy' do
should contain_concat__fragment('named.conf.local.test.com.include').
with_content(/forward only;/)
end
end

context 'In the default case with no explicit forward policy or forwarder' do
let :facts do { :concat_basedir => '/dne', } end
let :params do
{ :allow_transfer => [ '192.0.2.0', '2001:db8::/32' ],
}
end

it 'should not have any forwarder configuration' do
should_not contain_concat__fragment('named.conf.local.test.com.include').
with_content(/forward/)
end
end
end

10 changes: 9 additions & 1 deletion templates/zone.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ zone "<%= @zone %>" {
<%= ip %>;
<% end -%>
};
<% end -%>
<% end -%>
<% if !@allow_forwarder.empty? -%>
forward <%= @forward_policy %>;
forwarders {
<% @allow_forwarder.each do |ip| -%>
<%= ip %>;
<% end -%>
};
<% end -%>
<% end -%>
};

0 comments on commit 09176e3

Please sign in to comment.