Skip to content

Commit

Permalink
Merge pull request #460 from dan-wittenberg/master
Browse files Browse the repository at this point in the history
Add service_config_hash to customize services
  • Loading branch information
bastelfreak committed Jan 14, 2019
2 parents 09449a4 + 2287ac3 commit f2e5366
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
1 change: 1 addition & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
$service_enable = true
$service_ensure = 'running'
$services = {}
$service_config_hash = {}
$user = 'consul'
$version = '1.2.3'
$watches = {}
Expand Down
48 changes: 38 additions & 10 deletions manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,49 @@
# [*service_name*]
# Name of the service. Defaults to title.
#
# [*service_config_hash*]
# Use this to populate the basic service params for each of the services
#
# [*tags*]
# Array of strings.
#
# [*token*]
# ACL token for interacting with the catalog (must be 'management' type)
#
# === Examples
# @example
# ::consul::service { 'my_db':
# port => 3306,
# tags => ['db','mysql'],
# address => '1.2.3.4',
# token => 'xxxxxxxxxx',
# service_config_hash => {
# 'connect' => {
# 'sidecar_service' => {},
# },
# },
# checks => [
# {
# name => 'MySQL Port',
# tcp => 'localhost:3306',
# interval => '10s',
# },
# ],
# }
#
define consul::service(
$address = undef,
$checks = [],
$enable_tag_override = false,
$ensure = present,
$id = $title,
$port = undef,
$service_name = $title,
$tags = [],
$token = undef,
$address = undef,
$checks = [],
$enable_tag_override = false,
$ensure = present,
$id = $title,
$port = undef,
$service_name = $title,
Hash $service_config_hash = {},
$tags = [],
$token = undef,
) {

include consul

consul::validate_checks($checks)
Expand All @@ -54,7 +80,7 @@
$override_key = 'enableTagOverride'
}

$basic_hash = {
$default_config_hash = {
'id' => $id,
'name' => $service_name,
'address' => $address,
Expand All @@ -65,6 +91,8 @@
$override_key => $enable_tag_override,
}

$basic_hash = $default_config_hash + $service_config_hash

$service_hash = {
service => delete_undef_values($basic_hash),
}
Expand Down

0 comments on commit f2e5366

Please sign in to comment.