@hashicorp
The googlecompute plugin can be used with HashiCorp Packer to create custom images on GCE.
- Official
Updated 3 months ago
- GitHub(opens in new tab)
Google Cloud Platform Image Import
Type: googlecompute-import
Artifact BuilderId: packer.post-processor.googlecompute-import
The Google Compute Image Import post-processor takes a compressed raw disk image and imports it to a GCE image available to Google Compute Engine.
This post-processor is for advanced users. Please ensure you read the GCE import documentation before using this post-processor.
How Does it Work?
The import process operates by uploading a temporary copy of the compressed raw disk image to a GCS bucket, and calling an import task in GCP on the raw disk file. Once completed, a GCE image is created containing the converted virtual machine. The temporary raw disk image copy in GCS can be discarded after the import is complete.
Google Cloud has very specific requirements for images being imported. Please see the GCE import documentation for details.
Note: To prevent Packer from deleting the compressed RAW disk image set the keep_input_artifact
configuration option to true
.
See Post-Processor Input Artifacts for more details.
Configuration
Required
project_id
(string) - The project ID where the GCS bucket exists and where the GCE image is stored.bucket
(string) - The name of the GCS bucket where the raw disk image will be uploaded.image_name
(string) - The unique name of the resulting image.
Optional
access_token
(string) - A temporary OAuth 2.0 access tokenaccount_file
(string) - The JSON file containing your account credentials. If specified, the account file will take precedence over anygooglecompute
builder authentication method.impersonate_service_account
(string) - This allows service account impersonation as per the docs.scopes
([]string) - The service account scopes for launched importer post-processor instance. Defaults to:gcs_object_name
(string) - The name of the GCS object inbucket
where the RAW disk image will be copied for import. This is treated as a template engine. Therefore, you may use user variables and template functions in this field. Defaults topacker-import-{{timestamp}}.tar.gz
.image_architecture
(string) - Specifies the architecture or processor type that this image can support. Must be one of:arm64
orx86_64
. Defaults toARCHITECTURE_UNSPECIFIED
.image_description
(string) - The description of the resulting image.image_family
(string) - The name of the image family to which the resulting image belongs.image_guest_os_features
([]string) - A list of features to enable on the guest operating system. Applicable only for bootable images. Valid values areMULTI_IP_SUBNET
,UEFI_COMPATIBLE
,VIRTIO_SCSI_MULTIQUEUE
,GVNIC
andWINDOWS
currently.image_labels
(map[string]string) - Key/value pair labels to apply to the created image.image_storage_locations
([]string) - Specifies a Cloud Storage location, either regional or multi-regional, where image content is to be stored. If not specified, the multi-region location closest to the source is chosen automatically.skip_clean
(bool) - Skip removing the TAR file uploaded to the GCS bucket after the import process has completed. "true" means that we should leave it in the GCS bucket, "false" means to clean it out. Defaults tofalse
.vault_gcp_oauth_engine
(string) - Vault GCP Oauth Engineimage_platform_key
(string) - A key used to establish the trust relationship between the platform owner and the firmware. You may only specify one platform key, and it must be a valid X.509 certificate.image_key_exchange_key
([]string) - A key used to establish a trust relationship between the firmware and the OS. You may specify multiple comma-separated keys for this value.image_signatures_db
([]string) - A database of certificates that are trusted and can be used to sign boot files. You may specify single or multiple comma-separated values for this value.image_forbidden_signatures_db
([]string) - A database of certificates that have been revoked and will cause the system to stop booting if a boot file is signed with one of them. You may specify single or multiple comma-separated values for this value.
Basic Example
Here is a basic example. This assumes that the builder has produced an compressed raw disk image artifact for us to work with, and that the GCS bucket has been created.
HCL
JSON
QEMU Builder Example
Here is a complete example for building a Fedora 31 server GCE image. For this example Packer was run from a Debian Linux host with KVM installed.
HCL2
JSON