Skip to content

Commit 5144a5b

Browse files
committed
Allow adding roles, config entires and hba rules via hiera
1 parent 06cef86 commit 5144a5b

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

manifests/server.pp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@
5555
$manage_pg_ident_conf = $postgresql::params::manage_pg_ident_conf,
5656
$manage_recovery_conf = $postgresql::params::manage_recovery_conf,
5757
$module_workdir = $postgresql::params::module_workdir,
58+
59+
Hash[String, Hash] $roles = {},
60+
Hash[String, Any] $config_entries = {},
61+
Hash[String, Hash] $pg_hba_rules = {},
62+
5863
#Deprecated
5964
$version = undef,
6065
) inherits postgresql::params {
@@ -85,4 +90,22 @@
8590
-> Class['postgresql::server::config']
8691
-> Class['postgresql::server::service']
8792
-> Class['postgresql::server::passwd']
93+
94+
$roles.each |$rolename, $role| {
95+
postgresql::server::role { $rolename:
96+
* => $role,
97+
}
98+
}
99+
100+
$config_entries.each |$entry, $value| {
101+
postgresql::server::config_entry { $entry:
102+
value => $value,
103+
}
104+
}
105+
106+
$pg_hba_rules.each |$rule_name, $rule| {
107+
postgresql::server::pg_hba_rule { $rule_name:
108+
* => $rule,
109+
}
110+
}
88111
}

spec/unit/classes/server_spec.rb

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,58 @@ class { 'postgresql::globals':
165165
is_expected.to contain_class('postgresql::repo').with_version('99.5')
166166
end
167167
end
168+
169+
describe 'additional roles' do
170+
let(:params) do
171+
{
172+
:roles => {
173+
:username => { :createdb => true }
174+
}
175+
}
176+
end
177+
178+
it { is_expected.to compile.with_all_deps }
179+
it { is_expected.to contain_postgresql__server__role('username').with_createdb(true) }
180+
end
181+
182+
describe 'additional config_entries' do
183+
let(:params) do
184+
{
185+
:config_entries => {
186+
:fsync => 'off',
187+
:checkpoint_segments => '20'
188+
}
189+
}
190+
end
191+
192+
it { is_expected.to compile.with_all_deps }
193+
it { is_expected.to contain_postgresql__server__config_entry('fsync').with_value('off') }
194+
it { is_expected.to contain_postgresql__server__config_entry('checkpoint_segments').with_value('20') }
195+
end
196+
197+
describe 'additional pg_hba_rules' do
198+
let(:params) do
199+
{
200+
:pg_hba_rules => {
201+
:from_remote_host => {
202+
:type => 'host',
203+
:database => 'mydb',
204+
:user => 'myuser',
205+
:auth_method => 'md5',
206+
:address => '192.0.2.100'
207+
}
208+
}
209+
}
210+
end
211+
212+
it { is_expected.to compile.with_all_deps }
213+
it do
214+
is_expected.to contain_postgresql__server__pg_hba_rule('from_remote_host'). \
215+
with_type('host'). \
216+
with_database('mydb'). \
217+
with_user('myuser'). \
218+
with_auth_method('md5'). \
219+
with_address('192.0.2.100')
220+
end
221+
end
168222
end

0 commit comments

Comments
 (0)