How to move an instance to another project

Problem

There is no option in Google Cloud Console or Cloud SDK to move a Google Compute Engine instance between projects.

Environment

  • Google Cloud console
  • Cloud SDK

Solution

  1. Stop the VM Instance. 
    gcloud compute instances stop INSTANCE_NAME  --zone=ZONE --project=OLD_PROJECT_ID
    
  2. Create an image from the VM Instance disk. 
    gcloud compute images create IMAGE_NAME --source-disk=DISK_NAME --source-disk-zone=DISK_ZONE --project=OLD_PROJECT_ID
    
  3. Confirm the image is created and present. 
    gcloud compute images list --project=OLD_PROJECT_ID
    
  4. Create a new VM Instance using the newly created image.
    gcloud compute instances create INSTANCE_NAME --image=IMAGE_NAME --image-project=OLD_PROJECT_ID --project=NEW_PROJECT_ID