From f66359c3ec09555267fc4f3d1149873f7f7b51b1 Mon Sep 17 00:00:00 2001 From: Eric Heydrick Date: Fri, 28 Jan 2022 14:43:14 -0800 Subject: [PATCH] Add option property to haproxy_listen Signed-off-by: Eric Heydrick --- CHANGELOG.md | 2 ++ documentation/haproxy_listen.md | 1 + resources/listen.rb | 8 ++++++++ templates/default/haproxy.cfg.erb | 7 +++++++ test/cookbooks/test/recipes/config_4.rb | 1 + test/integration/config_4/example_spec.rb | 1 + 6 files changed, 20 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 67796fbf..2086715d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ This file is used to list changes made in each version of the haproxy cookbook. ## Unreleased +- Add `option` property to `haproxy_listen` - [@eheydrick](https://github.com/eheydrick) + ## 12.2.2 - *2021-10-05* ## 12.2.1 - *2021-08-30* diff --git a/documentation/haproxy_listen.md b/documentation/haproxy_listen.md index c682229b..efdb5056 100644 --- a/documentation/haproxy_listen.md +++ b/documentation/haproxy_listen.md @@ -37,6 +37,7 @@ This resource also uses the following partial resources: | `server` | Array | None | Servers the listen section routes to | | `stats` | Hash | None | Enable stats with various options | | `hash_type` | String | None | Specify a method to use for mapping hashes to servers | `consistent`, `map-based` | +| `option` | Array | None | Array of HAProxy `option` directives | ## Examples diff --git a/resources/listen.rb b/resources/listen.rb index f7e145fa..a1519428 100644 --- a/resources/listen.rb +++ b/resources/listen.rb @@ -39,6 +39,9 @@ property :acl, Array, description: 'Access control list items' +property :option, Array, + description: 'Array of HAProxy option directives' + property :server, Array, description: 'Servers the listen section routes to' @@ -95,6 +98,11 @@ haproxy_config_resource.variables['listen'][new_resource.name]['server'].push(new_resource.server) end + if property_is_set?(:option) + haproxy_config_resource.variables['listen'][new_resource.name]['option'] ||= [] + haproxy_config_resource.variables['listen'][new_resource.name]['option'].push(new_resource.option) + end + haproxy_config_resource.variables['listen'][new_resource.name]['hash_type'] = new_resource.hash_type if property_is_set?(:hash_type) haproxy_config_resource.variables['listen'][new_resource.name]['extra_options'] = new_resource.extra_options if property_is_set?(:extra_options) end diff --git a/templates/default/haproxy.cfg.erb b/templates/default/haproxy.cfg.erb index 8744e2a2..effdf793 100644 --- a/templates/default/haproxy.cfg.erb +++ b/templates/default/haproxy.cfg.erb @@ -419,6 +419,13 @@ listen <%= key %> <% if listen['default_backend'] -%> default_backend <%= listen['default_backend'] %> <% end %> +<% unless nil_or_empty?(listen['option']) %> +<% listen['option'].each do | option |%> +<% option.each do | option | %> + option <%= option %> +<% end -%> +<% end -%> +<% end -%> <% unless nil_or_empty?(listen['extra_options']) %> <% listen['extra_options'].each do | key, value | %> <% if key == 'http-request' %> diff --git a/test/cookbooks/test/recipes/config_4.rb b/test/cookbooks/test/recipes/config_4.rb index b7edd0dc..c53fd892 100644 --- a/test/cookbooks/test/recipes/config_4.rb +++ b/test/cookbooks/test/recipes/config_4.rb @@ -20,6 +20,7 @@ ] http_response 'set-header Expires %[date(3600),http_date]' default_backend 'servers' + option ['dontlog-normal'] extra_options('bind-process' => 'odd') hash_type 'consistent' end diff --git a/test/integration/config_4/example_spec.rb b/test/integration/config_4/example_spec.rb index ce88640b..9e2cb8b0 100644 --- a/test/integration/config_4/example_spec.rb +++ b/test/integration/config_4/example_spec.rb @@ -71,6 +71,7 @@ ' http-request add-header X-Proto http', ' http-response set-header Expires %\[date\(3600\),http_date\]', ' default_backend servers', + ' option dontlog-normal', ' bind-process odd', ' hash-type consistent', '',