// interactiveCollectVariables attempts to complete the given existing
// map of variables by interactively prompting for any variables that are
// declared as required but not yet present.
//
// If interactive input is disabled for this backend instance then this is
// a no-op. If input is enabled but fails for some reason, the resulting
// map will be incomplete. For these reasons, the caller must still validate
// that the result is complete and valid.
//
// This function does not modify the map given in "existing", but may return
// it unchanged if no modifications are required. If modifications are required,
// the result is a new map with all of the elements from "existing" plus
// additional elements as appropriate.
//
// Interactive prompting is a "best effort" thing for first-time user UX and
// not something we expect folks to be relying on for routine use. Terraform
// is primarily a non-interactive tool and so we prefer to report in error
// messages that variables are not set rather than reporting that input failed:
// the primary resolution to missing variables is to provide them by some other
// means.
interactiveCollectVariables attempts to complete the given existing
map of variables by interactively prompting for any variables that are
declared as required but not yet present.

If interactive input is disabled for this backend instance then this is
a no-op. If input is enabled but fails for some reason, the resulting
map will be incomplete. For these reasons, the caller must still validate
that the result is complete and valid.

This function does not modify the map given in "existing", but may return
it unchanged if no modifications are required. If modifications are required,
the result is a new map with all of the elements from "existing" plus
additional elements as appropriate.

Interactive prompting is a "best effort" thing for first-time user UX and
not something we expect folks to be relying on for routine use. Terraform
is primarily a non-interactive tool and so we prefer to report in error
messages that variables are not set rather than reporting that input failed:
the primary resolution to missing variables is to provide them by some other
means.
// interactiveCollectVariables attempts to complete the given existing // map of variables by interactively prompting for any variables that are // declared as required but not yet present . // // If interactive input is disabled for this backend instance then this is // a no - op . If input is enabled but fails for some reason the resulting // map will be incomplete . For these reasons the caller must still validate // that the result is complete and valid . // // This function does not modify the map given in " existing " but may return // it unchanged if no modifications are required . If modifications are required // the result is a new map with all of the elements from " existing " plus // additional elements as appropriate . // // Interactive prompting is a " best effort " thing for first - time user UX and // not something we expect folks to be relying on for routine use . Terraform // is primarily a non - interactive tool and so we prefer to report in error // messages that variables are not set rather than reporting that input failed : // the primary resolution to missing variables is to provide them by some other // means .
func (b *Local) interactiveCollectVariables(ctx context.Context, existing map[string]backend.UnparsedVariableValue, vcs map[string]*configs.Variable, uiInput terraform.UIInput) map[string]backend.UnparsedVariableValue {
	var needed []string
	if b.OpInput && uiInput != nil {
		for name, vc := range vcs {
			if !vc.Required() {
				continue 
			}
			if _, exists := existing[name]; !exists {
				needed = append(needed, name)
			}
		}
	} else {
		log.Print("[DEBUG] backend/local: Skipping interactive prompts for variables because input is disabled")
	}
	if len(needed) == 0 {
		return existing
	}
	log.Printf("[DEBUG] backend/local: will prompt for input of unset required variables %s", needed)
	sort.Strings(needed) 
	ret := make(map[string]backend.UnparsedVariableValue, len(vcs))
	for k, v := range existing {
		ret[k] = v
	}
	for _, name := range needed {
		vc := vcs[name]
		rawValue, err := uiInput.Input(ctx, &terraform.InputOpts{
			Id:          fmt.Sprintf("var.%s", name),
			Query:       fmt.Sprintf("var.%s", name),
			Description: vc.Description,
		})
		if err != nil {
			log.Printf("[WARN] backend/local: Failed to request user input for variable %q: %s", name, err)
			continue
		}
		ret[name] = unparsedInteractiveVariableValue{Name: name, RawValue: rawValue}
	}
	return ret
}
func ( b * Local ) interactiveCollectVariables ( ctx context . Context , existing map [ string ] backend . UnparsedVariableValue , vcs map [ string ] * configs . Variable , uiInput terraform . UIInput ) map [ string ] backend . UnparsedVariableValue { var needed [ ] string if b . OpInput && uiInput != nil { for name , vc := range vcs { if ! vc . Required ( ) { continue } if _ , exists := existing [ name ] ; ! exists { needed = append ( needed , name ) } } } else { log . Print ( " " ) } if len ( needed ) == 0 { return existing } log . Printf ( " " , needed ) sort . Strings ( needed ) ret := make ( map [ string ] backend . UnparsedVariableValue , len ( vcs ) ) for k , v := range existing { ret [ k ] = v } for _ , name := range needed { vc := vcs [ name ] rawValue , err := uiInput . Input ( ctx , & terraform . InputOpts { Id : fmt . Sprintf ( " " , name ) , Query : fmt . Sprintf ( " " , name ) , Description : vc . Description , } ) if err != nil { log . Printf ( " " , name , err ) continue } ret [ name ] = unparsedInteractiveVariableValue { Name : name , RawValue : rawValue } } return ret }
interactiveCollectVariables attempts to complete the given existing
map of variables by interactively prompting for any variables that are
declared as required but not yet present.
interactiveCollectVariables attempts to complete the given existing map of variables by interactively prompting for any variables that are declared as required but not yet present .
// We only prompt for required variables // If we get here then we're planning to prompt for at least one additional // variable's value. // prompt in lexical order // Since interactive prompts are best-effort, we'll just continue // here and let subsequent validation report this as a variable // not specified.