diff --git a/REFERENCE.md b/REFERENCE.md
index 9e53411f..3aada6ab 100644
--- a/REFERENCE.md
+++ b/REFERENCE.md
@@ -49,6 +49,12 @@ file on an haproxy load balancer.
* `haproxy::mailer::collect_exported`
* `haproxy::service`: HAProxy service
+### Functions
+
+* [`haproxy::generate_error_message`](#haproxy--generate_error_message): Function created to generate error message. Any string as error message can be passed and the function can be called in epp templates.
+* [`haproxy::sort_bind`](#haproxy--sort_bind)
+* [`haproxy::validate_ip_addr`](#haproxy--validate_ip_addr)
+
## Classes
### `haproxy`
@@ -714,6 +720,7 @@ The following parameters are available in the `haproxy::defaults` defined type:
* [`options`](#-haproxy--defaults--options)
* [`sort_options_alphabetic`](#-haproxy--defaults--sort_options_alphabetic)
+* [`merge_options`](#-haproxy--defaults--merge_options)
* [`instance`](#-haproxy--defaults--instance)
##### `options`
@@ -733,6 +740,16 @@ Defaults to true.
Default value: `true`
+##### `merge_options`
+
+Data type: `Boolean`
+
+Whether to merge the user-supplied `options` hash with the
+`default_options` values set in params.pp. Merging allows to change
+or add options without having to recreate the entire hash.
+
+Default value: `$haproxy::params::merge_options`
+
##### `instance`
Data type: `String`
@@ -2010,3 +2027,61 @@ Optional. Defaults to 'haproxy'
Default value: `'haproxy'`
+## Functions
+
+### `haproxy::generate_error_message`
+
+Type: Ruby 4.x API
+
+Function created to generate error message. Any string as error message can be passed and the function can
+be called in epp templates.
+
+#### `haproxy::generate_error_message(String $error_message)`
+
+Function created to generate error message. Any string as error message can be passed and the function can
+be called in epp templates.
+
+Returns: `Any`
+
+##### `error_message`
+
+Data type: `String`
+
+
+
+### `haproxy::sort_bind`
+
+Type: Ruby 4.x API
+
+The haproxy::sort_bind function.
+
+#### `haproxy::sort_bind(Hash $bind)`
+
+The haproxy::sort_bind function.
+
+Returns: `Array`
+
+##### `bind`
+
+Data type: `Hash`
+
+
+
+### `haproxy::validate_ip_addr`
+
+Type: Ruby 4.x API
+
+The haproxy::validate_ip_addr function.
+
+#### `haproxy::validate_ip_addr(String $virtual_ip)`
+
+The haproxy::validate_ip_addr function.
+
+Returns: `Boolean`
+
+##### `virtual_ip`
+
+Data type: `String`
+
+
+
diff --git a/manifests/defaults.pp b/manifests/defaults.pp
index 636d33fc..a3bb838c 100644
--- a/manifests/defaults.pp
+++ b/manifests/defaults.pp
@@ -16,12 +16,18 @@
# Sort options either alphabetic or custom like haproxy internal sorts them.
# Defaults to true.
#
+# @param merge_options
+# Whether to merge the user-supplied `options` hash with the
+# `default_options` values set in params.pp. Merging allows to change
+# or add options without having to recreate the entire hash.
+#
# @param instance
# Optional. Defaults to 'haproxy'.
#
define haproxy::defaults (
Hash $options = {},
Boolean $sort_options_alphabetic = true,
+ Boolean $merge_options = $haproxy::params::merge_options,
String $instance = 'haproxy',
) {
if $instance == 'haproxy' {
@@ -36,9 +42,16 @@
include haproxy::globals
$_sort_options_alphabetic = pick($sort_options_alphabetic, $haproxy::globals::sort_options_alphabetic)
+ $defaults_options = pick($options, $haproxy::params::defaults_options)
+ if $merge_options {
+ $_defaults_options = $haproxy::params::defaults_options + $defaults_options
+ } else {
+ $_defaults_options = $defaults_options
+ }
+
$parameters = {
'_sort_options_alphabetic' => $_sort_options_alphabetic,
- 'options' => $options,
+ 'options' => $_defaults_options,
'name' => $name,
}
diff --git a/spec/defines/defaults_spec.rb b/spec/defines/defaults_spec.rb
index 302b8e41..47ed6e44 100644
--- a/spec/defines/defaults_spec.rb
+++ b/spec/defines/defaults_spec.rb
@@ -25,7 +25,8 @@
context 'with a single option' do
let(:params) do
{
- options: { 'balance' => 'roundrobin' }
+ options: { 'balance' => 'roundrobin' },
+ merge_options: false
}
end
@@ -37,4 +38,37 @@
)
}
end
+
+ context 'with merge defaults true' do
+ let(:params) do
+ {
+ options: { 'balance' => 'roundrobin' }
+ }
+ end
+
+ defaults_output = <<~EXPECTEDOUTPUT
+
+
+ defaults test
+ balance roundrobin
+ log global
+ maxconn 8000
+ option redispatch
+ retries 3
+ stats enable
+ timeout http-request 10s
+ timeout queue 1m
+ timeout connect 10s
+ timeout client 1m
+ timeout server 1m
+ timeout check 10s
+ EXPECTEDOUTPUT
+ it {
+ is_expected.to contain_concat__fragment('haproxy-test_defaults_block').with(
+ 'order' => '25-test',
+ 'target' => '/tmp/haproxy.cfg',
+ 'content' => defaults_output,
+ )
+ }
+ end
end