Google Compute Engine Disk

This page shows how to write Terraform for Compute Engine Disk and write them securely.

google_compute_disk (Terraform)

The Disk in Compute Engine can be configured in Terraform with the resource name google_compute_disk. The following sections describe 1 example of how to use the resource and its parameters.

Example Usage from GitHub
resource "google_compute_disk" "neo-database-01-disk" {
  name  = "neo-database-01-disk"
  type  = "pd-ssd"
  zone  = "us-east1-b"
  size  = "100"

Review your Terraform file for Google best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Security Best Practices for google_compute_disk

There are 2 settings in google_compute_disk that should be taken care of for security reasons. The following section explain an overview and example code.


Ensure the encryption key for your GCE disk is stored securely

It is better to store the encryption key for your GCE disk securely. Secret Manager could be used instead.


Ensure your GCE disk is encrypted

It is better to encrypt GCE disk. Encryption reduces the risk of data leakage.

Review your Google Compute Engine settings

You can check if the google_compute_disk setting in your .tf file is correct in 3 min with Shisho Cloud.


Creation timestamp in RFC3339 text format.

An optional description of this resource. Provide this property when you create the resource.

  • id optional computed - string
  • image optional - string

The image from which to initialize this disk. This can be one of: the image's 'self_link', 'projects/[project]/global/images/[image]', 'projects/[project]/global/images/family/[family]', 'global/images/[image]', 'global/images/family/[family]', 'family/[family]', '[project]/[family]', '[project]/[image]', '[family]', or '[image]'. If referred by family, the images names must include the family name. If they don't, use the google_compute_image data source. For instance, the image 'centos-6-v20180104' includes its family name 'centos-6'. These images can be referred by family name here.

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

  • labels optional - map from string to string

Labels to apply to this disk. A list of key->value pairs.

Last attach timestamp in RFC3339 text format.

Last detach timestamp in RFC3339 text format.

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?' 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.

Physical block size of the persistent disk, in bytes. If not present in a request, a default value is used. Currently supported sizes are 4096 and 16384, other sizes may be added in the future. If an unsupported value is requested, the error message will list the supported values for the caller's project.

Size of the persistent disk, specified in GB. You can specify this field when creating a persistent disk using the 'image' or 'snapshot' parameter, or specify it alone to create an empty persistent disk. If you specify this field along with 'image' or 'snapshot', the value must not be less than the size of the image or the size of the snapshot. ~>NOTE If you change the size, Terraform updates the disk size if upsizing is detected but recreates the disk if downsizing is requested. You can add 'lifecycle.prevent_destroy' in the config to prevent destroying and recreating.

The source snapshot used to create this disk. You can provide this as a partial or full URL to the resource. If the snapshot is in another project than this disk, you must supply a full URL. For example, the following are valid values: '' 'projects/project/global/snapshots/snapshot' 'global/snapshots/snapshot' 'snapshot'

The ID value of the image used to create this disk. This value identifies the exact image that was used to create this persistent disk. For example, if you created the persistent disk from an image that was later deleted and recreated under the same name, the source image ID would identify the exact version of the image that was used.

The unique ID of the snapshot used to create this disk. This value identifies the exact snapshot that was used to create this persistent disk. For example, if you created the persistent disk from a snapshot that was later deleted and recreated under the same name, the source snapshot ID would identify the exact version of the snapshot that was used.

URL of the disk type resource describing which disk type to use to create the disk. Provide this when creating the disk.

  • users optional computed - list of string

Links to the users of the disk (attached instances) in form: project/zones/zone/instances/instance

  • zone optional computed - string

A reference to the zone where the disk resides.

Explanation in Terraform Registry

Persistent disks are durable storage devices that function similarly to the physical disks in a desktop or a server. Compute Engine manages the hardware behind these devices to ensure data redundancy and optimize performance for you. Persistent disks are available as either standard hard disk drives (HDD) or solid-state drives (SSD). Persistent disks are located independently from your virtual machine instances, so you can detach or move persistent disks to keep your data even after you delete your instances. Persistent disk performance scales automatically with size, so you can resize your existing persistent disks or add more persistent disks to an instance to meet your performance and storage space requirements. Add a persistent disk to your instance when you need reliable and affordable storage with consistent performance characteristics. To get more information about Disk, see:

Tips: Best Practices for The Other Google Compute Engine Resources

In addition to the google_compute_firewall, Google Compute Engine has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.



Ensure your VPC firewall blocks unwanted outbound traffic

It is better to block unwanted outbound traffic not to expose resources in the VPC to unwanted attacks.



Ensure appropriate service account is assigned to your GCE instance

It is better to create a custom service account for the instance and assign it.



Ensure OS login for your GCE instances is enabled at project level

It is better to enable OS login for your GCE instances. Enabling OS login ensures that SSH keys used to connect to instances are mapped with IAM users, allowing centralized and automated SSH key management.



Ensure to use modern TLS protocols

It's better to adopt TLS v1.2+ instead of outdated TLS protocols.



Ensure VPC flow logging is enabled

It is better to enable VPC flow logging. VPC flow logging allows us to audit traffic in your network.

Review your Google Compute Engine settings

In addition to the above, there are other security points you should be aware of making sure that your .tf files are protected in Shisho Cloud.

Frequently asked questions

What is Google Compute Engine Disk?

Google Compute Engine Disk is a resource for Compute Engine of Google Cloud Platform. Settings can be wrote in Terraform.

Where can I find the example code for the Google Compute Engine Disk?

For Terraform, the NarrativeCompany/narrative-infrastructure source code example is useful. See the Terraform Example section for further details.