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

Commit

Permalink
#214 Add the ability to configure health check params
Browse files Browse the repository at this point in the history
  • Loading branch information
misnyo committed Jan 5, 2016
1 parent 2a75c9e commit ba49280
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,15 @@ The Amazon Resource Name for the associated IAM profile.
#####`scheme`
*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.

#####`health_check`
*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):
* target
* interval
* timeout
* healthy_threshold
* unhealthy_threshold


#### Type: cloudwatch_alarm

##### `name`
Expand Down
29 changes: 29 additions & 0 deletions lib/puppet/provider/elb_loadbalancer/v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ def self.load_balancer_to_hash(region, load_balancer)
'instance_port' => listener.listener.instance_port,
}
end
health_check = {}
unless load_balancer.health_check.nil?
health_check = {
'healthy_threshold' => load_balancer.health_check.healthy_threshold,
'interval' => load_balancer.health_check.interval,
'target' => load_balancer.health_check.target,
'timeout' => load_balancer.health_check.timeout,
'unhealthy_threshold' => load_balancer.health_check.unhealthy_threshold,
}
end
tag_response = elb_client(region).describe_tags(
load_balancer_names: [load_balancer.load_balancer_name]
)
Expand Down Expand Up @@ -90,6 +100,7 @@ def self.load_balancer_to_hash(region, load_balancer)
subnets: subnet_names,
security_groups: security_group_names,
scheme: load_balancer.scheme,
health_check: health_check,
}
end

Expand Down Expand Up @@ -132,6 +143,10 @@ def create

@property_hash[:ensure] = :present

if ! resource[:health_check].nil?
self.health_check = resource[:health_check]
end

instances = resource[:instances]
if ! instances.nil?
instances = [instances] unless instances.is_a?(Array)
Expand Down Expand Up @@ -231,6 +246,20 @@ def subnets=(value)
end
end

def health_check=(value)
elb = elb_client(resource[:region])
elb.configure_health_check({
load_balancer_name: name,
health_check: {
target: value['target'],
interval: value['interval'],
timeout: value['timeout'],
unhealthy_threshold: value['unhealthy_threshold'],
healthy_threshold: value['healthy_threshold'],
},
})
end

def destroy
Puppet.info("Destroying load balancer #{name} in region #{target_region}")
elb_client(target_region).delete_load_balancer(
Expand Down
14 changes: 14 additions & 0 deletions lib/puppet/type/elb_loadbalancer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@ def insync?(is)
end
end

newproperty(:health_check) do
desc 'Health check.'
def insync?(is)
normalise(is).to_set == normalise(should).to_set
end
def normalise(value)
value.each { |k,v| value[k] = v.to_s }
Hash[value.sort]
end
validate do |value|
fail 'health check should be a Hash' unless value.is_a?(Hash)
end
end

validate do
subnets = self[:subnets]
zones = self[:availability_zones]
Expand Down

0 comments on commit ba49280

Please sign in to comment.