Merge pull request #12888 from hashicorp/b-legacy-remove

command: remove legacy remote state on migration
This commit is contained in:
Mitchell Hashimoto 2017-03-20 11:57:12 -07:00 committed by GitHub
commit f105c8533a
4 changed files with 29 additions and 1 deletions

View File

@ -110,6 +110,12 @@ func (b *Local) opPlan(
// Write the backend if we have one
plan.Backend = op.PlanOutBackend
// This works around a bug (#12871) which is no longer possible to
// trigger but will exist for already corrupted upgrades.
if plan.Backend != nil && plan.State != nil {
plan.State.Remote = nil
}
log.Printf("[INFO] backend/local: writing plan output to: %s", path)
f, err := os.Create(path)
if err == nil {

View File

@ -235,6 +235,15 @@ func (m *Meta) backendMigrateState_s_s(opts *backendMigrateOpts) error {
one := stateOne.State()
two := stateTwo.State()
// Clear the legacy remote state in both cases. If we're at the migration
// step then this won't be used anymore.
if one != nil {
one.Remote = nil
}
if two != nil {
two.Remote = nil
}
var confirmFunc func(state.State, state.State, *backendMigrateOpts) (bool, error)
switch {
// No migration necessary

View File

@ -771,6 +771,13 @@ func TestMetaBackend_configureNewLegacyCopy(t *testing.T) {
}
}
// Verify we have no configured legacy in the state itself
{
if !state.Remote.Empty() {
t.Fatalf("legacy has remote state: %#v", state.Remote)
}
}
// Write some state
state = terraform.NewState()
state.Lineage = "changing"

View File

@ -2,5 +2,11 @@
"version": 3,
"terraform_version": "0.8.2",
"serial": 7,
"lineage": "backend-new-legacy"
"lineage": "backend-new-legacy",
"remote": {
"type": "local",
"config": {
"path": "local-state-old.tfstate"
}
}
}