@@ -134,30 +134,37 @@ func parseVariable(val interface{}, varType string) hilast.Variable {
134134 case HCL_LIST_VARTYPE :
135135 s := reflect .ValueOf (val )
136136
137- switch reflect .TypeOf (s .Index (0 ).Interface ()).Kind () {
138- case reflect .Map :
139- var variables map [string ]hilast.Variable
140- variables = map [string ]hilast.Variable {}
141- for i := 0 ; i < s .Len (); i ++ {
142- ms := reflect .ValueOf (s .Index (i ).Interface ())
143- for _ , k := range ms .MapKeys () {
144- key := k .Interface ().(string )
145- value := ms .MapIndex (reflect .ValueOf (key )).Interface ()
146- variables [key ] = parseVariable (value , "" )
147- }
148- }
149- hilVar = hilast.Variable {
150- Type : hilast .TypeMap ,
151- Value : variables ,
152- }
153- default :
154- var variables []hilast.Variable
155- for i := 0 ; i < s .Len (); i ++ {
156- variables = append (variables , parseVariable (s .Index (i ).Interface (), "" ))
157- }
137+ if s .Len () == 0 {
158138 hilVar = hilast.Variable {
159139 Type : hilast .TypeList ,
160- Value : variables ,
140+ Value : []hilast.Variable {},
141+ }
142+ } else {
143+ switch reflect .TypeOf (s .Index (0 ).Interface ()).Kind () {
144+ case reflect .Map :
145+ var variables map [string ]hilast.Variable
146+ variables = map [string ]hilast.Variable {}
147+ for i := 0 ; i < s .Len (); i ++ {
148+ ms := reflect .ValueOf (s .Index (i ).Interface ())
149+ for _ , k := range ms .MapKeys () {
150+ key := k .Interface ().(string )
151+ value := ms .MapIndex (reflect .ValueOf (key )).Interface ()
152+ variables [key ] = parseVariable (value , "" )
153+ }
154+ }
155+ hilVar = hilast.Variable {
156+ Type : hilast .TypeMap ,
157+ Value : variables ,
158+ }
159+ default :
160+ var variables []hilast.Variable
161+ for i := 0 ; i < s .Len (); i ++ {
162+ variables = append (variables , parseVariable (s .Index (i ).Interface (), "" ))
163+ }
164+ hilVar = hilast.Variable {
165+ Type : hilast .TypeList ,
166+ Value : variables ,
167+ }
161168 }
162169 }
163170 }
0 commit comments