Skip to content

Commit

Permalink
Merge pull request openshift#509 from wking/cross-device-tfstate-copy
Browse files Browse the repository at this point in the history
pkg/destroy/bootstrap: Fix cross-filesystem tfstate recovery
  • Loading branch information
openshift-merge-robot authored Oct 24, 2018
2 parents fb0469e + db3b019 commit 060b1be
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pkg/destroy/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,15 @@ func Destroy(dir string) (err error) {
logrus.Infof("Using Terraform to destroy bootstrap resources...")
err = terraform.Destroy(tempDir, platform, "-target=module.bootstrap")
if err != nil {
err = errors.Wrap(err, "failed to run terraform")
return errors.Wrap(err, "failed to run terraform")
}

return os.Rename(filepath.Join(dir, terraform.StateFileName), filepath.Join(tempDir, terraform.StateFileName))
tempStateFilePath := filepath.Join(dir, terraform.StateFileName+".new")
err = copy(filepath.Join(tempDir, terraform.StateFileName), tempStateFilePath)
if err != nil {
return errors.Wrapf(err, "failed to copy %s from the temporary directory", terraform.StateFileName)
}
return os.Rename(tempStateFilePath, filepath.Join(dir, terraform.StateFileName))
}

func copy(from string, to string) error {
Expand Down

0 comments on commit 060b1be

Please sign in to comment.