Packer
Google Cloud Platform
@hashicorp
The googlecompute plugin can be used with HashiCorp Packer to create custom images on GCE.
- Official
- HCP Ready
Updated 2 years ago
- GitHub(opens in new tab)
GCE Image
Type: googlecompute-image
The Google Compute Image data source filters and fetches a GCE image and outputs relevant image metadata for use with Google Compute builders.
Note: Data sources is a feature exclusively available to HCL2 templates.
Basic example of usage:
data "googlecompute-image" "basic-example" {
project_id = "debian-cloud"
filters = "family=debian-12 AND labels.public-image=true"
most_recent = true
}
This configuration selects the most recent GCE image from the debian-cloud
project that belongs to thedebian-12
family and has the public-image
label set to true
.
The data source will fail unless exactly one image is matched. Setting most_recent = true
ensures only the newest image is selected when multiple matches exist.
Configuration Reference
project_id
(string) - The Google Cloud project ID to search for images.filters
(string) - The filter expression to narrow down the image search. For example: "name=ubuntu" or "family=ubuntu-2004". The exrpressions can be combined with AND/OR like this: "name=ubuntu AND family=ubuntu-2004". See https://cloud.google.com/sdk/gcloud/reference/topic/filtersmost_recent
(bool) - If true, the most recent image will be returned. If false, an error will be returned if more than one image matches the filters.
Output Data
id
(string) - IDname
(string) - Namecreation_date
(string) - Creation Datelabels
(map[string]string) - Labels
Authentication
To authenticate with GCE, this data-source supports everything the plugin does. To get more information on this, refer to the plugin's description page, under the authentication section.