@@ -317,16 +317,18 @@ func (c *Context) Input(mode InputMode) error {
317317 }
318318 }
319319
320+ var valueType config.VariableType
321+
320322 v := m [n ]
321- switch v .Type () {
323+ switch valueType = v .Type (); valueType {
322324 case config .VariableTypeUnknown :
323325 continue
324326 case config .VariableTypeMap :
325- continue
327+ // OK
326328 case config .VariableTypeList :
327- continue
329+ // OK
328330 case config .VariableTypeString :
329- // Good!
331+ // OK
330332 default :
331333 panic (fmt .Sprintf ("Unknown variable type: %#v" , v .Type ()))
332334 }
@@ -340,6 +342,12 @@ func (c *Context) Input(mode InputMode) error {
340342 }
341343 }
342344
345+ // this should only happen during tests
346+ if c .uiInput == nil {
347+ log .Println ("[WARN] Content.uiInput is nil" )
348+ continue
349+ }
350+
343351 // Ask the user for a value for this variable
344352 var value string
345353 retry := 0
@@ -355,27 +363,33 @@ func (c *Context) Input(mode InputMode) error {
355363 "Error asking for %s: %s" , n , err )
356364 }
357365
358- if value == "" && v .Required () {
359- // Redo if it is required, but abort if we keep getting
360- // blank entries
361- if retry > 2 {
362- return fmt .Errorf ("missing required value for %q" , n )
363- }
364- retry ++
365- continue
366- }
367-
368366 if value == "" {
369- // No value, just exit the loop. With no value, we just
370- // use whatever is currently set in variables.
371- break
367+ if v .Required () {
368+ // Redo if it is required, but abort if we keep getting
369+ // blank entries
370+ if retry > 2 {
371+ return fmt .Errorf ("missing required value for %q" , n )
372+ }
373+ retry ++
374+ continue
375+ }
372376 }
373377
374378 break
375379 }
376380
377- if value != "" {
378- c .variables [n ] = value
381+ // no value provided, so don't set the variable at all
382+ if value == "" {
383+ continue
384+ }
385+
386+ decoded , err := parseVariableAsHCL (n , value , valueType )
387+ if err != nil {
388+ return err
389+ }
390+
391+ if decoded != nil {
392+ c .variables [n ] = decoded
379393 }
380394 }
381395 }
@@ -656,9 +670,20 @@ func (c *Context) walk(
656670// the name of the variable. In order to get around the restriction of HCL requiring a
657671// top level object, we prepend a sentinel key, decode the user-specified value as its
658672// value and pull the value back out of the resulting map.
659- func parseVariableAsHCL (name string , input interface {}, targetType config.VariableType ) (interface {}, error ) {
673+ func parseVariableAsHCL (name string , input string , targetType config.VariableType ) (interface {}, error ) {
674+ // expecting a string so don't decode anything, just strip quotes
660675 if targetType == config .VariableTypeString {
661- return input , nil
676+ return strings .Trim (input , `"` ), nil
677+ }
678+
679+ // return empty types
680+ if strings .TrimSpace (input ) == "" {
681+ switch targetType {
682+ case config .VariableTypeList :
683+ return []interface {}{}, nil
684+ case config .VariableTypeMap :
685+ return make (map [string ]interface {}), nil
686+ }
662687 }
663688
664689 const sentinelValue = "SENTINEL_TERRAFORM_VAR_OVERRIDE_KEY"
0 commit comments