change to default state after backend migration

When migrating from a multi-state backend to a single-state backend, we
have to ensure that our locally configured environment is changed back
to "default", or we won't be able to access the new backend.
This commit is contained in:
James Bardin 2017-03-16 15:31:50 -04:00
parent fe4668cc88
commit ea095eda87
4 changed files with 10 additions and 0 deletions

View File

@ -183,6 +183,10 @@ func (m *Meta) backendMigrateState_S_s(opts *backendMigrateOpts) error {
// Copy the default state // Copy the default state
opts.oneEnv = currentEnv opts.oneEnv = currentEnv
// now switch back to the default env so we can acccess the new backend
m.SetEnv(backend.DefaultStateName)
return m.backendMigrateState_s_s(opts) return m.backendMigrateState_s_s(opts)
} }

View File

@ -1144,6 +1144,11 @@ func TestMetaBackend_configuredChangeCopy_multiToSingle(t *testing.T) {
if _, err := os.Stat(envPath); err != nil { if _, err := os.Stat(envPath); err != nil {
t.Fatal("env should exist") t.Fatal("env should exist")
} }
// Verify we are now in the default env, or we may not be able to access the new backend
if env := m.Env(); env != backend.DefaultStateName {
t.Fatal("using non-default env with single-env backend")
}
} }
// Changing a configured backend that supports multi-state to a // Changing a configured backend that supports multi-state to a