Copying VMs between projects

Linux Windows

This document describes how to copy your VM to a different project.

Before you begin

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.create on the project
  • To use a custom image to create the VM: compute.images.useReadOnly on the image
  • To use a snapshot to create the VM: compute.snapshots.useReadOnly on the snapshot
  • To use an instance template to create the VM: compute.instanceTemplates.useReadOnly on the instance template
  • To specify a subnet for your VM: compute.subnetworks.use on the project or on the chosen subnet
  • To specify a static IP address for the VM: compute.addresses.use on the project
  • To assign an external IP address to the VM when using a VPC network: compute.subnetworks.useExternalIp on the project or on the chosen subnet
  • To assign alegacy network to the VM: compute.networks.use on the project
  • To assign an external IP address to the VM when using a legacy network: compute.networks.useExternalIp on the project
  • To set VM instance metadata for the VM: compute.instances.setMetadata on the project
  • To set tags for the VM: compute.instances.setTags on the VM
  • To set labels for the VM: compute.instances.setLabels on the VM
  • To set a service account for the VM to use: compute.instances.setServiceAccount on the VM
  • To create a new disk for the VM: compute.disks.create on the project
  • To attach an existing disk in read-only or read-write mode: compute.disks.use on the disk
  • To attach an existing disk in read-only mode: compute.disks.useReadOnly on the disk

You might also be able to get these permissions withcustom roles or otherpredefined roles.

Copy a VM to another project

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

  2. 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 image
    • SOURCE_SNAPSHOT: the snapshot from which you want to create the image
    • LOCATION: Optional: a flag that lets you designate the region or multi-region where your image is stored. For example, specifyus to store the image in theus multi-region, orus-central1 to store it in theus-central1 region. If you don't make a selection, Compute Engine stores the image in the multi-region closest to your image's source location.
  3. 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.

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

What's next

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.