blob: c426334cf4953146bda8ac940c53929a376df2f8 [file] [log] [blame]
---
# ----------------------------------------------------------------------------
#
# *** AUTO GENERATED CODE *** Type: MMv1 ***
#
# ----------------------------------------------------------------------------
#
# This file is automatically generated by Magic Modules and manual
# changes will be clobbered when the file is regenerated.
#
# Please read more about how to change this file in
# .github/CONTRIBUTING.md.
#
# ----------------------------------------------------------------------------
subcategory: "Compute Engine"
description: |-
Represents a Persistent Disk Snapshot resource.
---
# 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:
* [API documentation](https://cloud.google.com/compute/docs/reference/rest/v1/snapshots)
* How-to Guides
* [Official Documentation](https://cloud.google.com/compute/docs/disks/create-snapshots)
~> **Warning:** All arguments including the following potentially sensitive
values will be stored in the raw state as plain text: `snapshot_encryption_key.raw_key`, `source_disk_encryption_key.raw_key`.
[Read more about sensitive data in state](https://www.terraform.io/language/state/sensitive-data).
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=snapshot_basic&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## Example Usage - Snapshot Basic
```hcl
resource "google_compute_snapshot" "snapshot" {
name = "my-snapshot"
source_disk = google_compute_disk.persistent.id
zone = "us-central1-a"
labels = {
my_label = "value"
}
storage_locations = ["us-central1"]
}
data "google_compute_image" "debian" {
family = "debian-11"
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"
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=snapshot_chainname&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## Example Usage - Snapshot Chainname
```hcl
resource "google_compute_snapshot" "snapshot" {
name = "my-snapshot"
source_disk = google_compute_disk.persistent.id
zone = "us-central1-a"
chain_name = "snapshot-chain"
labels = {
my_label = "value"
}
storage_locations = ["us-central1"]
}
data "google_compute_image" "debian" {
family = "debian-11"
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.
- - -
* `chain_name` -
(Optional)
Creates the new snapshot in the snapshot chain labeled with the
specified name. The chain name must be 1-63 characters long and
comply with RFC1035. This is an uncommon option only for advanced
service owners who needs to create separate snapshot chains, for
example, for chargeback tracking. When you describe your snapshot
resource, this field is visible only if it has a non-empty value.
* `description` -
(Optional)
An optional description of this resource.
* `storage_locations` -
(Optional)
Cloud Storage bucket storage location of the snapshot (regional or multi-regional).
* `labels` -
(Optional)
Labels to apply to this Snapshot.
**Note**: This field is non-authoritative, and will only manage the labels present in your configuration.
Please refer to the field `effective_labels` for all of the labels present on the resource.
* `zone` -
(Optional)
A reference to the zone where the disk is hosted.
* `snapshot_encryption_key` -
(Optional)
Encrypts the snapshot using a customer-supplied encryption key.
After you encrypt a snapshot using a customer-supplied key, you must
provide the same key if you use the snapshot later. For example, you
must provide the encryption key when you create a disk from the
encrypted snapshot in a future request.
Customer-supplied encryption keys do not protect access to metadata of
the snapshot.
If you do not provide an encryption key when creating the snapshot,
then the snapshot will be encrypted using an automatically generated
key and you do not need to provide a key to use the snapshot later.
Structure is [documented below](#nested_snapshot_encryption_key).
* `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](#nested_source_disk_encryption_key).
* `project` - (Optional) The ID of the project in which the resource belongs.
If it is not provided, the provider project is used.
<a name="nested_snapshot_encryption_key"></a>The `snapshot_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.
**Note**: This property is sensitive and will not be displayed in the plan.
* `sha256` -
(Output)
The RFC 4648 base64 encoded SHA-256 hash of the customer-supplied
encryption key that protects this resource.
* `kms_key_self_link` -
(Optional)
The name of the encryption key that is stored in Google Cloud KMS.
* `kms_key_service_account` -
(Optional)
The service account used for the encryption request for the given KMS key.
If absent, the Compute Engine Service Agent service account is used.
<a name="nested_source_disk_encryption_key"></a>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.
**Note**: This property is sensitive and will not be displayed in the plan.
* `kms_key_service_account` -
(Optional)
The service account used for the encryption request for the given KMS key.
If absent, the Compute Engine Service Agent service account is used.
## Attributes Reference
In addition to the arguments listed above, the following computed attributes are exported:
* `id` - an identifier for the resource with format `projects/{{project}}/global/snapshots/{{name}}`
* `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 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.
* `terraform_labels` -
The combination of labels configured directly on the resource
and default labels configured on the provider.
* `effective_labels` -
All of labels (key/value pairs) present on the resource in GCP, including the labels configured through Terraform, other clients and services.
* `self_link` - The URI of the created resource.
## Timeouts
This resource provides the following
[Timeouts](https://developer.hashicorp.com/terraform/plugin/sdkv2/resources/retries-and-customizable-timeouts) configuration options:
- `create` - Default is 20 minutes.
- `update` - Default is 20 minutes.
- `delete` - Default is 20 minutes.
## Import
Snapshot can be imported using any of these accepted formats:
* `projects/{{project}}/global/snapshots/{{name}}`
* `{{project}}/{{name}}`
* `{{name}}`
In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import Snapshot using one of the formats above. For example:
```tf
import {
id = "projects/{{project}}/global/snapshots/{{name}}"
to = google_compute_snapshot.default
}
```
When using the [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import), Snapshot can be imported using one of the formats above. For example:
```
$ 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](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference#user_project_override).