Skip to content

Commit fa959c5

Browse files
committed
extensions type loop to install extensions
1 parent 121a455 commit fa959c5

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

manifests/server.pp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@
103103
# @param grants Specifies a hash from which to generate postgresql::server::grant resources.
104104
# @param config_entries Specifies a hash from which to generate postgresql::server::config_entry resources.
105105
# @param pg_hba_rules Specifies a hash from which to generate postgresql::server::pg_hba_rule resources.
106+
# @param extensions Specifies a hash from which to generate postgresql::server::extension resources.
107+
# The hash keys are database names, and the values are hashes of extension names to extension parameters.
106108
#
107109
# @param backup_enable Whether a backup job should be enabled.
108110
# @param backup_options A hash of options that should be passed through to the backup provider.
@@ -189,6 +191,7 @@
189191
Hash[String[1], Hash] $grants = {},
190192
Hash[String, Any] $config_entries = {},
191193
Postgresql::Pg_hba_rules $pg_hba_rules = {},
194+
Hash[String, Hash] $extensions = {},
192195

193196
Boolean $backup_enable = $postgresql::params::backup_enable,
194197
Hash $backup_options = {},
@@ -238,6 +241,26 @@
238241
}
239242
}
240243

244+
# Create databases first if not already defined
245+
$extensions.each |$database, $extensions_hash| {
246+
if $database != 'postgres' and ! defined(Postgresql::Server::Database[$database]) {
247+
# The database resource doesn't exist, create it
248+
postgresql::server::database { $database:
249+
dbname => $database,
250+
}
251+
}
252+
}
253+
254+
$extensions.each |$database, $extensions_hash| {
255+
$extensions_hash.each |$extension_name, $extension_params| {
256+
postgresql::server::extension { "${database}:${extension_name}":
257+
database => $database,
258+
* => $extension_params,
259+
}
260+
}
261+
}
262+
263+
241264
if $backup_enable {
242265
case $backup_provider {
243266
'pg_dump': {

0 commit comments

Comments
 (0)