helper/schema: test schema diffs with the interpolation splits

This commit is contained in:
Mitchell Hashimoto 2014-10-09 16:31:24 -07:00
parent 865ec6a6bf
commit 3aa655ad3b
2 changed files with 43 additions and 8 deletions

View File

@ -188,14 +188,6 @@ 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

@ -385,6 +385,49 @@ func TestSchemaMap_Diff(t *testing.T) {
Err: false,
},
{
Schema: map[string]*Schema{
"ports": &Schema{
Type: TypeList,
Required: true,
Elem: &Schema{Type: TypeInt},
},
},
State: nil,
Config: map[string]interface{}{
"ports": []interface{}{1, "${var.foo}"},
},
ConfigVariables: map[string]string{
"var.foo": "2" + config.InterpSplitDelim + "5",
},
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"ports.#": &terraform.ResourceAttrDiff{
Old: "0",
New: "3",
},
"ports.0": &terraform.ResourceAttrDiff{
Old: "",
New: "1",
},
"ports.1": &terraform.ResourceAttrDiff{
Old: "",
New: "2",
},
"ports.2": &terraform.ResourceAttrDiff{
Old: "",
New: "5",
},
},
},
Err: false,
},
{
Schema: map[string]*Schema{
"ports": &Schema{