Categories
Server Administration

Google Cloud: How to Migrate VM Instances from One Project to Another

If you’re just getting started with GCP, chances are you will have different VM instances running under a default project. Then somewhere down the track, if you decided to set up different billing accounts for different VM instances, you will have to come across this issue. So let’s get it started with a step by step guide.

  1. I assume at this point, you already have a basic understanding of how to use and navigate GCP, such as VM instance, Disks, Snapshots and Images and how to create them.
  2. Let say you have a VM instance client-b currently sitting in project-a, but you want to move it to project-b, you need to create an image from the disk which client-b is running on.
  3. Download and install Google Cloud SDK and login to your GCP account, it’s straightforward so no instructions needed here. Once you logged in it will prompt you to choose which project to work on, make sure you choose project-b, which is the destination of the new VM Instance you’re about to create. If you want to switch to a different project, use this command:
    gcloud config set project <my-project-id>
  4. Then use this command to create the new VM instance:
    gcloud compute instances create <new-instance-name> --image <image-name-you-just-created> --image-project <project-a-id>
  5. Make sure you enable http and https in the firewall, and once the new instance is a successful replica, you can go ahead turn the old VM off.
  6. It should only take less than 10 min to create a new instance from a 60G image, if you’re running a web server on your VM, you will need to restart Apache and MySQL.

By Ethan

To many, a business is a lifetime commitment. It's easy to start one yet difficult to make it successful. Attitude, skills, experiences and dedication help hone the craft along the way, but it's often the great vision and resilience to remain focused wins the game. Read more about me here