Updating the tests and refactoring the code a little

There was an error in the goamz package the prevented updating the
availability zones correctly. So PR #181 should be merged before this
one can be merged…
This commit is contained in:
Sander van Harmelen 2014-12-16 15:21:25 +01:00
parent 462cc24ce6
commit 9797881ed8
3 changed files with 11 additions and 15 deletions

View File

@ -257,7 +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("availability_zones", lb.AvailabilityZones)
d.Set("instances", flattenInstances(lb.Instances))
d.Set("listener", flattenListeners(lb.Listeners))
d.Set("security_groups", lb.SecurityGroups)

View File

@ -4,6 +4,7 @@ import (
"fmt"
"os"
"reflect"
"sort"
"testing"
"github.com/hashicorp/terraform/helper/resource"
@ -28,11 +29,11 @@ func TestAccAWSELB_basic(t *testing.T) {
resource.TestCheckResourceAttr(
"aws_elb.bar", "name", "foobar-terraform-test"),
resource.TestCheckResourceAttr(
"aws_elb.bar", "availability_zones.0", "us-west-2a"),
"aws_elb.bar", "availability_zones.2487133097", "us-west-2a"),
resource.TestCheckResourceAttr(
"aws_elb.bar", "availability_zones.1", "us-west-2b"),
"aws_elb.bar", "availability_zones.221770259", "us-west-2b"),
resource.TestCheckResourceAttr(
"aws_elb.bar", "availability_zones.2", "us-west-2c"),
"aws_elb.bar", "availability_zones.2050015877", "us-west-2c"),
resource.TestCheckResourceAttr(
"aws_elb.bar", "listener.206423021.instance_port", "8000"),
resource.TestCheckResourceAttr(
@ -150,7 +151,9 @@ func testAccCheckAWSELBDestroy(s *terraform.State) error {
func testAccCheckAWSELBAttributes(conf *elb.LoadBalancer) resource.TestCheckFunc {
return func(s *terraform.State) error {
if conf.AvailabilityZones[0].AvailabilityZone != "us-west-2a" {
zones := []string{"us-west-2a", "us-west-2b", "us-west-2c"}
sort.StringSlice(conf.AvailabilityZones).Sort()
if !reflect.DeepEqual(conf.AvailabilityZones, zones) {
return fmt.Errorf("bad availability_zones")
}
@ -182,7 +185,9 @@ func testAccCheckAWSELBAttributes(conf *elb.LoadBalancer) resource.TestCheckFunc
func testAccCheckAWSELBAttributesHealthCheck(conf *elb.LoadBalancer) resource.TestCheckFunc {
return func(s *terraform.State) error {
if conf.AvailabilityZones[0].AvailabilityZone != "us-west-2a" {
zones := []string{"us-west-2a", "us-west-2b", "us-west-2c"}
sort.StringSlice(conf.AvailabilityZones).Sort()
if !reflect.DeepEqual(conf.AvailabilityZones, zones) {
return fmt.Errorf("bad availability_zones")
}

View File

@ -172,15 +172,6 @@ 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))