don't loop indefinitely in confirm method
Only check for input twice in the meta.confirm method. This prevents an errant newline from aborting the run while allowing Terraform to exit if there is no input available. We don't just check for a tty, since we still rely on being able to pipe input in for testing. Remove the redundant confirmation loops in the migration code, and only use the confirm method.
This commit is contained in:
parent
7d2da9865e
commit
885e4cde81
|
@ -476,7 +476,8 @@ func (m *Meta) confirm(opts *terraform.InputOpts) (bool, error) {
|
|||
if !m.Input() {
|
||||
return false, errors.New("input is disabled")
|
||||
}
|
||||
for {
|
||||
|
||||
for i := 0; i < 2; i++ {
|
||||
v, err := m.UIInput().Input(opts)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf(
|
||||
|
@ -490,6 +491,7 @@ func (m *Meta) confirm(opts *terraform.InputOpts) (bool, error) {
|
|||
return true, nil
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// showDiagnostics displays error and warning messages in the UI.
|
||||
|
|
|
@ -346,22 +346,7 @@ func (m *Meta) backendMigrateEmptyConfirm(one, two state.State, opts *backendMig
|
|||
opts.OneType, opts.TwoType),
|
||||
}
|
||||
|
||||
// Confirm with the user that the copy should occur
|
||||
for {
|
||||
v, err := m.UIInput().Input(inputOpts)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf(
|
||||
"Error asking for state copy action: %s", err)
|
||||
}
|
||||
|
||||
switch strings.ToLower(v) {
|
||||
case "no":
|
||||
return false, nil
|
||||
|
||||
case "yes":
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
return m.confirm(inputOpts)
|
||||
}
|
||||
|
||||
func (m *Meta) backendMigrateNonEmptyConfirm(
|
||||
|
@ -410,21 +395,7 @@ func (m *Meta) backendMigrateNonEmptyConfirm(
|
|||
}
|
||||
|
||||
// Confirm with the user that the copy should occur
|
||||
for {
|
||||
v, err := m.UIInput().Input(inputOpts)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf(
|
||||
"Error asking for state copy action: %s", err)
|
||||
}
|
||||
|
||||
switch strings.ToLower(v) {
|
||||
case "no":
|
||||
return false, nil
|
||||
|
||||
case "yes":
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
return m.confirm(inputOpts)
|
||||
}
|
||||
|
||||
type backendMigrateOpts struct {
|
||||
|
|
Loading…
Reference in New Issue