remove duplicate backend migration prompts
The duplicate prompts can be confusing when the user confirms that a migration should happen and we immediately prompt a second time for the same thing with slightly different wording. The extra hand-holding that this provides for legacy remote states is less critical now, since it's been 2 major release cycles since those were removed.
This commit is contained in:
parent
03ddb9134a
commit
7c93b2e5e6
|
@ -678,24 +678,8 @@ func (m *Meta) backend_c_r_S(
|
|||
// Get the backend type for output
|
||||
backendType := s.Backend.Type
|
||||
|
||||
copy := m.forceInitCopy
|
||||
if !copy {
|
||||
var err error
|
||||
// Confirm with the user that the copy should occur
|
||||
copy, err = m.confirm(&terraform.InputOpts{
|
||||
Id: "backend-migrate-to-local",
|
||||
Query: fmt.Sprintf("Do you want to copy the state from %q?", s.Backend.Type),
|
||||
Description: fmt.Sprintf(
|
||||
strings.TrimSpace(inputBackendMigrateLocal), s.Backend.Type),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf(
|
||||
"Error asking for state copy action: %s", err)
|
||||
}
|
||||
}
|
||||
m.Ui.Output(fmt.Sprintf(strings.TrimSpace(outputBackendMigrateLocal), s.Backend.Type))
|
||||
|
||||
// If we're copying, perform the migration
|
||||
if copy {
|
||||
// Grab a purely local backend to get the local state if it exists
|
||||
localB, err := m.Backend(&BackendOpts{ForceLocal: true})
|
||||
if err != nil {
|
||||
|
@ -719,7 +703,6 @@ func (m *Meta) backend_c_r_S(
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// Remove the stored metadata
|
||||
s.Backend = nil
|
||||
|
@ -802,24 +785,7 @@ func (m *Meta) backend_c_R_S(
|
|||
// Grab the state
|
||||
s := sMgr.State()
|
||||
|
||||
// Ask the user if they want to migrate their existing remote state
|
||||
copy := m.forceInitCopy
|
||||
if !copy {
|
||||
copy, err = m.confirm(&terraform.InputOpts{
|
||||
Id: "backend-migrate-to-new",
|
||||
Query: fmt.Sprintf(
|
||||
"Do you want to copy the legacy remote state from %q?",
|
||||
s.Remote.Type),
|
||||
Description: strings.TrimSpace(inputBackendMigrateLegacyLocal),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf(
|
||||
"Error asking for state copy action: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
// If the user wants a copy, copy!
|
||||
if copy {
|
||||
m.Ui.Output(strings.TrimSpace(outputBackendMigrateLegacy))
|
||||
// Initialize the legacy backend
|
||||
oldB, err := m.backendInitFromLegacy(s.Remote)
|
||||
if err != nil {
|
||||
|
@ -836,7 +802,6 @@ func (m *Meta) backend_c_R_S(
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// Unset the remote state
|
||||
s = sMgr.State()
|
||||
|
@ -897,25 +862,7 @@ func (m *Meta) backend_C_R_s(
|
|||
return b, nil
|
||||
}
|
||||
|
||||
// Finally, ask the user if they want to copy the state from
|
||||
// their old remote state location.
|
||||
copy := m.forceInitCopy
|
||||
if !copy {
|
||||
copy, err = m.confirm(&terraform.InputOpts{
|
||||
Id: "backend-migrate-to-new",
|
||||
Query: fmt.Sprintf(
|
||||
"Do you want to copy the legacy remote state from %q?",
|
||||
s.Remote.Type),
|
||||
Description: strings.TrimSpace(inputBackendMigrateLegacy),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf(
|
||||
"Error asking for state copy action: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
// If the user wants a copy, copy!
|
||||
if copy {
|
||||
m.Ui.Output(strings.TrimSpace(outputBackendMigrateLegacy))
|
||||
// Initialize the legacy backend
|
||||
oldB, err := m.backendInitFromLegacy(s.Remote)
|
||||
if err != nil {
|
||||
|
@ -932,7 +879,6 @@ func (m *Meta) backend_C_R_s(
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// Unset the remote state
|
||||
s = sMgr.State()
|
||||
|
@ -1077,23 +1023,8 @@ func (m *Meta) backend_C_r_S_changed(
|
|||
"Error initializing new backend: %s", err)
|
||||
}
|
||||
|
||||
// Check with the user if we want to migrate state
|
||||
copy := m.forceInitCopy
|
||||
if !copy {
|
||||
copy, err = m.confirm(&terraform.InputOpts{
|
||||
Id: "backend-migrate-to-new",
|
||||
Query: fmt.Sprintf("Do you want to copy the state from %q?", s.Backend.Type),
|
||||
Description: strings.TrimSpace(fmt.Sprintf(inputBackendMigrateChange, s.Backend.Type, c.Type)),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf(
|
||||
"Error asking for state copy action: %s", err)
|
||||
}
|
||||
}
|
||||
m.Ui.Output(strings.TrimSpace(fmt.Sprintf(outputBackendMigrateChange, s.Backend.Type, c.Type)))
|
||||
|
||||
// If we are, then we need to initialize the old backend and
|
||||
// perform the copy.
|
||||
if copy {
|
||||
// Grab the existing backend
|
||||
oldB, err := m.backend_C_r_S_unchanged(c, sMgr)
|
||||
if err != nil {
|
||||
|
@ -1111,7 +1042,6 @@ func (m *Meta) backend_C_r_S_changed(
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if m.stateLock {
|
||||
lockCtx, cancel := context.WithTimeout(context.Background(), m.stateLockTimeout)
|
||||
|
@ -1237,24 +1167,8 @@ func (m *Meta) backend_C_R_S_unchanged(
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// Ask if the user wants to move their legacy remote state
|
||||
copy := m.forceInitCopy
|
||||
if !copy {
|
||||
copy, err = m.confirm(&terraform.InputOpts{
|
||||
Id: "backend-migrate-to-new",
|
||||
Query: fmt.Sprintf(
|
||||
"Do you want to copy the legacy remote state from %q?",
|
||||
s.Remote.Type),
|
||||
Description: strings.TrimSpace(inputBackendMigrateLegacy),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf(
|
||||
"Error asking for state copy action: %s", err)
|
||||
}
|
||||
}
|
||||
m.Ui.Output(strings.TrimSpace(outputBackendMigrateLegacy))
|
||||
|
||||
// If the user wants a copy, copy!
|
||||
if copy {
|
||||
// Initialize the legacy backend
|
||||
oldB, err := m.backendInitFromLegacy(s.Remote)
|
||||
if err != nil {
|
||||
|
@ -1271,7 +1185,6 @@ func (m *Meta) backend_C_R_S_unchanged(
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if m.stateLock {
|
||||
lockCtx, cancel := context.WithTimeout(context.Background(), m.stateLockTimeout)
|
||||
|
@ -1638,27 +1551,16 @@ Plan Serial: %[1]d
|
|||
Current Serial: %[2]d
|
||||
`
|
||||
|
||||
const inputBackendMigrateChange = `
|
||||
Would you like to copy the state from your prior backend %q to the
|
||||
newly configured %q backend? If you're reconfiguring the same backend,
|
||||
answering "yes" or "no" shouldn't make a difference. Please answer exactly
|
||||
"yes" or "no".
|
||||
const outputBackendMigrateChange = `
|
||||
Terraform detected a backend configuration change from %q to %q.
|
||||
`
|
||||
|
||||
const inputBackendMigrateLegacy = `
|
||||
Terraform can copy the existing state in your legacy remote state
|
||||
backend to your newly configured backend. Please answer "yes" or "no".
|
||||
const outputBackendMigrateLegacy = `
|
||||
Terraform detected legacy remote state.
|
||||
`
|
||||
|
||||
const inputBackendMigrateLegacyLocal = `
|
||||
Terraform can copy the existing state in your legacy remote state
|
||||
backend to your local state. Please answer "yes" or "no".
|
||||
`
|
||||
|
||||
const inputBackendMigrateLocal = `
|
||||
Terraform has detected you're unconfiguring your previously set backend.
|
||||
Would you like to copy the state from %q to local state? Please answer
|
||||
"yes" or "no". If you answer "no", you will start with a blank local state.
|
||||
const outputBackendMigrateLocal = `
|
||||
Terraform has detected you're unconfiguring your previously set %q backend.
|
||||
`
|
||||
|
||||
const outputBackendConfigureWithLegacy = `
|
||||
|
|
Loading…
Reference in New Issue