diff --git a/REFERENCE.md b/REFERENCE.md
index 9ad706b1..aa9a657b 100644
--- a/REFERENCE.md
+++ b/REFERENCE.md
@@ -615,6 +615,7 @@ The following parameters are available in the `consul::check` defined type:
* [`service_id`](#-consul--check--service_id)
* [`status`](#-consul--check--status)
* [`tcp`](#-consul--check--tcp)
+* [`grpc`](#-consul--check--grpc)
* [`timeout`](#-consul--check--timeout)
* [`token`](#-consul--check--token)
* [`ttl`](#-consul--check--ttl)
@@ -703,6 +704,14 @@ The IP/hostname and port for the service healthcheck. Should be in 'hostname:por
Default value: `undef`
+##### `grpc`
+
+Data type: `Any`
+
+GRPC endpoint for the service healthcheck
+
+Default value: `undef`
+
##### `timeout`
Data type: `Any`
diff --git a/lib/puppet/functions/consul/validate_checks.rb b/lib/puppet/functions/consul/validate_checks.rb
index 8f9da6bd..1f1674e9 100644
--- a/lib/puppet/functions/consul/validate_checks.rb
+++ b/lib/puppet/functions/consul/validate_checks.rb
@@ -14,20 +14,22 @@ def validate_checks(obj)
validate_checks(c)
end
when Hash
- raise Puppet::ParseError, 'interval must be defined for tcp, http, and script checks' if (obj.key?('http') || (obj.key?('script') || obj.key?('args')) || obj.key?('tcp')) && !obj.key?('interval')
+ raise Puppet::ParseError, 'interval must be defined for tcp, http, grpc and script checks' if (obj.key?('http') || (obj.key?('script') || obj.key?('args')) || obj.key?('tcp') || obj.key?('grpc')) && !obj.key?('interval')
if obj.key?('ttl')
- raise Puppet::ParseError, 'script, http, tcp, and interval must not be defined for ttl checks' if obj.key?('http') || (obj.key?('args') || obj.key?('script')) || obj.key?('tcp') || obj.key?('interval')
+ raise Puppet::ParseError, 'script, http, tcp, grpc and interval must not be defined for ttl checks' if (obj.key?('http') || (obj.key?('args') || obj.key?('script')) || obj.key?('tcp') || obj.key?('grpc')) || obj.key?('interval')
elsif obj.key?('http')
- raise Puppet::ParseError, 'script and tcp must not be defined for http checks' if (obj.key?('args') || obj.key?('script')) || obj.key?('tcp')
+ raise Puppet::ParseError, 'script, tcp and grpc must not be defined for http checks' if (obj.key?('args') || obj.key?('script')) || obj.key?('tcp') || obj.key?('grpc')
+ elsif obj.key?('grpc')
+ raise Puppet::ParseError, 'script, tcp and http must not be defined for grpc checks' if (obj.key?('args') || obj.key?('script')) || obj.key?('tcp') || obj.key?('http')
elsif obj.key?('tcp')
- raise Puppet::ParseError, 'script and http must not be defined for tcp checks' if obj.key?('http') || (obj.key?('args') || obj.key?('script'))
+ raise Puppet::ParseError, 'script, http and grpc must not be defined for tcp checks' if obj.key?('http') || (obj.key?('args') || obj.key?('script')) || obj.key?('grpc')
elsif obj.key?('args') || obj.key?('script')
- raise Puppet::ParseError, 'http and tcp must not be defined for script checks' if obj.key?('http') || obj.key?('tcp')
+ raise Puppet::ParseError, 'http, grpc and tcp must not be defined for script checks' if obj.key?('http') || obj.key?('tcp') || obj.key?('grpc')
elsif obj.key?('alias_service')
- raise Puppet::ParseError, 'alias_service must not define http, tcp, args, script, or interval' if obj.key?('http') || obj.key?('tcp') || obj.key?('args') || obj.key?('script') || obj.key?('interval')
+ raise Puppet::ParseError, 'alias_service must not define http, tcp, grpc, args, script, or interval' if obj.key?('http') || obj.key?('tcp') || obj.key?('args') || obj.key?('script') || obj.key?('interval') || obj.key?('grpc')
else
- raise Puppet::ParseError, 'One of ttl, script, tcp, or http must be defined.'
+ raise Puppet::ParseError, 'One of ttl, script, tcp, grpc or http must be defined.'
end
else
raise Puppet::ParseError, 'Unable to handle object of type <%s>' % obj.class.to_s
diff --git a/manifests/check.pp b/manifests/check.pp
index 0272db97..3fc9b00b 100644
--- a/manifests/check.pp
+++ b/manifests/check.pp
@@ -15,6 +15,7 @@
# @param service_id An optional service_id to match this check against
# @param status The default state of the check when it is registered against a consul agent. Should be either "critical" or "passing"
# @param tcp The IP/hostname and port for the service healthcheck. Should be in 'hostname:port' format.
+# @param grpc GRPC endpoint for the service healthcheck
# @param timeout A timeout value for HTTP request only
# @param token ACL token for interacting with the catalog (must be 'management' type)
# @param ttl Value in seconds before the http endpoint considers a failing healthcheck to be "HARD" down.
@@ -32,6 +33,7 @@
$service_id = undef,
$status = undef,
$tcp = undef,
+ $grpc = undef,
$timeout = undef,
$token = undef,
$ttl = undef,
@@ -48,6 +50,7 @@
'script' => $script,
'args' => $args,
'tcp' => $tcp,
+ 'grpc' => $grpc,
'interval' => $interval,
'timeout' => $timeout,
'service_id' => $service_id,
diff --git a/spec/defines/consul_check_spec.rb b/spec/defines/consul_check_spec.rb
index 3913e22c..e4157a95 100644
--- a/spec/defines/consul_check_spec.rb
+++ b/spec/defines/consul_check_spec.rb
@@ -240,6 +240,41 @@
}
end
+ describe 'with grpc' do
+ let(:params) do
+ {
+ 'grpc' => 'localhost:80',
+ 'interval' => '30s',
+ }
+ end
+
+ it {
+ is_expected.to contain_file('/etc/consul/check_my_check.json'). \
+ with_content(%r{"id" *: *"my_check"}). \
+ with_content(%r{"name" *: *"my_check"}). \
+ with_content(%r{"check" *: *\{}). \
+ with_content(%r{"grpc" *: *"localhost:80"})
+ }
+ end
+
+ describe 'with grpc with interval' do
+ let(:params) do
+ {
+ 'grpc' => 'localhost:80',
+ 'interval' => '30s',
+ }
+ end
+
+ it {
+ is_expected.to contain_file('/etc/consul/check_my_check.json'). \
+ with_content(%r{"id" *: *"my_check"}). \
+ with_content(%r{"name" *: *"my_check"}). \
+ with_content(%r{"check" *: *\{}). \
+ with_content(%r{"grpc" *: *"localhost:80"}). \
+ with_content(%r{"interval" *: *"30s"})
+ }
+ end
+
describe 'with script and service_id' do
let(:params) do
{
@@ -289,7 +324,7 @@
end
it {
- is_expected.to raise_error(Puppet::Error, %r{script, http, tcp, and interval must not be defined for ttl checks})
+ is_expected.to raise_error(Puppet::Error, %r{script, http, tcp, grpc and interval must not be defined for ttl checks})
}
end
@@ -303,7 +338,7 @@
end
it {
- is_expected.to raise_error(Puppet::Error, %r{script, http, tcp, and interval must not be defined for ttl checks})
+ is_expected.to raise_error(Puppet::Error, %r{script, http, tcp, grpc and interval must not be defined for ttl checks})
}
end
@@ -317,7 +352,7 @@
end
it {
- is_expected.to raise_error(Puppet::Error, %r{script, http, tcp, and interval must not be defined for ttl checks})
+ is_expected.to raise_error(Puppet::Error, %r{script, http, tcp, grpc and interval must not be defined for ttl checks})
}
end
@@ -331,7 +366,7 @@
end
it {
- is_expected.to raise_error(Puppet::Error, %r{script, http, tcp, and interval must not be defined for ttl checks})
+ is_expected.to raise_error(Puppet::Error, %r{script, http, tcp, grpc and interval must not be defined for ttl checks})
}
end
@@ -345,7 +380,7 @@
end
it {
- is_expected.to raise_error(Puppet::Error, %r{script and tcp must not be defined for http checks})
+ is_expected.to raise_error(Puppet::Error, %r{script, tcp and grpc must not be defined for http checks})
}
end
@@ -357,7 +392,7 @@
end
it {
- is_expected.to raise_error(Puppet::Error, %r{interval must be defined for tcp, http, and script checks})
+ is_expected.to raise_error(Puppet::Error, %r{interval must be defined for tcp, http, grpc and script checks})
}
end
@@ -369,7 +404,7 @@
end
it {
- is_expected.to raise_error(Puppet::Error, %r{interval must be defined for tcp, http, and script checks})
+ is_expected.to raise_error(Puppet::Error, %r{interval must be defined for tcp, http, grpc and script checks})
}
end
@@ -381,7 +416,7 @@
end
it {
- is_expected.to raise_error(Puppet::Error, %r{interval must be defined for tcp, http, and script checks})
+ is_expected.to raise_error(Puppet::Error, %r{interval must be defined for tcp, http, grpc and script checks})
}
end