Google Compute Engine Image
This page shows how to write Terraform for Compute Engine Image and write them securely.
google_compute_image (Terraform)
The Image in Compute Engine can be configured in Terraform with the resource name google_compute_image
. The following sections describe 3 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "google_compute_image" "empty" {
name = "example-image"
}
resource "google_compute_disk" "disk" {
name = "test-disk"
resource "google_compute_image" "empty" {
name = "example-image"
}
resource "google_compute_disk" "disk" {
name = "test-disk"
resource "google_compute_image" "image_disk_size" {
name = "image_disk_size"
disk_size_gb = 30
}
resource "google_compute_disk" "image_disk_size" {
Parameters
-
archive_size_bytes
optional computed - number
Size of the image tar.gz archive stored in Google Cloud Storage (in bytes).
-
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.
-
disk_size_gb
optional computed - number
Size of the image when restored onto a persistent disk (in GB).
-
family
optional - string
The name of the image family to which this image belongs. You can create disks by specifying an image family instead of a specific image name. The image family always returns its latest image that is not deprecated. The name of the image family must comply with RFC1035.
-
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 Image.
-
licenses
optional computed - list of string
Any applicable license URI.
-
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.
-
project
optional computed - string -
self_link
optional computed - string -
source_disk
optional - string
The source disk to create this image based on. You must provide either this property or the rawDisk.source property but not both to create an image.
-
source_image
optional - string
URL of the source image used to create this image. In order to create an image, you must provide the full or partial URL of one of the following: The selfLink URL This property The rawDisk.source URL The sourceDisk URL
-
source_snapshot
optional - string
URL of the source snapshot used to create this image. In order to create an image, you must provide the full or partial URL of one of the following: The selfLink URL This property The sourceImage URL The rawDisk.source URL * The sourceDisk URL
-
guest_os_features
set block-
type
required - string
The type of supported feature. Read Enabling guest operating system features to see a list of available options. Possible values: ["MULTI_IP_SUBNET", "SECURE_BOOT", "SEV_CAPABLE", "UEFI_COMPATIBLE", "VIRTIO_SCSI_MULTIQUEUE", "WINDOWS", "GVNIC"]
-
-
raw_disk
list block-
container_type
optional - string
The format used to encode and transmit the block device, which should be TAR. This is just a container and transmission format and not a runtime format. Provided by the client when the disk image is created. Default value: "TAR" Possible values: ["TAR"]
-
sha1
optional - string
An optional SHA1 checksum of the disk image before unpackaging. This is provided by the client when the disk image is created.
-
source
required - string
The full Google Cloud Storage URL where disk storage is stored You must provide either this property or the sourceDisk property but not both.
-
-
timeouts
single block
Explanation in Terraform Registry
Represents an Image resource. Google Compute Engine uses operating system images to create the root persistent disks for your instances. You specify an image when you create an instance. Images contain a boot loader, an operating system, and a root file system. Linux operating system images are also capable of running containers on Compute Engine. Images can be either public or custom. Public images are provided and maintained by Google, open-source communities, and third-party vendors. By default, all projects have access to these images and can use them to create instances. Custom images are available only to your project. You can create a custom image from root persistent disks and other images. Then, use the custom image to create an instance. To get more information about Image, see:
- API documentation
- How-to Guides
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 Image?
Google Compute Engine Image 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 Image?
For Terraform, the infracost/infracost, gilyas/infracost and infracost/infracost source code examples are useful. See the Terraform Example section for further details.