From 7d6d31eff83b6e75bd9a3eeceff5d016ef67fd5a Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Wed, 17 Nov 2021 12:43:37 -0800 Subject: [PATCH] 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. --- internal/command/meta_backend_migrate.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/internal/command/meta_backend_migrate.go b/internal/command/meta_backend_migrate.go index 800d45c9a8..6bdff56eb5 100644 --- a/internal/command/meta_backend_migrate.go +++ b/internal/command/meta_backend_migrate.go @@ -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.