Skip to content
This repository was archived by the owner on Jun 5, 2020. It is now read-only.

Commit ba49280

Browse files
author
misnyo
committed
#214 Add the ability to configure health check params
1 parent 2a75c9e commit ba49280

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,15 @@ The Amazon Resource Name for the associated IAM profile.
481481
#####`scheme`
482482
*Optional* Whether the load balancer is internal or public facing. This parameter is set at creation only; it is not affected by updates. Valid values are 'internal', 'internet-facing'. Default value is 'internet-facing' and makes the load balancer publicly available.
483483

484+
#####`health_check`
485+
*Optional* The health check which the load balancer should perform. For more description, see [AWS Elastic Load Balancing HealthCheck](http://docs.aws.amazon.com/sdkforruby/api/Aws/ElasticLoadBalancing/Types/HealthCheck.html). Accepts a Hash of the following values(all are required):
486+
* target
487+
* interval
488+
* timeout
489+
* healthy_threshold
490+
* unhealthy_threshold
491+
492+
484493
#### Type: cloudwatch_alarm
485494

486495
##### `name`

lib/puppet/provider/elb_loadbalancer/v2.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ def self.load_balancer_to_hash(region, load_balancer)
5757
'instance_port' => listener.listener.instance_port,
5858
}
5959
end
60+
health_check = {}
61+
unless load_balancer.health_check.nil?
62+
health_check = {
63+
'healthy_threshold' => load_balancer.health_check.healthy_threshold,
64+
'interval' => load_balancer.health_check.interval,
65+
'target' => load_balancer.health_check.target,
66+
'timeout' => load_balancer.health_check.timeout,
67+
'unhealthy_threshold' => load_balancer.health_check.unhealthy_threshold,
68+
}
69+
end
6070
tag_response = elb_client(region).describe_tags(
6171
load_balancer_names: [load_balancer.load_balancer_name]
6272
)
@@ -90,6 +100,7 @@ def self.load_balancer_to_hash(region, load_balancer)
90100
subnets: subnet_names,
91101
security_groups: security_group_names,
92102
scheme: load_balancer.scheme,
103+
health_check: health_check,
93104
}
94105
end
95106

@@ -132,6 +143,10 @@ def create
132143

133144
@property_hash[:ensure] = :present
134145

146+
if ! resource[:health_check].nil?
147+
self.health_check = resource[:health_check]
148+
end
149+
135150
instances = resource[:instances]
136151
if ! instances.nil?
137152
instances = [instances] unless instances.is_a?(Array)
@@ -231,6 +246,20 @@ def subnets=(value)
231246
end
232247
end
233248

249+
def health_check=(value)
250+
elb = elb_client(resource[:region])
251+
elb.configure_health_check({
252+
load_balancer_name: name,
253+
health_check: {
254+
target: value['target'],
255+
interval: value['interval'],
256+
timeout: value['timeout'],
257+
unhealthy_threshold: value['unhealthy_threshold'],
258+
healthy_threshold: value['healthy_threshold'],
259+
},
260+
})
261+
end
262+
234263
def destroy
235264
Puppet.info("Destroying load balancer #{name} in region #{target_region}")
236265
elb_client(target_region).delete_load_balancer(

lib/puppet/type/elb_loadbalancer.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,20 @@ def insync?(is)
9191
end
9292
end
9393

94+
newproperty(:health_check) do
95+
desc 'Health check.'
96+
def insync?(is)
97+
normalise(is).to_set == normalise(should).to_set
98+
end
99+
def normalise(value)
100+
value.each { |k,v| value[k] = v.to_s }
101+
Hash[value.sort]
102+
end
103+
validate do |value|
104+
fail 'health check should be a Hash' unless value.is_a?(Hash)
105+
end
106+
end
107+
94108
validate do
95109
subnets = self[:subnets]
96110
zones = self[:availability_zones]

0 commit comments

Comments
 (0)