github.com/marksheahan/packer@v0.10.2-0.20160613200515-1acb2d6645a0/website/source/docs/builders/googlecompute.html.md (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  -   `address` (string) - The name of a pre-allocated static external IP address.
   122      Note, must be the name and not the actual IP address.
   123  
   124  -   `disk_size` (integer) - The size of the disk in GB. This defaults to `10`,
   125      which is 10GB.
   126  
   127  -   `disk_type` (string) - Type of disk used to back your instance, like `pd-ssd` or `pd-standard`. Defaults to `pd-standard`.
   128  
   129  -   `image_description` (string) - The description of the resulting image.
   130  
   131  -   `image_family` (string) - The name of the image family to which the resulting image belongs. You can create disks by specifying an image family instead of a specific image name. The image family always returns its latest image that is not deprecated.
   132  
   133  -   `image_name` (string) - The unique name of the resulting image. Defaults to
   134      `"packer-{{timestamp}}"`.
   135  
   136  -   `instance_name` (string) - A name to give the launched instance. Beware that
   137      this must be unique. Defaults to `"packer-{{uuid}}"`.
   138  
   139  -   `machine_type` (string) - The machine type. Defaults to `"n1-standard-1"`.
   140  
   141  -   `metadata` (object of key/value strings)
   142  
   143  -   `network` (string) - The Google Compute network to use for the
   144      launched instance. Defaults to `"default"`.
   145  
   146  -   `preemptible` (boolean) - If true, launch a preembtible instance.
   147  
   148  -   `region` (string) - The region in which to launch the instance. Defaults to
   149      to the region hosting the specified `zone`.
   150  
   151  -   `state_timeout` (string) - The time to wait for instance state changes.
   152      Defaults to `"5m"`.
   153  
   154  -   `subnetwork` (string) - The Google Compute subnetwork to use for the launced
   155       instance. Only required if the `network` has been created with custom
   156       subnetting.
   157       Note, the region of the subnetwork must match the `region` or `zone` in
   158       which the VM is launched.
   159  
   160  -   `tags` (array of strings)
   161  
   162  -   `use_internal_ip` (boolean) - If true, use the instance's internal IP
   163      instead of its external IP during building.
   164  
   165  ## Gotchas
   166  
   167  Centos images have root ssh access disabled by default. Set `ssh_username` to
   168  any user, which will be created by packer with sudo access.
   169  
   170  The machine type must have a scratch disk, which means you can't use an
   171  `f1-micro` or `g1-small` to build images.