Official

»Google Compute Image Import Post-Processor

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.

»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

  • 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 token

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

  • 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, UEFI_COMPATIBLE, VIRTIO_SCSI_MULTIQUEUE and WINDOWS 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 to false.

  • vault_gcp_oauth_engine (string) - Vault GCP Oauth Engine

  • image_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 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.

  • image_forbidden_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.

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

post-processor "googlecompute-import"{
  account_file = "account.json"
  bucket = "my-bucket"
  project_id = "my-project"
  image_name = "my-gce-image"
}
post-processor "googlecompute-import"{  account_file = "account.json"  bucket = "my-bucket"  project_id = "my-project"  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.pkr.hcl
$ packer build -var serial=$(tty) build.pkr.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"
      }
    }
}
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"      }    }}