Skip to content

Commit 4e6b4de

Browse files
committed
allow docker::networks::networks param to be undef
I would like to include the docker::networks class into the role (manifest) of nodes which are also including the docker module but not necessarily always defining docker network(s). This would allow docker networks to optionally be defined, when needed, via hiera. Currently, this type of arrangement would require constructing a wrapper class as the docker::networks::networks parameter is mandatory.
1 parent f5a06f9 commit 4e6b4de

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

manifests/networks.pp

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
# @param networks
44
#
55
class docker::networks(
6-
$networks
6+
Optional[Hash[String, Hash]] $networks = undef,
77
) {
8-
create_resources(docker_network, $networks)
8+
if $networks {
9+
create_resources(docker_network, $networks)
10+
}
911
}

spec/classes/networks_spec.rb

+6
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,14 @@
6161
'ip_range' => params['ip_range'],
6262
)
6363
}
64+
65+
it { is_expected.to have_docker_network_resource_count(1) }
6466
end
6567
end
68+
69+
context 'with no params' do
70+
it { is_expected.to have_docker_network_resource_count(0) }
71+
end
6672
end
6773
end
6874
end

0 commit comments

Comments
 (0)