File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -240,12 +240,18 @@ func interpolationFuncConcat() ast.Function {
240240 // Otherwise variables
241241 if argument , ok := arg .([]ast.Variable ); ok {
242242 for _ , element := range argument {
243- finalListElements = append (finalListElements , element .Value .(string ))
243+ t := element .Type
244+ switch t {
245+ case ast .TypeString :
246+ finalListElements = append (finalListElements , element .Value .(string ))
247+ default :
248+ return nil , fmt .Errorf ("concat() does not support lists of %s" , t .Printable ())
249+ }
244250 }
245251 continue
246252 }
247253
248- return nil , fmt .Errorf ("arguments to concat() must be a string or list" )
254+ return nil , fmt .Errorf ("arguments to concat() must be a string or list of strings " )
249255 }
250256
251257 return stringSliceToVariableValue (finalListElements ), nil
Original file line number Diff line number Diff line change 55 "io/ioutil"
66 "os"
77 "reflect"
8+ "strings"
89 "testing"
910
1011 "github.com/hashicorp/hil"
@@ -226,6 +227,40 @@ func TestInterpolateFuncConcat(t *testing.T) {
226227 })
227228}
228229
230+ // TODO: This test is split out and calls a private function
231+ // because there's no good way to get a list of maps into the unit
232+ // tests due to GH-7142 - once lists of maps can be expressed properly as
233+ // literals this unit test can be wrapped back into the suite above.
234+ //
235+ // Reproduces crash reported in GH-7030.
236+ func TestInterpolationFuncConcatListOfMaps (t * testing.T ) {
237+ listOfMapsOne := ast.Variable {
238+ Type : ast .TypeList ,
239+ Value : []ast.Variable {
240+ {
241+ Type : ast .TypeMap ,
242+ Value : map [string ]interface {}{"one" : "foo" },
243+ },
244+ },
245+ }
246+ listOfMapsTwo := ast.Variable {
247+ Type : ast .TypeList ,
248+ Value : []ast.Variable {
249+ {
250+ Type : ast .TypeMap ,
251+ Value : map [string ]interface {}{"two" : "bar" },
252+ },
253+ },
254+ }
255+ args := []interface {}{listOfMapsOne .Value , listOfMapsTwo .Value }
256+
257+ _ , err := interpolationFuncConcat ().Callback (args )
258+
259+ if err == nil || ! strings .Contains (err .Error (), "concat() does not support lists of type map" ) {
260+ t .Fatalf ("Expected err, got: %v" , err )
261+ }
262+ }
263+
229264func TestInterpolateFuncFile (t * testing.T ) {
230265 tf , err := ioutil .TempFile ("" , "tf" )
231266 if err != nil {
You can’t perform that action at this time.
0 commit comments