Merge pull request #916 from gosuri/aws-elb-update-issue

fix for #915 - aws_elb.health_check attributes does not update during update
This commit is contained in:
Paul Hinze 2015-02-06 17:14:44 -06:00
commit 6f5234c52f
2 changed files with 69 additions and 1 deletions

View File

@ -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)
}

View File

@ -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
}
}
`