haproxy supports a single port or port range, but also muliples of those. This commit changes the 'virtual_ip_port' parameter to 'ports' and updates the template to accept an array of ports
# The namevar of the defined resource type is the listening service's name.
# This name goes right after the 'listen' statement in haproxy.cfg
#
-# [*virtual_ip_port*]
-# A unique port, or a port range for which the proxy will accept connections
-# for the ip address specified in the virtual_ip parameter.
+# [*ports*]
+# Ports on which the proxy will listen for connections on the ip address
+# specified in the virtual_ip parameter. Accepts either a single string or
+# an array of strings which may be a unique port or a hyphenated port range.
#
# [*order*]
# The order, or numerical weight, of the fragment created by this defined
# [*haproxy_config_options*]
# A hash of options that are inserted into the listening service
# configuration block.
-#
+#
# [*collect_exported*]
# Boolean, default 'true'. True means 'collect exported @@balancermember resources'
# (for the case when every balancermember node exports itself), false means
# 'rely on the existing declared balancermember resources' (for the case when you
# know the full set of balancermembers in advance and use haproxy::balancermember
# with array arguments, which allows you to deploy everything in 1 run)
-#
+#
#
# === Examples
#
# Gary Larizza <gary@puppetlabs.com>
#
define haproxy::config (
- $virtual_ip_port,
+ $ports,
$order = '20',
$virtual_ip = $::ipaddress,
$mode = 'tcp',
describe 'haproxy::config' do
let(:title) { 'tyler' }
let(:facts) {{ :ipaddress => '1.1.1.1' }}
- let(:params) do
- { :name => 'croy',
- :virtual_ip_port => '18140'
- }
+ context "when only one port is provided" do
+ let(:params) do
+ { :name => 'croy',
+ :ports => '18140'
+ }
+ end
+
+ it { should contain_concat__fragment('croy_config_block').with(
+ 'order' => '20',
+ 'target' => '/etc/haproxy/haproxy.cfg',
+ 'content' => "\nlisten croy 1.1.1.1:18140\n balance roundrobin\n option tcplog\n option ssl-hello-chk\n"
+ ) }
end
+ context "when an array of ports is provided" do
+ let(:params) do
+ { :name => 'apache',
+ :ports => [
+ '80',
+ '443',
+ ]
+ }
+ end
- it { should contain_concat__fragment('croy_config_block').with(
- 'order' => '20',
- 'target' => '/etc/haproxy/haproxy.cfg',
- 'content' => "\nlisten croy 1.1.1.1:18140\n balance roundrobin\n option tcplog\n option ssl-hello-chk\n"
+ it { should contain_concat__fragment('apache_config_block').with(
+ 'order' => '20',
+ 'target' => '/etc/haproxy/haproxy.cfg',
+ 'content' => "\nlisten apache 1.1.1.1:80,1.1.1.1:443\n balance roundrobin\n option tcplog\n option ssl-hello-chk\n"
) }
-end
\ No newline at end of file
+ end
+end
-listen <%= name %> <%= virtual_ip %>:<%= virtual_ip_port %>
+listen <%= name %> <%= virtual_ip %>:<%= Array(ports).join(",#{virtual_ip}:") %>
<% haproxy_config_options.sort.each do |key, val| -%>
<% if val.is_a?(Array) -%>
<% val.each do |item| -%>