diff --git a/builtin/providers/aws/resource_aws_elb.go b/builtin/providers/aws/resource_aws_elb.go index eb05143ab..e84825f52 100644 --- a/builtin/providers/aws/resource_aws_elb.go +++ b/builtin/providers/aws/resource_aws_elb.go @@ -37,10 +37,13 @@ func resourceAwsElb() *schema.Resource { }, "availability_zones": &schema.Schema{ - Type: schema.TypeList, + Type: schema.TypeSet, Elem: &schema.Schema{Type: schema.TypeString}, Optional: true, ForceNew: true, + Set: func(v interface{}) int { + return hashcode.String(v.(string)) + }, }, "instances": &schema.Schema{ @@ -172,7 +175,7 @@ func resourceAwsElbCreate(d *schema.ResourceData, meta interface{}) error { } if v, ok := d.GetOk("availability_zones"); ok { - elbOpts.AvailZone = expandStringList(v.([]interface{})) + elbOpts.AvailZone = expandStringList(v.(*schema.Set).List()) } if v, ok := d.GetOk("security_groups"); ok { @@ -223,8 +226,7 @@ func resourceAwsElbCreate(d *schema.ResourceData, meta interface{}) error { } } } - - + return resourceAwsElbUpdate(d, meta) } @@ -255,6 +257,7 @@ func resourceAwsElbRead(d *schema.ResourceData, meta interface{}) error { d.Set("name", lb.LoadBalancerName) d.Set("dns_name", lb.DNSName) d.Set("internal", lb.Scheme == "internal") + d.Set("availability_zones", flattenAvailabilityZones(lb.AvailabilityZones)) d.Set("instances", flattenInstances(lb.Instances)) d.Set("listener", flattenListeners(lb.Listeners)) d.Set("security_groups", lb.SecurityGroups) @@ -306,25 +309,25 @@ func resourceAwsElbUpdate(d *schema.ResourceData, meta interface{}) error { return fmt.Errorf("Failure deregistering instances: %s", err) } } - + d.SetPartial("instances") } log.Println("[INFO] outside modify attributes") - if d.HasChange("cross_zone_load_balancing") { - log.Println("[INFO] inside modify attributes") - attrs := elb.ModifyLoadBalancerAttributes{ - LoadBalancerName: d.Get("name").(string), - LoadBalancerAttributes: elb.LoadBalancerAttributes{ - CrossZoneLoadBalancingEnabled: d.Get("cross_zone_load_balancing").(bool), - }, - } - _, err := elbconn.ModifyLoadBalancerAttributes(&attrs) - if err != nil { - return fmt.Errorf("Failure configuring health check: %s", err) - } - d.SetPartial("cross_zone_load_balancing") + if d.HasChange("cross_zone_load_balancing") { + log.Println("[INFO] inside modify attributes") + attrs := elb.ModifyLoadBalancerAttributes{ + LoadBalancerName: d.Get("name").(string), + LoadBalancerAttributes: elb.LoadBalancerAttributes{ + CrossZoneLoadBalancingEnabled: d.Get("cross_zone_load_balancing").(bool), + }, } + _, err := elbconn.ModifyLoadBalancerAttributes(&attrs) + if err != nil { + return fmt.Errorf("Failure configuring health check: %s", err) + } + d.SetPartial("cross_zone_load_balancing") + } d.Partial(false) return resourceAwsElbRead(d, meta) diff --git a/builtin/providers/aws/structure.go b/builtin/providers/aws/structure.go index 2e634931b..8b1f7389b 100644 --- a/builtin/providers/aws/structure.go +++ b/builtin/providers/aws/structure.go @@ -172,6 +172,15 @@ func flattenInstances(list []elb.Instance) []string { return result } +// Flattens an array of AvailabilityZones into a []string +func flattenAvailabilityZones(list []elb.AvailabilityZone) []string { + result := make([]string, 0, len(list)) + for _, z := range list { + result = append(result, z.AvailabilityZone) + } + return result +} + // Flattens an array of Listeners into a []map[string]interface{} func flattenListeners(list []elb.Listener) []map[string]interface{} { result := make([]map[string]interface{}, 0, len(list))