github.com/ratanraj/packer@v1.3.2/website/source/docs/post-processors/googlecompute-import.html.md (about)

     1  ---
     2  description: |
     3      The Google Compute Image Import post-processor takes a compressed raw disk
     4      image and imports it to a GCE image available to Google Compute Engine.
     5      
     6  layout: docs
     7  page_title: 'Google Compute Image Import - Post-Processors'
     8  sidebar_current: 'docs-post-processors-googlecompute-import'
     9  ---
    10  
    11  # Google Compute Image Import Post-Processor
    12  
    13  Type: `googlecompute-import`
    14  
    15  The Google Compute Image Import post-processor takes a compressed raw disk
    16  image and imports it to a GCE image available to Google Compute Engine.
    17  
    18  ~> 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) before using this post-processor.
    19  
    20  ## How Does it Work?
    21  
    22  The import process operates by uploading a temporary copy of the compressed raw disk image
    23  to a GCS bucket, and calling an import task in GCP on the raw disk file. Once completed, a
    24  GCE image is created containing the converted virtual machine. The temporary raw disk image
    25  copy in GCS can be discarded after the import is complete.
    26  
    27  Google Cloud has very specific requirements for images being imported. Please see the
    28  [GCE import documentation](https://cloud.google.com/compute/docs/images/import-existing-image)
    29  for details.
    30  
    31  ## Configuration
    32  
    33  ### Required
    34  
    35  -   `account_file` (string) - The JSON file containing your account credentials.
    36  
    37  -   `bucket` (string) - The name of the GCS bucket where the raw disk image
    38       will be uploaded.
    39  
    40  -   `image_name` (string) - The unique name of the resulting image.
    41  
    42  -   `project_id` (string) - The project ID where the GCS bucket exists and
    43       where the GCE image is stored.
    44  
    45  ### Optional
    46  
    47  -   `gcs_object_name` (string) - The name of the GCS object in `bucket` where the RAW disk image will be copied for import. Defaults to "packer-import-{{timestamp}}.tar.gz".
    48  
    49  -   `image_description` (string) - The description of the resulting image.
    50  
    51  -   `image_family` (string) - The name of the image family to which the resulting image belongs.
    52  
    53  -   `image_labels` (object of key/value strings) - Key/value pair labels to apply to the created image.
    54  
    55  -   `keep_input_artifact` (boolean) - if true, do not delete the compressed RAW disk image. Defaults to false.
    56  
    57  -   `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`.
    58  
    59  
    60  ## Basic Example
    61  
    62  Here is a basic example. This assumes that the builder has produced an compressed
    63  raw disk image artifact for us to work with, and that the GCS bucket has been created.
    64  
    65  ``` json
    66  {
    67    "type": "googlecompute-import",
    68    "account_file": "account.json",
    69    "project_id": "my-project",
    70    "bucket": "my-bucket",
    71    "image_name": "my-gce-image"
    72  }
    73  
    74  ```
    75  
    76  ## QEMU Builder Example
    77  
    78  Here is a complete example for building a Fedora 28 server GCE image. For this example
    79  packer was run from a CentOS 7 server with KVM installed. The CentOS 7 server was running
    80  in GCE with the nested hypervisor feature enabled.
    81  
    82  ```
    83  $ packer build -var serial=$(tty) build.json
    84  ```
    85  
    86  ``` json
    87  {
    88    "variables": {
    89      "serial": ""
    90    },
    91    "builders": [
    92      {
    93        "type": "qemu",
    94        "accelerator": "kvm",
    95        "communicator": "none",
    96        "boot_command": ["<tab> console=ttyS0,115200n8 inst.text inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/fedora-28-ks.cfg rd.live.check=0<enter><wait>"],
    97        "disk_size": "15000",
    98        "format": "raw",
    99        "iso_checksum_type": "sha256",
   100        "iso_checksum": "ea1efdc692356b3346326f82e2f468903e8da59324fdee8b10eac4fea83f23fe",
   101        "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",
   102        "headless": "true",
   103        "http_directory": "http",
   104        "http_port_max": "10089",
   105        "http_port_min": "10082",
   106        "output_directory": "output",
   107        "shutdown_timeout": "30m",
   108        "vm_name": "disk.raw",
   109        "qemu_binary": "/usr/libexec/qemu-kvm",
   110        "qemuargs": [
   111          [
   112            "-m", "1024"
   113          ],
   114          [
   115            "-cpu", "host"
   116          ],
   117          [
   118            "-chardev", "tty,id=pts,path={{user `serial`}}"
   119          ],
   120          [
   121            "-device", "isa-serial,chardev=pts"
   122          ],
   123          [
   124            "-device", "virtio-net,netdev=user.0"
   125          ]
   126        ]
   127      }
   128    ],
   129    "post-processors": [
   130      [
   131        {
   132          "type": "compress",
   133          "output": "output/disk.raw.tar.gz"
   134        },
   135        {
   136          "type": "googlecompute-import",
   137          "project_id": "my-project",
   138          "account_file": "account.json",
   139          "bucket": "my-bucket",
   140          "image_name": "fedora28-server-{{timestamp}}",
   141          "image_description": "Fedora 28 Server",
   142          "image_family": "fedora28-server"
   143        }
   144      ]
   145    ]
   146  }
   147  ```