Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider/aws: Change ELB health_check to list type #5066

Merged
merged 1 commit into from
Feb 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 7 additions & 17 deletions builtin/providers/aws/resource_aws_elb.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func resourceAwsElb() *schema.Resource {
},

"health_check": &schema.Schema{
Type: schema.TypeSet,
Type: schema.TypeList,
Optional: true,
Computed: true,
Elem: &schema.Resource{
Expand Down Expand Up @@ -194,7 +194,6 @@ func resourceAwsElb() *schema.Resource {
},
},
},
Set: resourceAwsElbHealthCheckHash,
},

"dns_name": &schema.Schema{
Expand Down Expand Up @@ -374,6 +373,7 @@ func resourceAwsElbRead(d *schema.ResourceData, meta interface{}) error {
et = resp.TagDescriptions[0].Tags
}
d.Set("tags", tagsToMapELB(et))

// There's only one health check, so save that to state as we
// currently can
if *lb.HealthCheck.Target != "" {
Expand Down Expand Up @@ -574,9 +574,11 @@ func resourceAwsElbUpdate(d *schema.ResourceData, meta interface{}) error {
}

if d.HasChange("health_check") {
vs := d.Get("health_check").(*schema.Set).List()
if len(vs) > 0 {
check := vs[0].(map[string]interface{})
hc := d.Get("health_check").([]interface{})
if len(hc) > 1 {
return fmt.Errorf("Only one health check per ELB is supported")
} else if len(hc) > 0 {
check := hc[0].(map[string]interface{})
configureHealthCheckOpts := elb.ConfigureHealthCheckInput{
LoadBalancerName: aws.String(d.Id()),
HealthCheck: &elb.HealthCheck{
Expand Down Expand Up @@ -711,18 +713,6 @@ func resourceAwsElbDelete(d *schema.ResourceData, meta interface{}) error {
return nil
}

func resourceAwsElbHealthCheckHash(v interface{}) int {
var buf bytes.Buffer
m := v.(map[string]interface{})
buf.WriteString(fmt.Sprintf("%d-", m["healthy_threshold"].(int)))
buf.WriteString(fmt.Sprintf("%d-", m["unhealthy_threshold"].(int)))
buf.WriteString(fmt.Sprintf("%s-", m["target"].(string)))
buf.WriteString(fmt.Sprintf("%d-", m["interval"].(int)))
buf.WriteString(fmt.Sprintf("%d-", m["timeout"].(int)))

return hashcode.String(buf.String())
}

func resourceAwsElbAccessLogsHash(v interface{}) int {
var buf bytes.Buffer
m := v.(map[string]interface{})
Expand Down
14 changes: 7 additions & 7 deletions builtin/providers/aws/resource_aws_elb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,15 +339,15 @@ func TestAccAWSELB_HealthCheck(t *testing.T) {
testAccCheckAWSELBExists("aws_elb.bar", &conf),
testAccCheckAWSELBAttributesHealthCheck(&conf),
resource.TestCheckResourceAttr(
"aws_elb.bar", "health_check.3484319807.healthy_threshold", "5"),
"aws_elb.bar", "health_check.0.healthy_threshold", "5"),
resource.TestCheckResourceAttr(
"aws_elb.bar", "health_check.3484319807.unhealthy_threshold", "5"),
"aws_elb.bar", "health_check.0.unhealthy_threshold", "5"),
resource.TestCheckResourceAttr(
"aws_elb.bar", "health_check.3484319807.target", "HTTP:8000/"),
"aws_elb.bar", "health_check.0.target", "HTTP:8000/"),
resource.TestCheckResourceAttr(
"aws_elb.bar", "health_check.3484319807.timeout", "30"),
"aws_elb.bar", "health_check.0.timeout", "30"),
resource.TestCheckResourceAttr(
"aws_elb.bar", "health_check.3484319807.interval", "60"),
"aws_elb.bar", "health_check.0.interval", "60"),
),
},
},
Expand All @@ -364,14 +364,14 @@ func TestAccAWSELBUpdate_HealthCheck(t *testing.T) {
Config: testAccAWSELBConfigHealthCheck,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"aws_elb.bar", "health_check.3484319807.healthy_threshold", "5"),
"aws_elb.bar", "health_check.0.healthy_threshold", "5"),
),
},
resource.TestStep{
Config: testAccAWSELBConfigHealthCheck_update,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"aws_elb.bar", "health_check.2648756019.healthy_threshold", "10"),
"aws_elb.bar", "health_check.0.healthy_threshold", "10"),
),
},
},
Expand Down