Merge pull request #5066 from tpounds/fix-aws-elb-health-check-type

provider/aws: Change ELB health_check to list type
This commit is contained in:
Paul Stack 2016-02-21 22:38:10 +00:00
commit 1e7f10d3a3
2 changed files with 14 additions and 24 deletions

View File

@ -163,7 +163,7 @@ func resourceAwsElb() *schema.Resource {
}, },
"health_check": &schema.Schema{ "health_check": &schema.Schema{
Type: schema.TypeSet, Type: schema.TypeList,
Optional: true, Optional: true,
Computed: true, Computed: true,
Elem: &schema.Resource{ Elem: &schema.Resource{
@ -194,7 +194,6 @@ func resourceAwsElb() *schema.Resource {
}, },
}, },
}, },
Set: resourceAwsElbHealthCheckHash,
}, },
"dns_name": &schema.Schema{ "dns_name": &schema.Schema{
@ -374,6 +373,7 @@ func resourceAwsElbRead(d *schema.ResourceData, meta interface{}) error {
et = resp.TagDescriptions[0].Tags et = resp.TagDescriptions[0].Tags
} }
d.Set("tags", tagsToMapELB(et)) d.Set("tags", tagsToMapELB(et))
// There's only one health check, so save that to state as we // There's only one health check, so save that to state as we
// currently can // currently can
if *lb.HealthCheck.Target != "" { if *lb.HealthCheck.Target != "" {
@ -574,9 +574,11 @@ func resourceAwsElbUpdate(d *schema.ResourceData, meta interface{}) error {
} }
if d.HasChange("health_check") { if d.HasChange("health_check") {
vs := d.Get("health_check").(*schema.Set).List() hc := d.Get("health_check").([]interface{})
if len(vs) > 0 { if len(hc) > 1 {
check := vs[0].(map[string]interface{}) 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{ configureHealthCheckOpts := elb.ConfigureHealthCheckInput{
LoadBalancerName: aws.String(d.Id()), LoadBalancerName: aws.String(d.Id()),
HealthCheck: &elb.HealthCheck{ HealthCheck: &elb.HealthCheck{
@ -711,18 +713,6 @@ func resourceAwsElbDelete(d *schema.ResourceData, meta interface{}) error {
return nil 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 { func resourceAwsElbAccessLogsHash(v interface{}) int {
var buf bytes.Buffer var buf bytes.Buffer
m := v.(map[string]interface{}) m := v.(map[string]interface{})

View File

@ -339,15 +339,15 @@ func TestAccAWSELB_HealthCheck(t *testing.T) {
testAccCheckAWSELBExists("aws_elb.bar", &conf), testAccCheckAWSELBExists("aws_elb.bar", &conf),
testAccCheckAWSELBAttributesHealthCheck(&conf), testAccCheckAWSELBAttributesHealthCheck(&conf),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"aws_elb.bar", "health_check.3484319807.healthy_threshold", "5"), "aws_elb.bar", "health_check.0.healthy_threshold", "5"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"aws_elb.bar", "health_check.3484319807.unhealthy_threshold", "5"), "aws_elb.bar", "health_check.0.unhealthy_threshold", "5"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"aws_elb.bar", "health_check.3484319807.target", "HTTP:8000/"), "aws_elb.bar", "health_check.0.target", "HTTP:8000/"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"aws_elb.bar", "health_check.3484319807.timeout", "30"), "aws_elb.bar", "health_check.0.timeout", "30"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"aws_elb.bar", "health_check.3484319807.interval", "60"), "aws_elb.bar", "health_check.0.interval", "60"),
), ),
}, },
}, },
@ -364,14 +364,14 @@ func TestAccAWSELBUpdate_HealthCheck(t *testing.T) {
Config: testAccAWSELBConfigHealthCheck, Config: testAccAWSELBConfigHealthCheck,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"aws_elb.bar", "health_check.3484319807.healthy_threshold", "5"), "aws_elb.bar", "health_check.0.healthy_threshold", "5"),
), ),
}, },
resource.TestStep{ resource.TestStep{
Config: testAccAWSELBConfigHealthCheck_update, Config: testAccAWSELBConfigHealthCheck_update,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"aws_elb.bar", "health_check.2648756019.healthy_threshold", "10"), "aws_elb.bar", "health_check.0.healthy_threshold", "10"),
), ),
}, },
}, },