diff --git a/builtin/providers/aws/resource_aws_elb.go b/builtin/providers/aws/resource_aws_elb.go index 15feae278..b56d47d87 100644 --- a/builtin/providers/aws/resource_aws_elb.go +++ b/builtin/providers/aws/resource_aws_elb.go @@ -119,7 +119,6 @@ func resourceAwsElb() *schema.Resource { "health_check": &schema.Schema{ Type: schema.TypeSet, Optional: true, - ForceNew: true, Computed: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ @@ -331,6 +330,28 @@ func resourceAwsElbUpdate(d *schema.ResourceData, meta interface{}) error { d.SetPartial("cross_zone_load_balancing") } + if d.HasChange("health_check") { + vs := d.Get("health_check").(*schema.Set).List() + if len(vs) > 0 { + check := vs[0].(map[string]interface{}) + configureHealthCheckOpts := elb.ConfigureHealthCheck{ + LoadBalancerName: d.Id(), + Check: elb.HealthCheck{ + HealthyThreshold: int64(check["healthy_threshold"].(int)), + UnhealthyThreshold: int64(check["unhealthy_threshold"].(int)), + Interval: int64(check["interval"].(int)), + Target: check["target"].(string), + Timeout: int64(check["timeout"].(int)), + }, + } + _, err := elbconn.ConfigureHealthCheck(&configureHealthCheckOpts) + if err != nil { + return fmt.Errorf("Failure configuring health check: %s", err) + } + d.SetPartial("health_check") + } + } + d.Partial(false) return resourceAwsElbRead(d, meta) } diff --git a/builtin/providers/aws/resource_aws_elb_test.go b/builtin/providers/aws/resource_aws_elb_test.go index cb5be7291..50563565b 100644 --- a/builtin/providers/aws/resource_aws_elb_test.go +++ b/builtin/providers/aws/resource_aws_elb_test.go @@ -152,6 +152,31 @@ func TestAccAWSELB_HealthCheck(t *testing.T) { }, }) } + +func TestAccAWSELBUpdate_HealthCheck(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSELBDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccAWSELBConfigHealthCheck, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "aws_elb.bar", "health_check.3484319807.healthy_threshold", "5"), + ), + }, + resource.TestStep{ + Config: testAccAWSELBConfigHealthCheck_update, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "aws_elb.bar", "health_check.2648756019.healthy_threshold", "10"), + ), + }, + }, + }) +} + func testAccCheckAWSELBDestroy(s *terraform.State) error { conn := testAccProvider.Meta().(*AWSClient).elbconn @@ -418,3 +443,25 @@ resource "aws_elb" "bar" { } } ` + +const testAccAWSELBConfigHealthCheck_update = ` +resource "aws_elb" "bar" { + name = "foobar-terraform-test" + availability_zones = ["us-west-2a"] + + listener { + instance_port = 8000 + instance_protocol = "http" + lb_port = 80 + lb_protocol = "http" + } + + health_check { + healthy_threshold = 10 + unhealthy_threshold = 5 + target = "HTTP:8000/" + interval = 60 + timeout = 30 + } +} +`