Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Compute Engine : Use snapshot from another project?

I have two projects in my developer console. I have taken a "Snapshot" of one of the VMs in project-1. I want to create a new VM in project-2 using the snapshot created in project-1. Right now snapshot is not showing in the option. How can I import snapshot from one project to another?

like image 824
Remis Haroon - رامز Avatar asked Apr 12 '15 02:04

Remis Haroon - رامز


People also ask

How do I copy a machine image from one project to another in GCP?

Use Google Cloud Share command to copy image from one project to another project. Actually, you can directly use this image by choosing from custom image to create a boot disk when you create a new VM. Note: Use project_id in the command , not project name.

Is it possible to create a disk from snapshot from one region to another region in GCP?

A snapshot can be used to create a new disk in any region and zone, regardless of the storage location of the snapshot.


2 Answers

You can create an image from the snap in Project 1, then create an instance from that image using Project 2.

I'm assuming you have edit rights in both projects.

Your question says you have a snapshot and want to make an instance in project 2 from the snap in project 1.

If you still have the disk available that you had snapshotted, make sure it's no longer attached to an instance. If it's still attached to the instance, uncheck "delete boot disk when deleting instance" and delete the instance. Go to Images and click create image from disk, and create an image from this disk.

If you do not have the disk available, but just the snapshot, create an instance and set the boot disk as a snapshot and select your snapshot. Then follow the directions above to create an image by deleting the instance first.

Now you have an image in project 1. You should see it listed under images.

I'm not sure why, but you won't see the image listed in the console in project 2, however you can use gcloud to create an instance in project 2 using the image from project 1. In project 1, click on the image and click "view REST" there will be a full URL to the image, similar to this:

https://www.googleapis.com/compute/v1/projects/cpomeroy-whitelist/global/images/ruby-image 

Use gcloud to create an instance in project 2 using the image in project 1:

gcloud config set project <project-id-of-project-2> gcloud config list 

(You should verify you are in project 2)

gcloud compute instances create <name of instance> --image https://www.googleapis.com/compute/v1/projects/cpomeroy-whitelist/global/images/ruby-image 

Obviously your URL will be different.

I just tested this and it works. Let me know if you need more help.

like image 125
chrispomeroy Avatar answered Sep 16 '22 16:09

chrispomeroy


The answer posted by @chrispomeroy worked for me, but I was able to simplify it a little as I need to do this more and more.

Let's say you have an image in project-1, and need to create an instance using that image in project-2.

gcloud config set project "project-2" gcloud compute instances create <name-of-new-instance> \     --image <name-of-your-image-from-project-1> \     --image-project "project-1" 

This eliminates the need to worry about using a URL for anything.

EDIT: My answer pretty much looks like his at this point, but the docs for this stuff is here:

gcloud compute instances create

like image 39
jiminikiz Avatar answered Sep 20 '22 16:09

jiminikiz