How to export an image machine to another GCP account?

Viewed 3006

I would like to import a machine image created in an account into a another google cloud platform account. could you help me?

2 Answers

There is a way to create an instance and a new machine image using a machine image from a different project.

I’ve reproduced this scenario in my own projects and I was able to use a machine image from a different project to create my instance, I’ve followed the next documentation

I already created a machine image my-machine-image on my machine-image-project-origin and I granted permission to the service account 123456789000-compute@developer.gserviceaccount.com that is under the new project vm-project-destination.

It is worth mentioning that my machine-image-project-origin and my vm-project-destination are under different organizations and were created with different accounts.

To grant access to the my-machine-image that is stored in the project machine-image-project-origin using the gcloud command-line tool:

gcloud beta compute machine-images add-iam-policy-binding my-machine-image \
    --project=machine-image-project-origin \
    --member='serviceAccount:123456789000-compute@developer.gserviceaccount.com' \
    --role='roles/compute.admin'

You will obtain something like:

Updated IAM policy for machine image [my-machine-image].
bindings:
- members:
  - serviceAccount:123456789000-compute@developer.gserviceaccount.com
  role: roles/compute.admin
etag: BwXtXMjY8wZ=
version: 1

Then to use this image to create a new instance my-instance, in my new project vm-project-destination :

gcloud beta compute instances create my-instance \
 --project=vm-project-destination \
 --zone us-east1-b \
 --source-machine-image projects/machine-image-project-origin/global/machineImages/machine-image-to-share \
 --service-account 123456789000-compute@developer.gserviceaccount.com

And you will obtain something like:

Created [https://www.googleapis.com/compute/beta/projects/vm-project-destination/zones/us-east1-b/instances/my-instance].
NAME             ZONE        MACHINE_TYPE   PREEMPTIBLE  INTERNAL_IP  EXTERNAL_IP   STATUS
my-instance      us-east1-b  n1-standard-1               10.122.0.2   35.222.19.36  RUNNING

Then if you want, you can create a new machine image based in this new instance that we already created, that basically will be a copy from the machine image created in the original project.

On the other hand, I recommend you to review the following guides on asking questions: How do I ask a good question? and How to create a Minimal, Complete, and Verifiable example in order to provide a better context on what you are doing and what you want to achieve.

I hope you find this information useful.

Start by looking at these docs: Here

This should give you an insight into sharing images across accounts.

Once you have properly shared access to the other account's image. I believe you could do something like:

gcloud compute --project=destinationproject images create dest-image --source-image=src-image --source-image-project=sourceproject

Related