diff --git a/builtin/providers/aws/resource_aws_elb.go b/builtin/providers/aws/resource_aws_elb.go index 3128f8a76..e7c2caba5 100644 --- a/builtin/providers/aws/resource_aws_elb.go +++ b/builtin/providers/aws/resource_aws_elb.go @@ -30,14 +30,14 @@ func resource_aws_elb_create( v := flatmap.Expand(rs.Attributes, "listener").([]interface{}) listeners := expandListeners(v) + v = flatmap.Expand(rs.Attributes, "availability_zones").([]interface{}) + zones := expandStringList(v) + // Provision the elb elbOpts := &elb.CreateLoadBalancer{ LoadBalancerName: elbName, Listeners: listeners, - AvailZone: []string{ - "us-east-1a", - "us-east-1b", - }, + AvailZone: zones, } log.Printf("[DEBUG] ELB create configuration: %#v", elbOpts) @@ -103,7 +103,7 @@ func resource_aws_elb_diff( ComputedAttrs: []string{ "dns_name", - "instances", + "instances ", }, } diff --git a/builtin/providers/aws/structure.go b/builtin/providers/aws/structure.go index 44ab80519..0f2b4800a 100644 --- a/builtin/providers/aws/structure.go +++ b/builtin/providers/aws/structure.go @@ -26,3 +26,13 @@ func expandListeners(configured []interface{}) []elb.Listener { return listeners } + +// Takes the result of flatmap.Expand for an array of strings +// and returns a []string +func expandStringList(configured []interface{}) []string { + vs := make([]string, 0, len(configured)) + for _, v := range configured { + vs = append(vs, v.(string)) + } + return vs +} diff --git a/builtin/providers/aws/structure_test.go b/builtin/providers/aws/structure_test.go index 28283a676..d534e4c24 100644 --- a/builtin/providers/aws/structure_test.go +++ b/builtin/providers/aws/structure_test.go @@ -16,6 +16,9 @@ func testConf() map[string]string { "listener.0.lb_protocol": "http", "listener.0.instance_port": "8000", "listener.0.instance_protocol": "http", + "availability_zones.#": "2", + "availability_zones.0": "us-east-1a", + "availability_zones.1": "us-east-1b", } } @@ -37,3 +40,20 @@ func Test_expandListeners(t *testing.T) { } } + +func Test_expandStringList(t *testing.T) { + expanded := flatmap.Expand(testConf(), "availability_zones").([]interface{}) + stringList := expandStringList(expanded) + expected := []string{ + "us-east-1a", + "us-east-1b", + } + + if !reflect.DeepEqual(stringList, expected) { + t.Fatalf( + "Got:\n\n%#v\n\nExpected:\n\n%#v\n", + stringList, + expected) + } + +}