Copying VMs between projects Stay organized with collections Save and categorize content based on your preferences.
This document describes how to copy your VM to a different project.
Before you begin
- Review Best practices for persistent disk snapshots and prepare your boot disk for snapshots.
- If you haven't already, set upauthentication. Authentication verifies your identity for access to Google Cloud services and APIs. To run code or samples from a local development environment, you can authenticate to Compute Engine by selecting one of the following options:
Install the Google Cloud CLI. After installation,initialize the Google Cloud CLI by running the following command:
gcloudinit
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update.- Set a default region and zone.
Required roles
To get the permissions that you need to copy VM between projects, ask your administrator to grant you theCompute Instance Admin (v1) (roles/compute.instanceAdmin.v1) IAM role on the project. For more information about granting roles, seeManage access to projects, folders, and organizations.
This predefined role contains the permissions required to copy VM between projects. To see the exact permissions that are required, expand theRequired permissions section:
Required permissions
The following permissions are required to copy VM between projects:
compute.instances.createon the project- To use a custom image to create the VM:
compute.images.useReadOnlyon the image - To use a snapshot to create the VM:
compute.snapshots.useReadOnlyon the snapshot - To use an instance template to create the VM:
compute.instanceTemplates.useReadOnlyon the instance template - To specify a subnet for your VM:
compute.subnetworks.useon the project or on the chosen subnet - To specify a static IP address for the VM:
compute.addresses.useon the project - To assign an external IP address to the VM when using a VPC network:
compute.subnetworks.useExternalIpon the project or on the chosen subnet - To assign alegacy network to the VM:
compute.networks.useon the project - To assign an external IP address to the VM when using a legacy network:
compute.networks.useExternalIpon the project - To set VM instance metadata for the VM:
compute.instances.setMetadataon the project - To set tags for the VM:
compute.instances.setTagson the VM - To set labels for the VM:
compute.instances.setLabelson the VM - To set a service account for the VM to use:
compute.instances.setServiceAccounton the VM - To create a new disk for the VM:
compute.disks.createon the project - To attach an existing disk in read-only or read-write mode:
compute.disks.useon the disk - To attach an existing disk in read-only mode:
compute.disks.useReadOnlyon the disk
You might also be able to get these permissions withcustom roles or otherpredefined roles.
Copy a VM to another project
In your source project, create a snapshot of the VM's boot disk, using oneof the following commands:
Zonal boot disk
If your VM has a zonal boot disk, create a snapshot using the followingcommand:
gcloud compute snapshots createSNAPSHOT_NAME \ --source-diskSOURCE_DISK \ --snapshot-typeSNAPSHOT_TYPE \ --source-disk-zoneSOURCE_DISK_ZONE
Replace the following:
- SNAPSHOT_NAME: A name for the snapshot.
- SOURCE_DISK: The name of the zonal Persistent Disk volume from which you want to create a snapshot.
- SNAPSHOT_TYPE: The snapshot type, eitherSTANDARD orARCHIVE. If a snapshot type is not specified, aSTANDARD snapshot is created. Choose Archive for more cost-efficient data retention.
- SOURCE_DISK_ZONE: The zone of the zonal Persistent Disk volume from which you want to create a snapshot.
Regional boot disk
If your VM has a regional boot disk, create a snapshot using thefollowing command:
gcloud compute snapshots createSNAPSHOT_NAME \ --source-diskSOURCE_DISK \ --source-disk-region=SOURCE_DISK_REGION \ --snapshot-type=SNAPSHOT_TYPE
Replace the following:
- SNAPSHOT_NAME: A name for the snapshot.
- SOURCE_DISK: The name of the regional Persistent Disk volume from which you want to create a snapshot.
- SOURCE_DISK_REGION: The region of the regional Persistent Disk volume from which you want to create a snapshot.
- SNAPSHOT_TYPE: The snapshot type, eitherSTANDARD orARCHIVE. If a snapshot type is not specified, aSTANDARD snapshot is created.
Create a custom image from the snapshot using the following command:
gcloud compute images createIMAGE_NAME \ --source-snapshot=SOURCE_SNAPSHOT \ [--storage-location=LOCATION]
Replace the following:
IMAGE_NAME: a name for the new imageSOURCE_SNAPSHOT: the snapshot from which you want to create the imageLOCATION: Optional: a flag that lets you designate the region or multi-region where your image is stored. For example, specifyusto store the image in theusmulti-region, orus-central1to store it in theus-central1region. If you don't make a selection, Compute Engine stores the image in the multi-region closest to your image's source location.
Optional: Share the custom image with users who create VMs in thedestination project. For more information about sharing custom images, seeSharing custom image within an organization.
In your destination project, create a VM from the custom image using thefollowing command:
gcloud compute instances createVM_NAME \ --image-projectIMAGE_PROJECT \IMAGE_FLAG \ --subnetSUBNET
Replace the following:
VM_NAME: the name of the VMIMAGE_PROJECT: the ID of the Google Cloud project that contains the imageIMAGE_FLAG: specify one of the following:- Use the
--imageIMAGE_NAMEflag to specify a custom image.For example,
--image my-debian-image-v2. - If you created your custom images as part of acustom image family, use the
--image-familyIMAGE_FAMILY_NAMEflag to specify that custom image family.This creates the VM from the most recent, non-deprecated OS image and OS version in your custom image family. For example, if you specify
--image-family my-debian-family, Compute Engine creates a VM from the latest OS image in your custommy-debian-familyimage family.
debian-10anddebian-cloud, respectively.- Use the
SUBNET: if the subnet and instance are in the same project, replaceSUBNETwith the name of a subnet that is in the same region as the instance.To specify a subnet in a Shared VPC network, replace
SUBNETwith a string of the form:projects/HOST_PROJECT_ID/regions/REGION/subnetworks/SUBNET_NAME
Replace the following:
HOST_PROJECT_ID: the project ID of the Shared VPC host projectREGION: the region of the subnetSUBNET_NAME: the name of the subnet
The region of the subnet for a Shared VPC network must also match the region containing the instance.
What's next
- Customize the destination project'sVPC network.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-15 UTC.