diff --git a/README.md b/README.md index 0924786a..33284f13 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/lib/puppet/provider/elb_loadbalancer/v2.rb b/lib/puppet/provider/elb_loadbalancer/v2.rb index a2fd7474..4b91df08 100644 --- a/lib/puppet/provider/elb_loadbalancer/v2.rb +++ b/lib/puppet/provider/elb_loadbalancer/v2.rb @@ -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] ) @@ -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 @@ -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) @@ -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( diff --git a/lib/puppet/type/elb_loadbalancer.rb b/lib/puppet/type/elb_loadbalancer.rb index 8d64b761..3652b8d7 100644 --- a/lib/puppet/type/elb_loadbalancer.rb +++ b/lib/puppet/type/elb_loadbalancer.rb @@ -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]