github.com/tonnydourado/packer@v0.6.1-0.20140701134019-5d0cd9676a37/website/source/docs/builders/googlecompute.markdown (about)

     1  ---
     2  layout: "docs"
     3  ---
     4  
     5  # Google Compute Builder
     6  
     7  Type: `googlecompute`
     8  
     9  The `googlecompute` builder is able to create
    10  [images](https://developers.google.com/compute/docs/images)
    11  for use with [Google Compute Engine](https://cloud.google.com/products/compute-engine)
    12  (GCE) based on existing images. Google Compute Engine doesn't allow the creation
    13  of images from scratch.
    14  
    15  ## Setting Up API Access
    16  
    17  There is a small setup step required in order to obtain the credentials
    18  that Packer needs to use Google Compute Engine. This needs to be done only
    19  once if you intend to share the credentials.
    20  
    21  In order for Packer to talk to Google Compute Engine, it will need
    22  a _client secrets_ JSON file and a _client private key_. Both of these are
    23  obtained from the [Google Cloud Console](https://cloud.google.com/console).
    24  
    25  Follow the steps below:
    26  
    27  1. Log into the [Google Cloud Console](https://cloud.google.com/console)
    28  2. Click on the project you want to use Packer with (or create one if you
    29     don't have one yet).
    30  3. Click "APIs & auth" in the left sidebar
    31  4. Click "Credentials" in the left sidebar
    32  5. Click "Create New Client ID" and choose "Service Account"
    33  6. A private key will be downloaded for you. Note the password for the private key! This private key is your _client private key_.
    34  7. After creating the account, click "Download JSON". This is your _client secrets JSON_ file. Make sure you didn't download the JSON from the "OAuth 2.0" section! This is a common mistake and will cause the builder to not work.
    35  
    36  Finally, one last step, you'll have to convert the `p12` file you
    37  got from Google into the PEM format. You can do this with OpenSSL, which
    38  is installed standard on most Unixes:
    39  
    40  ```
    41  $ openssl pkcs12 -in <path to .p12> -nocerts -passin pass:notasecret \
    42      -nodes -out private_key.pem
    43  ```
    44  
    45  The client secrets JSON you downloaded along with the new "private\_key.pem"
    46  file are the two files you need to configure Packer with to talk to GCE.
    47  
    48  ## Basic Example
    49  
    50  Below is a fully functioning example. It doesn't do anything useful,
    51  since no provisioners are defined, but it will effectively repackage an
    52  existing GCE image. The client secrets file and private key file are the
    53  files obtained in the previous section.
    54  
    55  <pre class="prettyprint">
    56  {
    57    "type": "googlecompute",
    58    "bucket_name": "my-project-packer-images",
    59    "client_secrets_file": "client_secret.json",
    60    "private_key_file": "XXXXXX-privatekey.p12",
    61    "project_id": "my-project",
    62    "source_image": "debian-7-wheezy-v20131014",
    63    "zone": "us-central1-a"
    64  }
    65  </pre>
    66  
    67  ## Configuration Reference
    68  
    69  Configuration options are organized below into two categories: required and optional. Within
    70  each category, the available options are alphabetized and described.
    71  
    72  ### Required:
    73  
    74  * `bucket_name` (string) - The Google Cloud Storage bucket to store the
    75    images that are created. The bucket must already exist in your project.
    76  
    77  * `client_secrets_file` (string) - The client secrets JSON file that
    78    was set up in the section above.
    79  
    80  * `private_key_file` (string) - The client private key file that was
    81    generated in the section above.
    82  
    83  * `project_id` (string) - The project ID that will be used to launch instances
    84    and store images.
    85  
    86  * `source_image` (string) - The source image to use to create the new image
    87    from. Example: "debian-7"
    88  
    89  * `zone` (string) - The zone in which to launch the instance used to create
    90    the image. Example: "us-central1-a"
    91  
    92  ### Optional:
    93  
    94  * `image_name` (string) - The unique name of the resulting image.
    95    Defaults to `packer-{{timestamp}}`.
    96  
    97  * `image_description` (string) - The description of the resulting image.
    98  
    99  * `instance_name` (string) - A name to give the launched instance. Beware
   100    that this must be unique. Defaults to "packer-{{uuid}}".
   101  
   102  * `machine_type` (string) - The machine type. Defaults to `n1-standard-1`.
   103  
   104  * `metadata` (object of key/value strings)
   105  <!---
   106  @todo document me
   107  -->
   108  
   109  * `network` (string) - The Google Compute network to use for the launched
   110    instance. Defaults to `default`.
   111  
   112  * `passphrase` (string) - The passphrase to use if the `private_key_file`
   113    is encrypted.
   114  
   115  * `ssh_port` (integer) - The SSH port. Defaults to 22.
   116  
   117  * `ssh_timeout` (string) - The time to wait for SSH to become available.
   118    Defaults to "1m".
   119  
   120  * `ssh_username` (string) - The SSH username. Defaults to "root".
   121  
   122  * `state_timeout` (string) - The time to wait for instance state changes.
   123    Defaults to "5m".
   124  
   125  * `tags` (array of strings)
   126  <!---
   127  @todo document me
   128  -->
   129  
   130  ## Gotchas
   131  
   132  Centos images have root ssh access disabled by default. Set `ssh_username` to any user, which will be created by packer with sudo access.
   133  
   134  The machine type must have a scratch disk, which means you can't use an `f1-micro` or `g1-small` to build images.