Select the tab for how you plan to use the samples on this page:
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
After installing the Google Cloud CLI, initialize it 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.
To use the Terraform samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
To initialize the gcloud CLI, run the following command:
gcloudinit
If you're using a local shell, then create local authentication credentials for your user account:
gcloudauthapplication-defaultlogin
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
For more information, see Set up authentication for a local development environment.
To use the Go samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
To initialize the gcloud CLI, run the following command:
gcloudinit
If you're using a local shell, then create local authentication credentials for your user account:
gcloudauthapplication-defaultlogin
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
For more information, see Set up authentication for a local development environment.
To use the Java samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
To initialize the gcloud CLI, run the following command:
gcloudinit
If you're using a local shell, then create local authentication credentials for your user account:
gcloudauthapplication-defaultlogin
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
For more information, see Set up authentication for a local development environment.
To use the Python samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
To initialize the gcloud CLI, run the following command:
gcloudinit
If you're using a local shell, then create local authentication credentials for your user account:
gcloudauthapplication-defaultlogin
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
For more information, see Set up authentication for a local development environment.
To use the REST API samples on this page in a local development environment, you use the credentials you provide to the gcloud CLI.
After installing the Google Cloud CLI, initialize it 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.
For more information, see Authenticate for using REST in the Google Cloud authentication documentation.
When you clone a disk, you create a new disk that contains all the data on the source disk. You can create a disk clone even if the existing disk is attached to a VM instance.
The disk type of the clone must be the same as that of the source disk. However, you can modify properties on the clone, such as the disk size. You can also delete the source disk without any risk of deleting the clone.
You can create disk clones only for the following disk types:
Depending on the type of disk, disk clones have the following restrictions:
The following restrictions apply to clones of all disk types:
internalError
. However, if you create a disk clone and delete it later, then the deleted disk clone is not included in this limit.Disk clones for Persistent Disk have the following restrictions:
You can't create a Hyperdisk Balanced High Availability disk by cloning a zonal disk. To create a Hyperdisk Balanced High Availability disk from an existing zonal disk, complete the steps in Change a zonal disk to a regional Hyperdisk Balanced High Availability disk.
You can't clone Hyperdisk ML volumes.
If you exceed the cloning frequency limits, the request fails with the following error:
RATE LIMIT: ERROR: (gcloud.compute.disks.create) Could not fetch resource: - Operation rate exceeded for resource RESOURCE. Too frequent operations from the source resource.
This section explains how you can duplicate an existing disk and create a disk clone.
For detailed steps, depending on the type of disk clone creation, see one of the following sections in this document:
You can create zonal disk clones of an existing disk in the same zone as the source disk by using the Google Cloud console, the Google Cloud CLI, or REST.
In the Google Cloud console, go to the Disks page.
In the list of disks, navigate to the disk that you want to clone.
In the Actions column, click the
menu button and select Clone disk.In the Clone disk panel that appears, do the following:
To clone a zonal source disk and create a new zonal disk, run the disks create
command and specify the --source-disk
flag:
gcloud compute disks create TARGET_DISK_NAME \ --description="cloned disk" \ --source-disk=projects/PROJECT_ID/zones/ZONE/disks/SOURCE_DISK_NAME
Replace the following:
TARGET_DISK_NAME
: the name for the new disk.PROJECT_ID
: the project ID where you want to clone the disk.ZONE
: the zone of the source and new disk.SOURCE_DISK_NAME
: the name of the source disk.To create a disk clone, use the google_compute_disk
resource.
To learn how to apply or remove a Terraform configuration, see Basic Terraform commands.
Before trying this sample, follow the Go setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Go API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Before trying this sample, follow the Java setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Java API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Before trying this sample, follow the Python setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Python API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
To clone a zonal source disk and create a new zonal disk, make a POST
request to the compute.disks.insert
method. In the request body, specify the name
and sourceDisk
parameters. The disk clone inherits all omitted properties from the source disk.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/disks { "name": "TARGET_DISK_NAME" "sourceDisk": "projects/PROJECT_ID/zones/ZONE/disks/SOURCE_DISK_NAME" }
Replace the following:
PROJECT_ID
: the project ID where you want to clone the disk.ZONE
: the zone of the source and new disk.TARGET_DISK_NAME
: the name for the new disk.SOURCE_DISK_NAME
: the name of the source diskYou can create a new regional Persistent Disk disk by cloning an existing zonal Persistent Disk volume. To migrate a zonal disk to a regional disk, Google recommends this option instead of creating a snapshot of the zonal disk and restoring the snapshot to a new regional disk.
In the Google Cloud console, go to the Disks page.
In the list of disks, navigate to the zonal Persistent Disk volume that you want to clone.
In the Actions column, click the
menu button and select Clone disk.In the Clone disk panel that appears, do the following:
To create a regional disk clone from a zonal disk, run the gcloud compute disks create
command and specify the --region
and --replica-zones
parameters.
gcloud compute disks create TARGET_DISK_NAME \ --description="zonal to regional cloned disk" \ --region=CLONED_REGION \ --source-disk=SOURCE_DISK_NAME \ --source-disk-zone=SOURCE_DISK_ZONE \ --replica-zones=SOURCE_DISK_ZONE,REPLICA_ZONE_2 \ --project=PROJECT_ID
Replace the following:
TARGET_DISK_NAME
: the name for the new regional disk clone.CLONED_REGION
: the region of the source and cloned disks.SOURCE_DISK_NAME
: the name of the zonal disk to clone.SOURCE_DISK_ZONE
: the zone for the source disk. This will also be the first replica zone for the regional disk clone.REPLICA_ZONE_2
: the second replica zone for the new regional disk clone.PROJECT_ID
: the project ID where you want to clone the disk.To create a regional disk clone from a zonal disk, you can optionally create a snapshot of the zonal disk and then clone the snapshot. To do this, use the following resources:
To learn how to apply or remove a Terraform configuration, see Basic Terraform commands.
Before trying this sample, follow the Go setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Go API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Before trying this sample, follow the Java setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Java API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Before trying this sample, follow the Python setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Python API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
To create a regional disk clone from a zonal disk, make a POST
request to the compute.disks.insert
method and specify the sourceDisk
and replicaZone
parameters.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/CLONED_REGION/disks { "name": "TARGET_DISK_NAME" "sourceDisk": "projects/PROJECT_ID/zones/SOURCE_DISK_ZONE/disks/SOURCE_DISK_NAME" "replicaZone": "SOURCE_DISK_ZONE,REPLICA_ZONE_2" }
Replace the following:
PROJECT_ID
: the project ID where you want to clone the disk.TARGET_DISK_NAME
: the name for the new regional disk clone.CLONED_REGION
: the region of the source and cloned disks.SOURCE_DISK_NAME
: the name of the zonal disk to clone.SOURCE_DISK_ZONE
: the zone for the source disk. This will also be the first replica zone for the regional disk clone.REPLICA_ZONE_2
: the second replica zone for the new regional disk clone.You can use a customer-supplied encryption key (CSEK) or a customer-managed encryption key to encrypt your disks.
If you use a CSEK to encrypt your source disk, you must also use the same key to encrypt the clone.
In the Google Cloud console, go to the Disks page.
In the list of zonal persistent disks, find the disk that you want to clone.
In the Actions column, click the
menu button and select Clone disk.In the Clone disk panel that appears, do the following:
To create a disk clone for a CSEK-encrypted source disk, run the gcloud compute disks create
command and provide the source disk encryption key using the --csek-key-file
flag. If you are using an RSA-wrapped key, use the gcloud beta compute disks create
command.
gcloud compute disks create TARGET_DISK_NAME \ --description="cloned disk" \ --source-disk=projects/PROJECT_ID/zones/ZONE/disks/SOURCE_DISK_NAME \ --csek-key-file example-key-file.json
Replace the following:
TARGET_DISK_NAME
: the name for the new disk.PROJECT_ID
: the project ID where you want to clone the disk.ZONE
: the zone of the source and new disk.SOURCE_DISK_NAME
: the name of the source diskBefore trying this sample, follow the Go setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Go API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Before trying this sample, follow the Java setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Java API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Before trying this sample, follow the Python setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Python API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
To create a disk clone for a CSEK-encrypted source disk, make a POST
request to the compute.disks.insert
method and provide the source disk encryption key using the diskEncryptionKey
property. If you are using an RSA-wrapped key, use the beta
version of the method.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/disks { "name": "TARGET_DISK_NAME" "sourceDisk": "projects/PROJECT_ID/zones/ZONE/disks/SOURCE_DISK_NAME" "diskEncryptionKey": { "rsaEncryptedKey": "ieCx/NcW06PcT7Ep1X6LUTc/hLvUDYyzSZPPVCVPTVEohpeHASqC8uw5TzyO9U+Fka9JFHz0mBibXUInrC/jEk014kCK/NPjYgEMOyssZ4ZINPKxlUh2zn1bV+MCaTICrdmuSBTWlUUiFoDD6PYznLwh8ZNdaheCeZ8ewEXgFQ8V+sDroLaN3Xs3MDTXQEMMoNUXMCZEIpg9Vtp9x2oeQ5lAbtt7bYAAHf5l+gJWw3sUfs0/Glw5fpdjT8Uggrr+RMZezGrltJEF293rvTIjWOEB3z5OHyHwQkvdrPDFcTqsLfh+8Hr8g+mf+7zVPEC8nEbqpdl3GPv3A7AwpFp7MA==" }, }
Replace the following:
PROJECT_ID
: the project ID where you want to clone the disk.ZONE
: the zone of the source and new disk.TARGET_DISK_NAME
: the name for the new disk.SOURCE_DISK_NAME
: the name of the source diskIf you use a CMEK to encrypt your source disk, you must also use the same key to encrypt the clone.
Compute Engine automatically encrypts the clone using the source disk encryption key.
To create a disk clone for a CMEK-encrypted source disk, run the gcloud compute disks create
command and provide the source disk encryption key using the --kms-key
flag. If you are using an RSA-wrapped key, use the gcloud beta compute disks create
command.
gcloud compute disks create TARGET_DISK_NAME \ --description="cloned disk" \ --source-disk=projects/PROJECT_ID/zones/ZONE/disks/SOURCE_DISK_NAME \ --kms-key projects/KMS_PROJECT_ID/locations/REGION/keyRings/KEY_RING/cryptoKeys/KEY
Replace the following:
TARGET_DISK_NAME
: the name for the new disk.PROJECT_ID
: the project ID where you want to clone the disk.ZONE
: the zone of the source and new disk.SOURCE_DISK_NAME
: the name of the source disk.KMS_PROJECT_ID
: the project ID for the encryption key.REGION
: the region of the encryption key.KEY_RING
: the key ring of the encryption key.KEY
: the name of the encryption key.Before trying this sample, follow the Go setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Go API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Before trying this sample, follow the Java setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Java API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Before trying this sample, follow the Python setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Python API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
To create a disk clone for a CMEK-encrypted source disk, make a POST
request to the compute.disks.insert
method and provide the source disk encryption key using the kmsKeyName
property. If you are using an RSA-wrapped key, use the beta
version of the method.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/disks { "name": "TARGET_DISK_NAME" "sourceDisk": "projects/PROJECT_ID/zones/ZONE/disks/SOURCE_DISK_NAME" "diskEncryptionKey": { "kmsKeyName": "projects/KMS_PROJECT_ID/locations/REGION/keyRings/KEY_RING/cryptoKeys/KEY" }, }
Replace the following:
PROJECT_ID
: the project ID where you want to clone the disk.ZONE
: the zone of the source and new disk.TARGET_DISK_NAME
: the name for the new disk.SOURCE_DISK_NAME
: the name of the source disk.KMS_PROJECT_ID
: the project ID for the encryption key.REGION
: the region of the encryption key.KEY_RING
: the key ring of the encryption key.KEY
: the name of the encryption key.Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-04-25 UTC.