packer-cn/website/pages/docs/post-processors/googlecompute-import.mdx

154 lines
5.0 KiB
Plaintext
Raw Normal View History

---
description: |
2020-03-18 18:46:47 -04:00
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.
layout: docs
2020-03-18 18:46:47 -04:00
page_title: Google Compute Image Import - Post-Processors
sidebar_current: docs-post-processors-googlecompute-import
---
# Google Compute Image Import Post-Processor
Type: `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.
2020-03-23 20:02:12 -04:00
~> This post-processor is for advanced users. Please ensure you read the
[GCE import documentation](https://cloud.google.com/compute/docs/images/import-existing-image)
2018-10-26 20:02:51 -04:00
before using this post-processor.
## How Does it Work?
2018-10-26 20:02:51 -04:00
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
2020-03-23 20:02:12 -04:00
machine. The temporary raw disk image copy in GCS can be discarded after the import is complete.
2018-10-26 20:02:51 -04:00
Google Cloud has very specific requirements for images being imported. Please
2020-03-23 20:02:12 -04:00
see the [GCE import documentation](https://cloud.google.com/compute/docs/images/import-existing-image)
for details.
## Configuration
### Required
2020-03-18 18:46:47 -04:00
- `account_file` (string) - The JSON file containing your account
credentials.
2020-03-18 18:46:47 -04:00
- `bucket` (string) - The name of the GCS bucket where the raw disk image
will be uploaded.
2020-03-18 18:46:47 -04:00
- `image_name` (string) - The unique name of the resulting image.
2020-03-18 18:46:47 -04:00
- `project_id` (string) - The project ID where the GCS bucket exists and
where the GCE image is stored.
### Optional
2020-03-18 18:46:47 -04:00
- `gcs_object_name` (string) - The name of the GCS object in `bucket` where
the RAW disk image will be copied for import. This is treated as a
[template engine](/docs/templates/engine.html). Therefore, you
may use user variables and template functions in this field. Defaults to
2020-03-23 20:02:12 -04:00
`packer-import-{{timestamp}}.tar.gz`.
2020-03-18 18:46:47 -04:00
- `image_description` (string) - The description of the resulting image.
2020-03-18 18:46:47 -04:00
- `image_family` (string) - The name of the image family to which the
resulting image belongs.
2020-03-18 18:46:47 -04:00
- `image_labels` (object of key/value strings) - Key/value pair labels to
apply to the created image.
2020-03-18 18:46:47 -04:00
- `image_guest_os_features` (array of strings) - A list of features to enable
on the guest operating system. Applicable only for bootable images. Valid
values are `MULTI_IP_SUBNET`, `SECURE_BOOT`, `UEFI_COMPATIBLE`,
`VIRTIO_SCSI_MULTIQUEUE` and `WINDOWS` currently.
2020-03-18 18:46:47 -04:00
- `keep_input_artifact` (boolean) - if true, do not delete the compressed RAW
disk image. Defaults to false.
2020-03-18 18:46:47 -04:00
- `skip_clean` (boolean) - 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 to
`false`.
## Basic Example
2018-10-26 20:02:51 -04:00
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.
```json
{
"type": "googlecompute-import",
"account_file": "account.json",
"project_id": "my-project",
"bucket": "my-bucket",
"image_name": "my-gce-image"
}
```
## QEMU Builder Example
2018-10-26 20:02:51 -04:00
Here is a complete example for building a Fedora 28 server GCE image. For this
example packer was run from a CentOS 7 server with KVM installed. The CentOS 7
server was running in GCE with the nested hypervisor feature enabled.
2018-10-26 20:02:51 -04:00
$ packer build -var serial=$(tty) build.json
```json
{
"variables": {
"serial": ""
},
"builders": [
{
"type": "qemu",
"accelerator": "kvm",
"communicator": "none",
2020-03-18 18:46:47 -04:00
"boot_command": [
"<tab> console=ttyS0,115200n8 inst.text inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/fedora-28-ks.cfg rd.live.check=0<enter><wait>"
],
"disk_size": "15000",
"format": "raw",
"iso_checksum_type": "sha256",
"iso_checksum": "ea1efdc692356b3346326f82e2f468903e8da59324fdee8b10eac4fea83f23fe",
"iso_url": "https://download-ib01.fedoraproject.org/pub/fedora/linux/releases/28/Server/x86_64/iso/Fedora-Server-netinst-x86_64-28-1.1.iso",
"headless": "true",
"http_directory": "http",
"http_port_max": "10089",
"http_port_min": "10082",
"output_directory": "output",
"shutdown_timeout": "30m",
"vm_name": "disk.raw",
"qemu_binary": "/usr/libexec/qemu-kvm",
"qemuargs": [
2020-03-18 18:46:47 -04:00
["-m", "1024"],
["-cpu", "host"],
["-chardev", "tty,id=pts,path={{user `serial`}}"],
["-device", "isa-serial,chardev=pts"],
["-device", "virtio-net,netdev=user.0"]
]
}
],
"post-processors": [
[
{
"type": "compress",
"output": "output/disk.raw.tar.gz"
},
{
"type": "googlecompute-import",
"project_id": "my-project",
"account_file": "account.json",
"bucket": "my-bucket",
"image_name": "fedora28-server-{{timestamp}}",
"image_description": "Fedora 28 Server",
"image_family": "fedora28-server"
}
]
]
}
```