providers/aws: expand wildcard string lists

This commit is contained in:
Jack Pearkes 2014-07-16 18:51:50 -04:00
parent 9ec1990608
commit 901785d04a
2 changed files with 26 additions and 0 deletions

View File

@ -1,6 +1,8 @@
package aws
import (
"strings"
"github.com/mitchellh/goamz/autoscaling"
"github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/goamz/elb"
@ -134,6 +136,14 @@ func flattenInstances(list []elb.Instance) []string {
// Takes the result of flatmap.Expand for an array of strings
// and returns a []string
func expandStringList(configured []interface{}) []string {
// here we special case the * expanded lists. For example:
//
// instances = ["${aws_instance.foo.*.id}"]
//
if len(configured) == 1 && strings.Contains(configured[0].(string), ",") {
return strings.Split(configured[0].(string), ",")
}
vs := make([]string, 0, len(configured))
for _, v := range configured {
vs = append(vs, v.(string))

View File

@ -90,3 +90,19 @@ func Test_expandStringList(t *testing.T) {
}
}
func Test_expandStringListWildcard(t *testing.T) {
stringList := expandStringList([]interface{}{"us-east-1a,us-east-1b"})
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)
}
}