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.
- 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.
- 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.
- 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>
- 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>
- 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.
- 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.