From 04ac1ffd0205bc539dba5b19abcfd3358fe3817e Mon Sep 17 00:00:00 2001 From: Greg Osuri Date: Mon, 2 Feb 2015 19:25:54 -0800 Subject: [PATCH] provider/aws: fix for #915 - aws_elb.health_check attributes does not update during update --- builtin/providers/aws/resource_aws_elb.go | 22 +++++++++ .../providers/aws/resource_aws_elb_test.go | 47 +++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/builtin/providers/aws/resource_aws_elb.go b/builtin/providers/aws/resource_aws_elb.go index 15feae278..bffa1e0a2 100644 --- a/builtin/providers/aws/resource_aws_elb.go +++ b/builtin/providers/aws/resource_aws_elb.go @@ -331,6 +331,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 + } +} +`