diff --git a/config/interpolate_funcs.go b/config/interpolate_funcs.go index 03bf070b2..fbbe441ed 100644 --- a/config/interpolate_funcs.go +++ b/config/interpolate_funcs.go @@ -54,7 +54,7 @@ func interpolationFuncConcat() ast.Function { continue } - if strings.Contains(argument, InterpSplitDelim) { + if IsStringList(argument) { isDeprecated = false } @@ -68,7 +68,7 @@ func interpolationFuncConcat() ast.Function { return b.String(), nil } - return strings.Join(finalList, InterpSplitDelim), nil + return NewStringList(finalList).String(), nil }, } } diff --git a/config/interpolate_funcs_test.go b/config/interpolate_funcs_test.go index 488aed91c..dc6c93339 100644 --- a/config/interpolate_funcs_test.go +++ b/config/interpolate_funcs_test.go @@ -5,7 +5,6 @@ import ( "io/ioutil" "os" "reflect" - "strings" "testing" "github.com/hashicorp/terraform/config/lang" @@ -42,74 +41,46 @@ func TestInterpolateFuncConcat(t *testing.T) { // String + list { `${concat("a", split(",", "b,c"))}`, - fmt.Sprintf( - "%s%s%s%s%s", - "a", - InterpSplitDelim, - "b", - InterpSplitDelim, - "c"), + NewStringList([]string{"a", "b", "c"}).String(), false, }, // List + string { `${concat(split(",", "a,b"), "c")}`, - fmt.Sprintf( - "%s%s%s%s%s", - "a", - InterpSplitDelim, - "b", - InterpSplitDelim, - "c"), + NewStringList([]string{"a", "b", "c"}).String(), false, }, // Single list { `${concat(split(",", ",foo,"))}`, - fmt.Sprintf( - "%s%s%s", - InterpSplitDelim, - "foo", - InterpSplitDelim), + NewStringList([]string{"", "foo", ""}).String(), false, }, { `${concat(split(",", "a,b,c"))}`, - fmt.Sprintf( - "%s%s%s%s%s", - "a", - InterpSplitDelim, - "b", - InterpSplitDelim, - "c"), + NewStringList([]string{"a", "b", "c"}).String(), false, }, // Two lists { `${concat(split(",", "a,b,c"), split(",", "d,e"))}`, - strings.Join([]string{ - "a", "b", "c", "d", "e", - }, InterpSplitDelim), + NewStringList([]string{"a", "b", "c", "d", "e"}).String(), false, }, // Two lists with different separators { `${concat(split(",", "a,b,c"), split(" ", "d e"))}`, - strings.Join([]string{ - "a", "b", "c", "d", "e", - }, InterpSplitDelim), + NewStringList([]string{"a", "b", "c", "d", "e"}).String(), false, }, // More lists { `${concat(split(",", "a,b"), split(",", "c,d"), split(",", "e,f"), split(",", "0,1"))}`, - strings.Join([]string{ - "a", "b", "c", "d", "e", "f", "0", "1", - }, InterpSplitDelim), + NewStringList([]string{"a", "b", "c", "d", "e", "f", "0", "1"}).String(), false, }, }, @@ -204,7 +175,7 @@ func TestInterpolateFuncFormatList(t *testing.T) { // formatlist applies to each list element in turn { `${formatlist("<%s>", split(",", "A,B"))}`, - "" + StringListDelim + "", + NewStringList([]string{"", ""}).String(), false, }, // formatlist repeats scalar elements @@ -266,10 +237,7 @@ func TestInterpolateFuncJoin(t *testing.T) { { fmt.Sprintf(`${join(".", "%s")}`, - fmt.Sprintf( - "foo%sbar%sbaz", - StringListDelim, - StringListDelim)), + NewStringList([]string{"foo", "bar", "baz"}).String()), "foo.bar.baz", false, }, @@ -394,39 +362,25 @@ func TestInterpolateFuncSplit(t *testing.T) { { `${split(",", ",,,")}`, - fmt.Sprintf( - "%s%s%s", - StringListDelim, - StringListDelim, - StringListDelim), + NewStringList([]string{"", "", "", ""}).String(), false, }, { `${split(",", "foo,")}`, - fmt.Sprintf( - "%s%s", - "foo", - StringListDelim), + NewStringList([]string{"foo", ""}).String(), false, }, { `${split(",", ",foo,")}`, - fmt.Sprintf( - "%s%s%s", - StringListDelim, - "foo", - StringListDelim), + NewStringList([]string{"", "foo", ""}).String(), false, }, { `${split(".", "foo.bar.baz")}`, - fmt.Sprintf( - "foo%sbar%sbaz", - StringListDelim, - StringListDelim), + NewStringList([]string{"foo", "bar", "baz"}).String(), false, }, }, @@ -484,9 +438,7 @@ func TestInterpolateFuncKeys(t *testing.T) { Cases: []testFunctionCase{ { `${keys("foo")}`, - fmt.Sprintf( - "bar%squx", - StringListDelim), + NewStringList([]string{"bar", "qux"}).String(), false, }, @@ -533,9 +485,7 @@ func TestInterpolateFuncValues(t *testing.T) { Cases: []testFunctionCase{ { `${values("foo")}`, - fmt.Sprintf( - "quack%sbaz", - StringListDelim), + NewStringList([]string{"quack", "baz"}).String(), false, }, @@ -568,7 +518,7 @@ func TestInterpolateFuncElement(t *testing.T) { Cases: []testFunctionCase{ { fmt.Sprintf(`${element("%s", "1")}`, - "foo"+StringListDelim+"baz"), + NewStringList([]string{"foo", "baz"}).String()), "baz", false, }, @@ -582,7 +532,7 @@ func TestInterpolateFuncElement(t *testing.T) { // Invalid index should wrap vs. out-of-bounds { fmt.Sprintf(`${element("%s", "2")}`, - "foo"+StringListDelim+"baz"), + NewStringList([]string{"foo", "baz"}).String()), "foo", false, }, @@ -590,7 +540,7 @@ func TestInterpolateFuncElement(t *testing.T) { // Too many args { fmt.Sprintf(`${element("%s", "0", "2")}`, - "foo"+StringListDelim+"baz"), + NewStringList([]string{"foo", "baz"}).String()), nil, true, }, diff --git a/config/interpolate_walk_test.go b/config/interpolate_walk_test.go index 5155001e0..bc17dbddd 100644 --- a/config/interpolate_walk_test.go +++ b/config/interpolate_walk_test.go @@ -157,7 +157,7 @@ func TestInterpolationWalker_replace(t *testing.T) { "bing", }, }, - Value: "bar" + StringListDelim + "baz", + Value: NewStringList([]string{"bar", "baz"}).String(), }, { @@ -168,7 +168,7 @@ func TestInterpolationWalker_replace(t *testing.T) { }, }, Output: map[string]interface{}{}, - Value: UnknownVariableValue + StringListDelim + "baz", + Value: NewStringList([]string{UnknownVariableValue, "baz"}).String(), }, } diff --git a/helper/schema/schema_test.go b/helper/schema/schema_test.go index 2f7c259a5..bf5a3a19b 100644 --- a/helper/schema/schema_test.go +++ b/helper/schema/schema_test.go @@ -582,7 +582,7 @@ func TestSchemaMap_Diff(t *testing.T) { }, ConfigVariables: map[string]string{ - "var.foo": "2" + config.StringListDelim + "5", + "var.foo": config.NewStringList([]string{"2", "5"}).String(), }, Diff: &terraform.InstanceDiff{ @@ -626,8 +626,8 @@ func TestSchemaMap_Diff(t *testing.T) { }, ConfigVariables: map[string]string{ - "var.foo": config.UnknownVariableValue + - config.StringListDelim + "5", + "var.foo": config.NewStringList([]string{ + config.UnknownVariableValue, "5"}).String(), }, Diff: &terraform.InstanceDiff{ @@ -905,7 +905,7 @@ func TestSchemaMap_Diff(t *testing.T) { }, ConfigVariables: map[string]string{ - "var.foo": "2" + config.StringListDelim + "5", + "var.foo": config.NewStringList([]string{"2", "5"}).String(), }, Diff: &terraform.InstanceDiff{ @@ -952,8 +952,8 @@ func TestSchemaMap_Diff(t *testing.T) { }, ConfigVariables: map[string]string{ - "var.foo": config.UnknownVariableValue + - config.StringListDelim + "5", + "var.foo": config.NewStringList([]string{ + config.UnknownVariableValue, "5"}).String(), }, Diff: &terraform.InstanceDiff{