Skip to content

Commit

Permalink
Updating the tests and refactoring the code a little
Browse files Browse the repository at this point in the history
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…
  • Loading branch information
Sander van Harmelen committed Dec 16, 2014
1 parent 462cc24 commit 9797881
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion builtin/providers/aws/resource_aws_elb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 10 additions & 5 deletions builtin/providers/aws/resource_aws_elb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"reflect"
"sort"
"testing"

"github.com/hashicorp/terraform/helper/resource"
Expand All @@ -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(
Expand Down Expand Up @@ -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")
}

Expand Down Expand Up @@ -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")
}

Expand Down
9 changes: 0 additions & 9 deletions builtin/providers/aws/structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 9797881

Please sign in to comment.