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

#214 Add the ability to configure health check params #267

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
31 changes: 30 additions & 1 deletion 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 @@ -141,6 +152,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 @@ -243,7 +258,21 @@ def subnets=(value)
def flush
update unless @property_hash[:ensure] == :absent
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