github.com/kimor79/packer@v0.8.7-0.20151221212622-d507b18eb4cf/website/source/docs/builders/googlecompute.html.markdown (about)

     1  ---
     2  description: |
     3      The `googlecompute` Packer builder is able to create images for use with Google
     4      Compute Engine (GCE) based on existing images. Google Compute Engine doesn't
     5      allow the creation of images from scratch.
     6  layout: docs
     7  page_title: Google Compute Builder
     8  ...
     9  
    10  # Google Compute Builder
    11  
    12  Type: `googlecompute`
    13  
    14  The `googlecompute` Packer builder is able to create
    15  [images](https://developers.google.com/compute/docs/images) for use with [Google
    16  Compute Engine](https://cloud.google.com/products/compute-engine)(GCE) based on
    17  existing images. Google Compute Engine doesn't allow the creation of images from
    18  scratch.
    19  
    20  ## Authentication
    21  
    22  Authenticating with Google Cloud services requires at most one JSON file, called
    23  the *account file*. The *account file* is **not** required if you are running
    24  the `googlecompute` Packer builder from a GCE instance with a
    25  properly-configured [Compute Engine Service
    26  Account](https://cloud.google.com/compute/docs/authentication).
    27  
    28  ### Running With a Compute Engine Service Account
    29  
    30  If you run the `googlecompute` Packer builder from a GCE instance, you can
    31  configure that instance to use a [Compute Engine Service
    32  Account](https://cloud.google.com/compute/docs/authentication). This will allow
    33  Packer to authenticate to Google Cloud without having to bake in a separate
    34  credential/authentication file.
    35  
    36  To create a GCE instance that uses a service account, provide the required
    37  scopes when launching the instance.
    38  
    39  For `gcloud`, do this via the `--scopes` parameter:
    40  
    41  ``` {.sh}
    42  gcloud compute --project YOUR_PROJECT instances create "INSTANCE-NAME" ... \
    43                 --scopes "https://www.googleapis.com/auth/compute" \
    44                          "https://www.googleapis.com/auth/devstorage.full_control" \
    45                 ...
    46  ```
    47  
    48  For the [Google Developers Console](https://console.developers.google.com):
    49  
    50  1.  Choose "Show advanced options"
    51  2.  Tick "Enable Compute Engine service account"
    52  3.  Choose "Read Write" for Compute
    53  4.  Chose "Full" for "Storage"
    54  
    55  **The service account will be used automatically by Packer as long as there is
    56  no *account file* specified in the Packer configuration file.**
    57  
    58  ### Running Without a Compute Engine Service Account
    59  
    60  The [Google Developers Console](https://console.developers.google.com) allows
    61  you to create and download a credential file that will let you use the
    62  `googlecompute` Packer builder anywhere. To make the process more
    63  straightforwarded, it is documented here.
    64  
    65  1.  Log into the [Google Developers
    66      Console](https://console.developers.google.com) and select a project.
    67  
    68  2.  Under the "APIs & Auth" section, click "Credentials."
    69  
    70  3.  Click the "Create new Client ID" button, select "Service account", and click
    71      "Create Client ID"
    72  
    73  4.  Click "Generate new JSON key" for the Service Account you just created. A
    74      JSON file will be downloaded automatically. This is your *account file*.
    75  
    76  ## Basic Example
    77  
    78  Below is a fully functioning example. It doesn't do anything useful, since no
    79  provisioners are defined, but it will effectively repackage an existing GCE
    80  image. The account_file is obtained in the previous section.  If it parses as
    81  JSON it is assumed to be the file itself, otherwise it is assumed to be
    82  the path to the file containing the JSON.
    83  
    84  ``` {.javascript}
    85  {
    86    "type": "googlecompute",
    87    "account_file": "account.json",
    88    "project_id": "my-project",
    89    "source_image": "debian-7-wheezy-v20150127",
    90    "zone": "us-central1-a"
    91  }
    92  ```
    93  
    94  ## Configuration Reference
    95  
    96  Configuration options are organized below into two categories: required and
    97  optional. Within each category, the available options are alphabetized and
    98  described.
    99  
   100  In addition to the options listed here, a
   101  [communicator](/docs/templates/communicator.html) can be configured for this
   102  builder.
   103  
   104  ### Required:
   105  
   106  -   `project_id` (string) - The project ID that will be used to launch instances
   107      and store images.
   108  
   109  -   `source_image` (string) - The source image to use to create the new
   110      image from. Example: `"debian-7-wheezy-v20150127"`
   111  
   112  -   `zone` (string) - The zone in which to launch the instance used to create
   113      the image. Example: `"us-central1-a"`
   114  
   115  ### Optional:
   116  
   117  -   `account_file` (string) - The JSON file containing your account credentials.
   118      Not required if you run Packer on a GCE instance with a service account.
   119      Instructions for creating file or using service accounts are above.
   120  
   121  -   `disk_size` (integer) - The size of the disk in GB. This defaults to `10`,
   122      which is 10GB.
   123  
   124  -   `image_name` (string) - The unique name of the resulting image. Defaults to
   125      `"packer-{{timestamp}}"`.
   126  
   127  -   `image_description` (string) - The description of the resulting image.
   128  
   129  -   `instance_name` (string) - A name to give the launched instance. Beware that
   130      this must be unique. Defaults to `"packer-{{uuid}}"`.
   131  
   132  -   `machine_type` (string) - The machine type. Defaults to `"n1-standard-1"`.
   133  
   134  -   `metadata` (object of key/value strings)
   135  
   136  -   `network` (string) - The Google Compute network to use for the
   137      launched instance. Defaults to `"default"`.
   138  
   139  -   `state_timeout` (string) - The time to wait for instance state changes.
   140      Defaults to `"5m"`.
   141  
   142  -   `tags` (array of strings)
   143  
   144  -   `use_internal_ip` (boolean) - If true, use the instance's internal IP
   145      instead of its external IP during building.
   146  
   147  -   `preemptible` (boolean) - If true, launch a preembtible instance.
   148  
   149  ## Gotchas
   150  
   151  Centos images have root ssh access disabled by default. Set `ssh_username` to
   152  any user, which will be created by packer with sudo access.
   153  
   154  The machine type must have a scratch disk, which means you can't use an
   155  `f1-micro` or `g1-small` to build images.