Method: instances.attachDisk

Attaches an existing Disk resource to an instance. You must first create the disk before you can attach it. It is not possible to create and attach a disk at the same time. For more information, read Adding a persistent disk to your instance.

HTTP request

POST https://compute.googleapis.com/compute/beta/projects/{project}/zones/{zone}/instances/{resourceId}/attachDisk

The URL uses gRPC Transcoding syntax.

Path parameters

Parameters
project

string

Project ID for this request.

zone

string

The name of the zone for this request.

resourceId

string

The instance name for this request.

Query parameters

Parameters
requestId

string

An optional request ID to identify requests. Specify a unique request ID so that if you must retry your request, the server will know to ignore the request if it has already been completed.

For example, consider a situation where you make an initial request and the request times out. If you make the request again with the same request ID, the server can check if original operation with the same request ID was received, and if so, will ignore the second request. This prevents clients from accidentally creating duplicate commitments.

The request ID must be a valid UUID with the exception that zero UUID is not supported (00000000-0000-0000-0000-000000000000).

forceAttach

boolean

Whether to force attach the regional disk even if it's currently attached to another instance. If you try to force attach a zonal disk to an instance, you will receive an error.

Request body

The request body contains data with the following structure:

JSON representation
{
  "type": enum,
  "mode": enum,
  "source": string,
  "deviceName": string,
  "index": integer,
  "boot": boolean,
  "initializeParams": {
    "diskName": string,
    "sourceImage": string,
    "diskSizeGb": string,
    "diskType": string,
    "sourceImageEncryptionKey": {
      "sha256": string,
      "kmsKeyServiceAccount": string,

      
      "rawKey": string,
      "rsaEncryptedKey": string,
      "kmsKeyName": string
      
    },
    "labels": {
      string: string,
      ...
    },
    "sourceSnapshot": string,
    "sourceSnapshotEncryptionKey": {
      "sha256": string,
      "kmsKeyServiceAccount": string,

      
      "rawKey": string,
      "rsaEncryptedKey": string,
      "kmsKeyName": string
      
    },
    "description": string,
    "guestOsFeatures": [
      {
        "type": enum
      }
    ],
    "resourcePolicies": [
      string
    ],
    "onUpdateAction": enum,
    "provisionedIops": string,
    "multiWriter": boolean
  },
  "autoDelete": boolean,
  "licenses": [
    string
  ],
  "interface": enum,
  "guestOsFeatures": [
    {
      "type": enum
    }
  ],
  "diskEncryptionKey": {
    "rawKey": string,
    "rsaEncryptedKey": string,
    "kmsKeyName": string,
    "sha256": string,
    "kmsKeyServiceAccount": string
  },
  "diskSizeGb": string,
  "shieldedInstanceInitialState": {
    "pk": {
      "content": string,
      "fileType": enum
    },
    "keks": [
      {
        "content": string,
        "fileType": enum
      }
    ],
    "dbs": [
      {
        "content": string,
        "fileType": enum
      }
    ],
    "dbxs": [
      {
        "content": string,
        "fileType": enum
      }
    ]
  },
  "userLicenses": [
    string
  ],
  "locked": boolean,
  "kind": string
}
Fields
type

enum

Specifies the type of the disk, either SCRATCH or PERSISTENT. If not specified, the default is PERSISTENT.

mode

enum

The mode in which to attach this disk, either READ_WRITE or READ_ONLY. If not specified, the default is to attach the disk in READ_WRITE mode.

source

string

Specifies a valid partial or full URL to an existing Persistent Disk resource. When creating a new instance, one of initializeParams.sourceImage or initializeParams.sourceSnapshot or disks.source is required except for local SSD.

If desired, you can also attach existing non-root persistent disks using this property. This field is only applicable for persistent disks.

Note that for InstanceTemplate, specify the disk name, not the URL for the disk.

Authorization requires one or more of the following IAM permissions on the specified resource source:

  • compute.disks.use
  • compute.disks.useReadOnly
deviceName

string

Specifies a unique device name of your choice that is reflected into the /dev/disk/by-id/google-* tree of a Linux operating system running within the instance. This name can be used to reference the device for mounting, resizing, and so on, from within the instance.

If not specified, the server chooses a default device name to apply to this disk, in the form persistent-disk-x, where x is a number assigned by Google Compute Engine. This field is only applicable for persistent disks.

index

integer

[Output Only] A zero-based index to this disk, where 0 is reserved for the boot disk. If you have many disks attached to an instance, each disk would have a unique index number.

boot

boolean

Indicates that this is a boot disk. The virtual machine will use the first partition of the disk for its root filesystem.

initializeParams

object

[Input Only] Specifies the parameters for a new disk that will be created alongside the new instance. Use initialization parameters to create boot disks or local SSDs attached to the new instance.

This property is mutually exclusive with the source property; you can only define one or the other, but not both.

initializeParams.diskName

string

Specifies the disk name. If not specified, the default is to use the name of the instance. If a disk with the same name already exists in the given region, the existing disk is attached to the new instance and the new disk is not created.

initializeParams.sourceImage

string

The source image to create this disk. When creating a new instance, one of initializeParams.sourceImage or initializeParams.sourceSnapshot or disks.source is required except for local SSD.

To create a disk with one of the public operating system images, specify the image by its family name. For example, specify family/debian-9 to use the latest Debian 9 image:

projects/debian-cloud/global/images/family/debian-9

Alternatively, use a specific version of a public operating system image:

projects/debian-cloud/global/images/debian-9-stretch-vYYYYMMDD

To create a disk with a custom image that you created, specify the image name in the following format:

global/images/my-custom-image

You can also specify a custom image by its image family, which returns the latest version of the image in that family. Replace the image name with family/family-name:

global/images/family/my-image-family

If the source image is deleted later, this field will not be set.

Authorization requires one or more of the following IAM permissions on the specified resource sourceImage:

  • compute.disks.create
  • compute.images.useReadOnly
initializeParams.diskSizeGb

string (int64 format)

Specifies the size of the disk in base-2 GB. The size must be at least 10 GB. If you specify a sourceImage, which is required for boot disks, the default size is the size of the sourceImage. If you do not specify a sourceImage, the default disk size is 500 GB.

initializeParams.diskType

string

Specifies the disk type to use to create the instance. If not specified, the default is pd-standard, specified using the full URL. For example:

https://www.googleapis.com/compute/v1/projects/project/zones/zone/diskTypes/pd-standard

For a full list of acceptable values, see Persistent disk types. If you define this field, you can provide either the full or partial URL. For example, the following are valid values:

Note that for InstanceTemplate, this is the name of the disk type, not URL.

initializeParams.sourceImageEncryptionKey

object

The customer-supplied encryption key of the source image. Required if the source image is protected by a customer-supplied encryption key.

Instance templates do not store customer-supplied encryption keys, so you cannot create disks for instances in a managed instance group if the source images are encrypted with your own keys.

initializeParams.sourceImageEncryptionKey.rawKey

string

Specifies a 256-bit customer-supplied encryption key, encoded in RFC 4648 base64 to either encrypt or decrypt this resource.

initializeParams.sourceImageEncryptionKey.rsaEncryptedKey

string

Specifies an RFC 4648 base64 encoded, RSA-wrapped 2048-bit customer-supplied encryption key to either encrypt or decrypt this resource.

The key must meet the following requirements before you can provide it to Compute Engine:

  1. The key is wrapped using a RSA public key certificate provided by Google.
  2. After being wrapped, the key must be encoded in RFC 4648 base64 encoding.
Gets the RSA public key certificate provided by Google at:
https://cloud-certs.storage.googleapis.com/google-cloud-csek-ingress.pem

initializeParams.sourceImageEncryptionKey.kmsKeyName

string

The name of the encryption key that is stored in Google Cloud KMS.

initializeParams.sourceImageEncryptionKey.sha256

string

[Output only] The RFC 4648 base64 encoded SHA-256 hash of the customer-supplied encryption key that protects this resource.

initializeParams.sourceImageEncryptionKey.kmsKeyServiceAccount

string

The service account being used for the encryption request for the given KMS key. If absent, the Compute Engine default service account is used.

initializeParams.labels

map (key: string, value: string)

Labels to apply to this disk. These can be later modified by the disks.setLabels method. This field is only applicable for persistent disks.

An object containing a list of "key": value pairs. Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.

initializeParams.sourceSnapshot

string

The source snapshot to create this disk. When creating a new instance, one of initializeParams.sourceSnapshot or initializeParams.sourceImage or disks.source is required except for local SSD.

To create a disk with a snapshot that you created, specify the snapshot name in the following format:

global/snapshots/my-backup

If the source snapshot is deleted later, this field will not be set.

initializeParams.sourceSnapshotEncryptionKey

object

The customer-supplied encryption key of the source snapshot.

initializeParams.sourceSnapshotEncryptionKey.rawKey

string

Specifies a 256-bit customer-supplied encryption key, encoded in RFC 4648 base64 to either encrypt or decrypt this resource.

initializeParams.sourceSnapshotEncryptionKey.rsaEncryptedKey

string

Specifies an RFC 4648 base64 encoded, RSA-wrapped 2048-bit customer-supplied encryption key to either encrypt or decrypt this resource.

The key must meet the following requirements before you can provide it to Compute Engine:

  1. The key is wrapped using a RSA public key certificate provided by Google.
  2. After being wrapped, the key must be encoded in RFC 4648 base64 encoding.
Gets the RSA public key certificate provided by Google at: