Google Compute Engine Region Disk
This page shows how to write Terraform for Compute Engine Region Disk and write them securely.
google_compute_region_disk (Terraform)
The Region Disk in Compute Engine can be configured in Terraform with the resource name google_compute_region_disk
. The following sections describe 1 example of how to use the resource and its parameters.
Example Usage from GitHub
resource "google_compute_region_disk" "this" {
description = var.description
labels = var.labels
name = var.name
physical_block_size_bytes = var.physical_block_size_bytes
project = var.project
Parameters
-
creation_timestamp
optional computed - string
Creation timestamp in RFC3339 text format.
-
description
optional - string
An optional description of this resource. Provide this property when you create the resource.
-
id
optional computed - string -
label_fingerprint
optional computed - string
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
optional computed - string
Last attach timestamp in RFC3339 text format.
-
last_detach_timestamp
optional computed - string
Last detach timestamp in RFC3339 text format.
-
name
required - string
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_bytes
optional computed - number
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.
A reference to the region where the disk resides.
-
replica_zones
required - list of string
URLs of the zones where the disk should be replicated to.
Size of the persistent disk, specified in GB. You can specify this field when creating a persistent disk using the sourceImage or sourceSnapshot parameter, or specify it alone to create an empty persistent disk. If you specify this field along with sourceImage or sourceSnapshot, the value of sizeGb must not be less than the size of the sourceImage or the size of the snapshot.
-
snapshot
optional - string
The source snapshot used to create this disk. You can provide this as a partial or full URL to the resource. For example, the following are valid values: 'https://www.googleapis.com/compute/v1/projects/project/global/snapshots/snapshot' 'projects/project/global/snapshots/snapshot' 'global/snapshots/snapshot' 'snapshot'
-
source_snapshot_id
optional computed - string
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.
-
type
optional - string
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
-
disk_encryption_key
list block-
raw_key
optional - string
Specifies a 256-bit customer-supplied encryption key, encoded in RFC 4648 base64 to either encrypt or decrypt this resource.
-
sha256
optional computed - string
The RFC 4648 base64 encoded SHA-256 hash of the customer-supplied encryption key that protects this resource.
-
-
source_snapshot_encryption_key
list block-
raw_key
optional - string
Specifies a 256-bit customer-supplied encryption key, encoded in RFC 4648 base64 to either encrypt or decrypt this resource.
-
sha256
optional computed - string
The RFC 4648 base64 encoded SHA-256 hash of the customer-supplied encryption key that protects this resource.
-
-
timeouts
single block
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 RegionDisk, see:
- API documentation
- How-to Guides
- Adding or Resizing Regional Persistent Disks
Warning: All arguments including
disk_encryption_key.raw_key
will be stored in the raw state as plain-text. Read more about sensitive data in state.
Tips: Best Practices for The Other Google Compute Engine Resources
In addition to the google_compute_disk, Google Compute Engine has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.
google_compute_disk
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.
google_compute_firewall
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.
google_compute_instance
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.
google_compute_project_metadata
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.
google_compute_ssl_policy
Ensure to use modern TLS protocols
It's better to adopt TLS v1.2+ instead of outdated TLS protocols.
google_compute_subnetwork
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.
Frequently asked questions
What is Google Compute Engine Region Disk?
Google Compute Engine Region 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 Region Disk?
For Terraform, the niveklabs/google source code example is useful. See the Terraform Example section for further details.