providers/aws: availability_zones and expandList

This commit is contained in:
Jack Pearkes 2014-07-02 16:57:57 -07:00
parent 1b6faa0eb9
commit 0f64ff9387
3 changed files with 35 additions and 5 deletions

View File

@ -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 ",
},
}

View File

@ -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
}

View File

@ -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)
}
}