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

209 lines
5.8 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.
page_title: Google Compute Image Import - Post-Processors
sidebar_title: Google Compute 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.
~> **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](https://www.packer.io/docs/templates/post-processors#input-artifacts) for more details.
## Configuration
### Required
@include 'post-processor/googlecompute-import/Config-required.mdx'
### Optional
@include 'post-processor/googlecompute-import/Config-not-required.mdx'
## 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.
<Tabs>
<Tab heading="JSON">
```json
{
"type": "googlecompute-import",
"account_file": "account.json",
"project_id": "my-project",
"bucket": "my-bucket",
"image_name": "my-gce-image"
}
```
</Tab>
<Tab heading="HCL">
```hcl
post-processor "googlecompute-import"{
account_file = "account.json"
bucket = "my-bucket"
project_id = "my-project"
image_name = "my-gce-image"
}
```
</Tab>
</Tabs>
## 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.
2018-10-26 20:02:51 -04:00
$ packer build -var serial=$(tty) build.json
<Tabs>
<Tab heading="JSON">
```json
{
"variables": {
"account_file": "account.json",
"bucket": "my-bucket",
"project": "my-project",
"serial": ""
},
"builders": [
{
"type": "qemu",
"accelerator": "kvm",
2020-03-18 18:46:47 -04:00
"boot_command": [
"<tab> console=ttyS0,115200n8 inst.text inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/fedora-31-ks.cfg rd.live.check=0<enter><wait>"
2020-03-18 18:46:47 -04:00
],
"disk_size": "15000",
"format": "raw",
"iso_checksum": "sha256:225ebc160e40bb43c5de28bad9680e3a78a9db40c9e3f4f42f3ee3f10f95dbeb",
"iso_url": "https://download-ib01.fedoraproject.org/pub/fedora/linux/releases/31/Server/x86_64/iso/Fedora-Server-dvd-x86_64-31-1.9.iso",
"headless": "true",
"http_directory": "http",
"http_port_max": "10089",
"http_port_min": "10082",
"output_directory": "output",
"shutdown_timeout": "30m",
"shutdown_command": "echo 'vagrant'|sudo -S shutdown -P now",
"ssh_username": "vagrant",
"ssh_password": "vagrant",
"vm_name": "disk.raw",
"qemu_binary": "/usr/bin/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": "{{user `project`}}",
"account_file": "{{user `account_file`}}",
"bucket": "{{user `bucket`}}",
"image_name": "fedora31-server-packertest",
"image_description": "Fedora 31 Server",
"image_family": "fedora31-server"
}
]
]
}
```
</Tab>
<Tab heading="HCL">
```hcl
variables {
account_file = "account.json"
bucket = "my-bucket"
project = "my-project"
serial = ""
}
source "qemu" "example" {
accelerator = "kvm"
boot_command = [
"<tab> console=ttyS0,115200n8 inst.text inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/fedora-31-ks.cfg rd.live.check=0<enter><wait>"
]
disk_size = "15000"
format = "raw"
iso_checksum = "sha256:225ebc160e40bb43c5de28bad9680e3a78a9db40c9e3f4f42f3ee3f10f95dbeb"
iso_url = "https://download-ib01.fedoraproject.org/pub/fedora/linux/releases/31/Server/x86_64/iso/Fedora-Server-dvd-x86_64-31-1.9.iso"
headless = "true"
http_directory = "http"
http_port_max = "10089"
http_port_min = "10082"
output_directory = "output"
shutdown_timeout = "30m"
shutdown_command = "echo 'vagrant'|sudo -S shutdown -P now"
ssh_username = "vagrant"
ssh_password = "vagrant"
vm_name = "disk.raw"
qemu_binary = "/usr/bin/kvm"
qemuargs = [
["-m", "1024"],
["-cpu", "host"],
["-chardev", "tty,id=pts,path=${var.serial}"],
["-device", "isa-serial,chardev=pts"],
["-device", "virtio-net,netdev=user.0"]
]
}
build {
sources = ["source.qemu.example"]
post-processors {
post-processor "compress" {
output = "output/disk.raw.tar.gz"
}
post-processor "googlecompute-import" {
account_file = var.account_file
bucket = var.bucket
project_id = var.project
image_name = "fedora31-server-packertest"
image_description = "Fedora 31 Server"
image_family = "fedora31-server"
}
}
}
```
</Tab>
</Tabs>