» google_compute_snapshot

Represents a Persistent Disk Snapshot resource.

Use snapshots to back up data from your persistent disks. Snapshots are different from public images and custom images, which are used primarily to create instances or configure instance templates. Snapshots are useful for periodic backup of the data on your persistent disks. You can create snapshots from persistent disks even while they are attached to running instances.

Snapshots are incremental, so you can create regular snapshots on a persistent disk faster and at a much lower cost than if you regularly created a full image of the disk.

To get more information about Snapshot, see:

» Example Usage - Snapshot Basic

resource "google_compute_snapshot" "snapshot" {
  name        = "my-snapshot"
  source_disk = google_compute_disk.persistent.name
  zone        = "us-central1-a"
  labels = {
    my_label = "value"
  }
}

data "google_compute_image" "debian" {
  family  = "debian-9"
  project = "debian-cloud"
}

resource "google_compute_disk" "persistent" {
  name  = "debian-disk"
  image = data.google_compute_image.debian.self_link
  size  = 10
  type  = "pd-ssd"
  zone  = "us-central1-a"
}

» Argument Reference

The following arguments are supported:

  • name - (Required) Name of the resource; provided by the client when the resource is created. The name must be 1-63 characters long, and comply with RFC1035. Specifically, the name must be 1-63 characters long and match the regular expression [a-z]([-a-z0-9]*[a-z0-9])? which means the first character must be a lowercase letter, and all following characters must be a dash, lowercase letter, or digit, except the last character, which cannot be a dash.

  • source_disk - (Required) A reference to the disk used to create this snapshot.


  • description - (Optional) An optional description of this resource.

  • labels - (Optional) Labels to apply to this Snapshot.

  • zone - (Optional) A reference to the zone where the disk is hosted.

  • snapshot_encryption_key - (Optional) The customer-supplied encryption key of the snapshot. Required if the source snapshot is protected by a customer-supplied encryption key. Structure is documented below.

  • source_disk_encryption_key - (Optional) The customer-supplied encryption key of the source snapshot. Required if the source snapshot is protected by a customer-supplied encryption key. Structure is documented below.

  • project - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

The snapshot_encryption_key block supports:

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

  • sha256 - The RFC 4648 base64 encoded SHA-256 hash of the customer-supplied encryption key that protects this resource.

The source_disk_encryption_key block supports:

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

» Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:

  • creation_timestamp - Creation timestamp in RFC3339 text format.

  • snapshot_id - The unique identifier for the resource.

  • disk_size_gb - Size of the snapshot, specified in GB.

  • storage_bytes - A size of the the storage used by the snapshot. As snapshots share storage, this number is expected to change with snapshot creation/deletion.

  • licenses - A list of public visible licenses that apply to this snapshot. This can be because the original image had licenses attached (such as a Windows image). snapshotEncryptionKey nested object Encrypts the snapshot using a customer-supplied encryption key.

  • label_fingerprint - The fingerprint used for optimistic locking of this resource. Used internally during updates.

  • self_link - The URI of the created resource.

» Timeouts

This resource provides the following Timeouts configuration options:

  • create - Default is 5 minutes.
  • update - Default is 5 minutes.
  • delete - Default is 5 minutes.

» Import

Snapshot can be imported using any of these accepted formats:

$ terraform import google_compute_snapshot.default projects/{{project}}/global/snapshots/{{name}}
$ terraform import google_compute_snapshot.default {{project}}/{{name}}
$ terraform import google_compute_snapshot.default {{name}}

» User Project Overrides

This resource supports User Project Overrides.