command/init: Skip redundant state migration prompt in Cloud mode

The specialized Terraform Cloud migration process asks right up top
whether the user wants to migrate state, because there are various other
questions contingent on that answer.

Therefore we ought to just honor their earlier answer when we get to the
point of actually doing the state migration, rather than prompting again.

This is tricky because we're otherwise just reusing a codepath that's
common to both modes. Hopefully we can find a better way to do this in
a later commit, but for the moment our main motivation is minimizing risk
to the very next release.
This commit is contained in:
Martin Atkins 2021-11-17 12:43:37 -08:00
parent 27aa51687e
commit 7d6d31eff8
1 changed files with 12 additions and 2 deletions

View File

@ -387,8 +387,18 @@ func (m *Meta) backendMigrateState_s_s(opts *backendMigrateOpts) error {
// We have existing state moving into no state. Ask the user if
// they'd like to do this.
case !source.Empty() && destination.Empty():
log.Print("[TRACE] backendMigrateState: destination workspace has empty state, so might copy source workspace state")
confirmFunc = m.backendMigrateEmptyConfirm
if opts.SourceType == "cloud" || opts.DestinationType == "cloud" {
// HACK: backendMigrateTFC has its own earlier prompt for
// whether to migrate state in the cloud case, so we'll skip
// this later prompt for Cloud, even though we do still need it
// for state backends.
confirmFunc = func(statemgr.Full, statemgr.Full, *backendMigrateOpts) (bool, error) {
return true, nil // the answer is implied to be "yes" if we reached this point
}
} else {
log.Print("[TRACE] backendMigrateState: destination workspace has empty state, so might copy source workspace state")
confirmFunc = m.backendMigrateEmptyConfirm
}
// Both states are non-empty, meaning we need to determine which
// state should be used and update accordingly.