Skip to content

Commit dcfd35d

Browse files
authored
Merge pull request #610 from traylenator/ports
Allow ports parameters as Stdlib::Ports
2 parents 19051b6 + 13b08bb commit dcfd35d

File tree

11 files changed

+173
-59
lines changed

11 files changed

+173
-59
lines changed

README.md

+15-15
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,20 @@ node 'haproxy-server' {
4343
haproxy::listen { 'puppet00':
4444
collect_exported => false,
4545
ipaddress => $facts['networking']['ip'],
46-
ports => '8140',
46+
ports => [8140],
4747
}
4848
haproxy::balancermember { 'server00':
4949
listening_service => 'puppet00',
5050
server_names => 'server00.example.com',
5151
ipaddresses => '10.0.0.10',
52-
ports => '8140',
52+
ports => [8140],
5353
options => 'check',
5454
}
5555
haproxy::balancermember { 'server01':
5656
listening_service => 'puppet00',
5757
server_names => 'server01.example.com',
5858
ipaddresses => '10.0.0.11',
59-
ports => '8140',
59+
ports => [8140],
6060
options => 'check',
6161
}
6262
}
@@ -153,7 +153,7 @@ To export the resource for a balancermember and collect it on a single HAProxy l
153153
~~~puppet
154154
haproxy::listen { 'puppet00':
155155
ipaddress => $facts['networking']['ip'],
156-
ports => '8140',
156+
ports => [8140],
157157
mode => 'tcp',
158158
options => {
159159
'option' => [
@@ -213,7 +213,7 @@ Then create the resource for multiple balancermembers at once:
213213
~~~puppet
214214
haproxy::balancermember { 'haproxy':
215215
listening_service => 'puppet00',
216-
ports => '8140',
216+
ports => 8140,
217217
server_names => ['server01', 'server02'],
218218
ipaddresses => ['192.168.56.200', '192.168.56.201'],
219219
options => 'check',
@@ -231,7 +231,7 @@ node 'haproxy-server' {
231231
include ::haproxy
232232
haproxy::listen { 'puppet00':
233233
ipaddress => $facts['networking']['ip'],
234-
ports => '8140',
234+
ports => 8140,
235235
}
236236
}
237237
@@ -240,7 +240,7 @@ node /^server\d+/ {
240240
listening_service => 'puppet00',
241241
server_names => $facts['networking']['hostname'],
242242
ipaddresses => $facts['networking']['ip'],
243-
ports => '8140',
243+
ports => 8140,
244244
options => 'check',
245245
}
246246
}
@@ -255,7 +255,7 @@ This example routes traffic from port 8140 to all balancermembers added to a bac
255255
~~~puppet
256256
haproxy::frontend { 'puppet00':
257257
ipaddress => $facts['networking']['ip'],
258-
ports => '8140',
258+
ports => 8140,
259259
mode => 'tcp',
260260
bind_options => 'accept-proxy',
261261
options => {
@@ -274,7 +274,7 @@ If option order is important, pass an array of hashes to the `options` parameter
274274
~~~puppet
275275
haproxy::frontend { 'puppet00':
276276
ipaddress => $facts['networking']['ip'],
277-
ports => '8140',
277+
ports => [8140],
278278
mode => 'tcp',
279279
bind_options => 'accept-proxy',
280280
options => [
@@ -353,7 +353,7 @@ haproxy::resolver { 'puppet00':
353353
# Setup the balancermember to use the resolver for DNS resolution
354354
haproxy::balancermember { 'haproxy':
355355
listening_service => 'puppet00',
356-
ports => '8140',
356+
ports => 8140,
357357
server_names => ['server01', 'server02'],
358358
ipaddresses => ['server01', 'server02'],
359359
options => 'check resolvers puppet00 resolve-prefer ipv4',
@@ -399,7 +399,7 @@ class and uses `haproxy::instance` to add an additional instance called
399399
instance => 'haproxy',
400400
collect_exported => false,
401401
ipaddress => $facts['networking']['ip'],
402-
ports => '8800',
402+
ports => 8800,
403403
}
404404
405405
haproxy::instance { 'beta': }
@@ -413,7 +413,7 @@ class and uses `haproxy::instance` to add an additional instance called
413413
instance => 'beta',
414414
collect_exported => false,
415415
ipaddress => $facts['networking']['ip'],
416-
ports => '9900',
416+
ports => 9900,
417417
}
418418
~~~
419419

@@ -432,7 +432,7 @@ The second uses a custom package.
432432
instance => 'group1',
433433
collect_exported => false,
434434
ipaddress => $facts['networking']['ip'],
435-
ports => '8800',
435+
ports => 8800,
436436
}
437437
haproxy::instance { 'group2': }
438438
->
@@ -446,7 +446,7 @@ The second uses a custom package.
446446
instance => 'group2',
447447
collect_exported => false,
448448
ipaddress => $facts['networking']['ip'],
449-
ports => '9900',
449+
ports => 9900,
450450
}
451451
~~~
452452

@@ -481,7 +481,7 @@ Or expressed using `haproxy::frontend`:
481481
~~~puppet
482482
haproxy::frontend { 'ft_allapps':
483483
ipaddress => '0.0.0.0',
484-
ports => '80',
484+
ports => ['80'],
485485
mode => 'http',
486486
options => {
487487
'use_backend' => '%[req.hdr(host),lower,map(/etc/haproxy/domains-to-backends.map,bk_default)]'

REFERENCE.md

+19-7
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ file on an haproxy load balancer.
5555
* [`haproxy::sort_bind`](#haproxy--sort_bind)
5656
* [`haproxy::validate_ip_addr`](#haproxy--validate_ip_addr)
5757

58+
### Data types
59+
60+
* [`Haproxy::Ports`](#Haproxy--Ports): Port or list of ports for haproxy. Supports `,` seperated list of ports also.
61+
5862
## Classes
5963

6064
### <a name="haproxy"></a>`haproxy`
@@ -485,7 +489,7 @@ Exporting the resource for a balancer member:
485489
486490
@@haproxy::balancermember { 'haproxy':
487491
listening_service => 'puppet00',
488-
ports => '8140',
492+
ports => [8140],
489493
server_names => $::hostname,
490494
ipaddresses => $::ipaddress,
491495
options => 'check',
@@ -505,7 +509,7 @@ pass to export the resources if you know the members in advance):
505509
506510
haproxy::balancermember { 'haproxy':
507511
listening_service => 'puppet00',
508-
ports => '8140',
512+
ports => 8140,
509513
server_names => ['server01', 'server02'],
510514
ipaddresses => ['192.168.56.200', '192.168.56.201'],
511515
options => 'check',
@@ -566,7 +570,7 @@ The haproxy service's instance name (or, the title of the
566570

567571
##### <a name="-haproxy--balancermember--ports"></a>`ports`
568572

569-
Data type: `Optional[Variant[Array, String]]`
573+
Data type: `Optional[Haproxy::Ports]`
570574

571575
An array or commas-separated list of ports for which the balancer member
572576
will accept connections from the load balancer. Note that cookie values
@@ -777,7 +781,7 @@ Exporting the resource for a balancer member:
777781
778782
haproxy::frontend { 'puppet00':
779783
ipaddress => $::ipaddress,
780-
ports => '18140',
784+
ports => [18140],
781785
mode => 'tcp',
782786
bind_options => 'accept-proxy',
783787
options => {
@@ -821,7 +825,7 @@ Default value: `$name`
821825

822826
##### <a name="-haproxy--frontend--ports"></a>`ports`
823827

824-
Data type: `Optional[Variant[Array, String]]`
828+
Data type: `Optional[Haproxy::Ports]`
825829

826830
Ports on which the proxy will listen for connections on the ip address
827831
specified in the ipaddress parameter. Accepts either a single
@@ -1286,7 +1290,7 @@ load balancer server.
12861290
```puppet
12871291
haproxy::listen { 'puppet00':
12881292
ipaddress => $::ipaddress,
1289-
ports => '18140',
1293+
ports => [18140],
12901294
mode => 'tcp',
12911295
options => {
12921296
'option' => [
@@ -1327,7 +1331,7 @@ Default value: `$name`
13271331

13281332
##### <a name="-haproxy--listen--ports"></a>`ports`
13291333

1330-
Data type: `Optional[Variant[Array, String]]`
1334+
Data type: `Optional[Haproxy::Ports]`
13311335

13321336
Ports on which the proxy will listen for connections on the ip address
13331337
specified in the ipaddress parameter. Accepts either a single
@@ -2085,3 +2089,11 @@ Data type: `String`
20852089

20862090

20872091

2092+
## Data types
2093+
2094+
### <a name="Haproxy--Ports"></a>`Haproxy::Ports`
2095+
2096+
Port or list of ports for haproxy. Supports `,` seperated list of ports also.
2097+
2098+
Alias of `Variant[Array[Variant[Pattern[/^[0-9]+$/],Stdlib::Port],0], Pattern[/^[0-9,]+$/], Stdlib::Port]`
2099+

manifests/balancermember.pp

+3-3
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
#
9191
# @@haproxy::balancermember { 'haproxy':
9292
# listening_service => 'puppet00',
93-
# ports => '8140',
93+
# ports => [8140],
9494
# server_names => $::hostname,
9595
# ipaddresses => $::ipaddress,
9696
# options => 'check',
@@ -108,7 +108,7 @@
108108
#
109109
# haproxy::balancermember { 'haproxy':
110110
# listening_service => 'puppet00',
111-
# ports => '8140',
111+
# ports => 8140,
112112
# server_names => ['server01', 'server02'],
113113
# ipaddresses => ['192.168.56.200', '192.168.56.201'],
114114
# options => 'check',
@@ -137,7 +137,7 @@
137137
define haproxy::balancermember (
138138
String $listening_service,
139139
Enum['server', 'default-server', 'server-template'] $type = 'server',
140-
Optional[Variant[Array, String]] $ports = undef,
140+
Optional[Haproxy::Ports] $ports = undef,
141141
Optional[Variant[String, Stdlib::Port]] $port = undef,
142142
Variant[String[1], Array] $server_names = $facts['networking']['hostname'],
143143
Variant[String, Array] $ipaddresses = $facts['networking']['ip'],

manifests/frontend.pp

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
#
7474
# haproxy::frontend { 'puppet00':
7575
# ipaddress => $::ipaddress,
76-
# ports => '18140',
76+
# ports => [18140],
7777
# mode => 'tcp',
7878
# bind_options => 'accept-proxy',
7979
# options => {
@@ -91,7 +91,7 @@
9191
# Gary Larizza <[email protected]>
9292
#
9393
define haproxy::frontend (
94-
Optional[Variant[Array, String]] $ports = undef,
94+
Optional[Haproxy::Ports] $ports = undef,
9595
Optional[Variant[String, Array]] $ipaddress = undef,
9696
Optional[Hash] $bind = undef,
9797
Optional[Enum['tcp', 'http', 'health']] $mode = undef,

manifests/listen.pp

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
# @example
7979
# haproxy::listen { 'puppet00':
8080
# ipaddress => $::ipaddress,
81-
# ports => '18140',
81+
# ports => [18140],
8282
# mode => 'tcp',
8383
# options => {
8484
# 'option' => [
@@ -94,7 +94,7 @@
9494
# Gary Larizza <[email protected]>
9595
#
9696
define haproxy::listen (
97-
Optional[Variant[Array, String]] $ports = undef,
97+
Optional[Haproxy::Ports] $ports = undef,
9898
Optional[Variant[String, Array]] $ipaddress = undef,
9999
Optional[Hash] $bind = undef,
100100
Optional[Enum['tcp', 'http', 'health']] $mode = undef,

spec/acceptance/basic_spec.rb

+28-2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,32 @@ class { 'haproxy':
3838

3939
describe 'configuring haproxy load balancing' do
4040
describe 'multiple ports' do
41+
pp_two = <<-PUPPETCODE
42+
class { 'haproxy': }
43+
haproxy::listen { 'stats':
44+
ipaddress => '127.0.0.1',
45+
ports => [9090, 9091],
46+
mode => 'http',
47+
options => { 'stats' => ['uri /','auth puppet:puppet'], },
48+
}
49+
PUPPETCODE
50+
it 'is able to listen on an array of ports' do
51+
retry_on_error_matching do
52+
apply_manifest(pp_two, catch_failures: true)
53+
end
54+
end
55+
56+
['9090', '9091'].each do |port|
57+
it "port #{port} has stats listening on each port" do
58+
run_shell("/usr/bin/curl -u puppet:puppet localhost:#{port}") do |r|
59+
expect(r.stdout).to contain %r{HAProxy}
60+
expect(r.exit_code).to eq 0
61+
end
62+
end
63+
end
64+
end
65+
66+
describe 'multiple ports as strings' do
4167
pp_two = <<-PUPPETCODE
4268
class { 'haproxy': }
4369
haproxy::listen { 'stats':
@@ -71,7 +97,7 @@ class { 'haproxy::globals':
7197
class { 'haproxy': }
7298
haproxy::listen { 'stats':
7399
ipaddress => '127.0.0.1',
74-
ports => ['9090','9091'],
100+
ports => [9090,9091],
75101
mode => 'http',
76102
options => { 'stats' => ['uri /','auth puppet:puppet'], },
77103
}
@@ -101,7 +127,7 @@ class { 'haproxy::globals':
101127
class { 'haproxy': }
102128
haproxy::listen { 'stats':
103129
ipaddress => '127.0.0.1',
104-
ports => ['9091'],
130+
ports => [9091],
105131
mode => 'http',
106132
}
107133
haproxy::backend { 'servers':

0 commit comments

Comments
 (0)