»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.

»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.

»Configuration

»Required

  • account_file (string) - The JSON file containing your account credentials. If specified, the account file will take precedence over any googlecompute builder authentication method.

  • 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

  • impersonate_service_account (string) - This allows service account impersonation as per the docs.

  • 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. Therefore, you may use user variables and template functions in this field. Defaults to packer-import-{{timestamp}}.tar.gz.

  • 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 are MULTI_IP_SUBNET, SECURE_BOOT, UEFI_COMPATIBLE, VIRTIO_SCSI_MULTIQUEUE and WINDOWS currently.

  • image_labels (map[string]string) - Key/value pair labels to apply to the created image.

  • 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 to false.

  • vault_gcp_oauth_engine (string) - Vault GCP Oauth Engine

»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.

{
  "type": "googlecompute-import",
  "account_file": "account.json",
  "project_id": "my-project",
  "bucket": "my-bucket",
  "image_name": "my-gce-image"
}

»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.

$ packer build -var serial=$(tty) build.json
{
  "variables": {
    "account_file": "account.json",
    "bucket": "my-bucket",
    "project": "my-project",
    "serial": ""
  },
  "builders": [
    {
      "type": "qemu",
      "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={{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"
      }
    ]
  ]
}