From 62e19f18b087ec5efc3c2cb3ce00c570f3368f76 Mon Sep 17 00:00:00 2001 From: Daniel Lin Date: Tue, 9 Apr 2013 14:10:58 -0700 Subject: [PATCH] Make ELB health checks configurable from recipes. Adds an 'health_check' attribute to the ELB resource provider to configure ELB health checks in a recipe. --- README.md | 13 +++++++++++++ providers/load_balancer.rb | 15 +++++++++++++++ resources/load_balancer.rb | 3 ++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1371a39..a4ed113 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,19 @@ search: action :create end +You can configure the `health check` parameters from the defaults by specifying +the `health_check` attribute with a hash: + + elb_load_balancer "ap-tcp-frontend" do + aws_access_key aws['aws_access_key_id'] + aws_secret_access_key aws['aws_secret_access_key'] + instances ['i-xxxxx', 'i-xxxxx'] + region 'ap-southeast-1' + listeners [{"InstancePort" => 1234, "Protocol" => "TCP", "LoadBalancerPort" => 1234}] + health_check [{"HealthyThreshold" => 10, "Interval" => 30, "Target" => "HTTP:80/ping", "Timeout" => 5, "UnhealthyThreshold" =>2}] + action :create + end + You can also do SSL, but it's a little funky. First, you have to [upload your cert](http://docs.amazonwebservices.com/ElasticLoadBalancing/latest/DeveloperGuide/index.html?US_SettingUpLoadBalancerHTTPSIntegrated.html). diff --git a/providers/load_balancer.rb b/providers/load_balancer.rb index aa92ec3..12533b8 100644 --- a/providers/load_balancer.rb +++ b/providers/load_balancer.rb @@ -67,6 +67,21 @@ def load_current_resource end new_resource.updated_by_last_action(true) + configure_successful = false + ruby_block "Configure ELB #{new_resource.lb_name}" do + block do + response = elb.configure_health_check(new_resource.lb_name, new_resource.health_check.first) + if response.status != 200 + Chef::Log::fatal!("Configuring load balancer health check returned " << response.status.to_s) + else + Chef::Log::debug("Configure load balancer health check succeeded: \n" << response.body.to_s) + configure_successful = true + end + end + action :create + end + new_resource.updated_by_last_action(configure_successful) + instances_to_add = new_resource.instances - current_resource.instances instances_to_delete = current_resource.instances - new_resource.instances diff --git a/resources/load_balancer.rb b/resources/load_balancer.rb index 3ac25be..45b8ead 100644 --- a/resources/load_balancer.rb +++ b/resources/load_balancer.rb @@ -8,4 +8,5 @@ attribute :listeners, :kind_of => Array, :default => [{"InstancePort" => 80, "Protocol" => "HTTP", "LoadBalancerPort" => 80}] attribute :instances, :kind_of => Array attribute :search_query, :kind_of => String -attribute :timeout, :default => 60 \ No newline at end of file +attribute :timeout, :default => 60 +attribute :health_check, :kind_of => Array, :default => [{"HealthyThreshold" => 10, "Interval" => 30, "Target" => "HTTP:80/", "Timeout" => 5, "UnhealthyThreshold" => 2}]