Commit 0c765435 authored by Chris Bednarski's avatar Chris Bednarski

Reformat

parent 8741a6df
--- ---
layout: "docs" description: |
page_title: "Google Compute Builder" The `googlecompute` Packer builder is able to create images for use with Google
description: |- Compute Engine (GCE) based on existing images. Google Compute Engine doesn't
The `googlecompute` Packer builder is able to create images for use with Google Compute Engine (GCE) based on existing images. Google Compute Engine doesn't allow the creation of images from scratch. allow the creation of images from scratch.
--- layout: docs
page_title: Google Compute Builder
...
# Google Compute Builder # Google Compute Builder
Type: `googlecompute` Type: `googlecompute`
The `googlecompute` Packer builder is able to create [images](https://developers.google.com/compute/docs/images) for use with The `googlecompute` Packer builder is able to create
[Google Compute Engine](https://cloud.google.com/products/compute-engine)(GCE) based on existing images. Google [images](https://developers.google.com/compute/docs/images) for use with [Google
Compute Engine doesn't allow the creation of images from scratch. Compute Engine](https://cloud.google.com/products/compute-engine)(GCE) based on
existing images. Google Compute Engine doesn't allow the creation of images from
scratch.
## Authentication ## Authentication
Authenticating with Google Cloud services requires at most one JSON file, Authenticating with Google Cloud services requires at most one JSON file, called
called the _account file_. The _account file_ is **not** required if you are running the *account file*. The *account file* is **not** required if you are running
the `googlecompute` Packer builder from a GCE instance with a properly-configured the `googlecompute` Packer builder from a GCE instance with a
[Compute Engine Service Account](https://cloud.google.com/compute/docs/authentication). properly-configured [Compute Engine Service
Account](https://cloud.google.com/compute/docs/authentication).
### Running With a Compute Engine Service Account ### Running With a Compute Engine Service Account
If you run the `googlecompute` Packer builder from a GCE instance, you can configure that
instance to use a [Compute Engine Service Account](https://cloud.google.com/compute/docs/authentication). This will allow Packer to authenticate
to Google Cloud without having to bake in a separate credential/authentication file.
To create a GCE instance that uses a service account, provide the required scopes when If you run the `googlecompute` Packer builder from a GCE instance, you can
launching the instance. configure that instance to use a [Compute Engine Service
Account](https://cloud.google.com/compute/docs/authentication). This will allow
Packer to authenticate to Google Cloud without having to bake in a separate
credential/authentication file.
To create a GCE instance that uses a service account, provide the required
scopes when launching the instance.
For `gcloud`, do this via the `--scopes` parameter: For `gcloud`, do this via the `--scopes` parameter:
```sh ``` {.sh}
gcloud compute --project YOUR_PROJECT instances create "INSTANCE-NAME" ... \ gcloud compute --project YOUR_PROJECT instances create "INSTANCE-NAME" ... \
--scopes "https://www.googleapis.com/auth/compute" \ --scopes "https://www.googleapis.com/auth/compute" \
"https://www.googleapis.com/auth/devstorage.full_control" \ "https://www.googleapis.com/auth/devstorage.full_control" \
...@@ -39,38 +47,39 @@ gcloud compute --project YOUR_PROJECT instances create "INSTANCE-NAME" ... \ ...@@ -39,38 +47,39 @@ gcloud compute --project YOUR_PROJECT instances create "INSTANCE-NAME" ... \
For the [Google Developers Console](https://console.developers.google.com): For the [Google Developers Console](https://console.developers.google.com):
1. Choose "Show advanced options" 1. Choose "Show advanced options"
2. Tick "Enable Compute Engine service account" 2. Tick "Enable Compute Engine service account"
3. Choose "Read Write" for Compute 3. Choose "Read Write" for Compute
4. Chose "Full" for "Storage" 4. Chose "Full" for "Storage"
**The service account will be used automatically by Packer as long as there is **The service account will be used automatically by Packer as long as there is
no _account file_ specified in the Packer configuration file.** no *account file* specified in the Packer configuration file.**
### Running Without a Compute Engine Service Account ### Running Without a Compute Engine Service Account
The [Google Developers Console](https://console.developers.google.com) allows you to The [Google Developers Console](https://console.developers.google.com) allows
create and download a credential file that will let you use the `googlecompute` Packer you to create and download a credential file that will let you use the
builder anywhere. To make `googlecompute` Packer builder anywhere. To make the process more
the process more straightforwarded, it is documented here. straightforwarded, it is documented here.
1. Log into the [Google Developers Console](https://console.developers.google.com) 1. Log into the [Google Developers
and select a project. Console](https://console.developers.google.com) and select a project.
2. Under the "APIs & Auth" section, click "Credentials." 2. Under the "APIs & Auth" section, click "Credentials."
3. Click the "Create new Client ID" button, select "Service account", and click "Create Client ID" 3. Click the "Create new Client ID" button, select "Service account", and click
"Create Client ID"
4. Click "Generate new JSON key" for the Service Account you just created. A JSON file will be downloaded automatically. This is your 4. Click "Generate new JSON key" for the Service Account you just created. A
_account file_. JSON file will be downloaded automatically. This is your *account file*.
## Basic Example ## Basic Example
Below is a fully functioning example. It doesn't do anything useful, Below is a fully functioning example. It doesn't do anything useful, since no
since no provisioners are defined, but it will effectively repackage an provisioners are defined, but it will effectively repackage an existing GCE
existing GCE image. The account file is obtained in the previous section. image. The account file is obtained in the previous section.
```javascript ``` {.javascript}
{ {
"type": "googlecompute", "type": "googlecompute",
"account_file": "account.json", "account_file": "account.json",
...@@ -82,58 +91,61 @@ existing GCE image. The account file is obtained in the previous section. ...@@ -82,58 +91,61 @@ existing GCE image. The account file is obtained in the previous section.
## Configuration Reference ## Configuration Reference
Configuration options are organized below into two categories: required and optional. Within Configuration options are organized below into two categories: required and
each category, the available options are alphabetized and described. optional. Within each category, the available options are alphabetized and
described.
In addition to the options listed here, a In addition to the options listed here, a
[communicator](/docs/templates/communicator.html) [communicator](/docs/templates/communicator.html) can be configured for this
can be configured for this builder. builder.
### Required: ### Required:
* `project_id` (string) - The project ID that will be used to launch instances - `project_id` (string) - The project ID that will be used to launch instances
and store images. and store images.
* `source_image` (string) - The source image to use to create the new image - `source_image` (string) - The source image to use to create the new
from. Example: `"debian-7-wheezy-v20150127"` image from. Example: `"debian-7-wheezy-v20150127"`
* `zone` (string) - The zone in which to launch the instance used to create - `zone` (string) - The zone in which to launch the instance used to create
the image. Example: `"us-central1-a"` the image. Example: `"us-central1-a"`
### Optional: ### Optional:
* `account_file` (string) - The JSON file containing your account credentials. - `account_file` (string) - The JSON file containing your account credentials.
Not required if you run Packer on a GCE instance with a service account. Not required if you run Packer on a GCE instance with a service account.
Instructions for creating file or using service accounts are above. Instructions for creating file or using service accounts are above.
* `disk_size` (integer) - The size of the disk in GB. - `disk_size` (integer) - The size of the disk in GB. This defaults to `10`,
This defaults to `10`, which is 10GB. which is 10GB.
* `image_name` (string) - The unique name of the resulting image. - `image_name` (string) - The unique name of the resulting image. Defaults to
Defaults to `"packer-{{timestamp}}"`. `"packer-{{timestamp}}"`.
* `image_description` (string) - The description of the resulting image. - `image_description` (string) - The description of the resulting image.
* `instance_name` (string) - A name to give the launched instance. Beware - `instance_name` (string) - A name to give the launched instance. Beware that
that this must be unique. Defaults to `"packer-{{uuid}}"`. this must be unique. Defaults to `"packer-{{uuid}}"`.
* `machine_type` (string) - The machine type. Defaults to `"n1-standard-1"`. - `machine_type` (string) - The machine type. Defaults to `"n1-standard-1"`.
* `metadata` (object of key/value strings) - `metadata` (object of key/value strings)
* `network` (string) - The Google Compute network to use for the launched - `network` (string) - The Google Compute network to use for the
instance. Defaults to `"default"`. launched instance. Defaults to `"default"`.
* `state_timeout` (string) - The time to wait for instance state changes. - `state_timeout` (string) - The time to wait for instance state changes.
Defaults to `"5m"`. Defaults to `"5m"`.
* `tags` (array of strings) - `tags` (array of strings)
* `use_internal_ip` (boolean) - If true, use the instance's internal IP instead - `use_internal_ip` (boolean) - If true, use the instance's internal IP
of its external IP during building. instead of its external IP during building.
## Gotchas ## Gotchas
Centos images have root ssh access disabled by default. Set `ssh_username` to any user, which will be created by packer with sudo access. Centos images have root ssh access disabled by default. Set `ssh_username` to
any user, which will be created by packer with sudo access.
The machine type must have a scratch disk, which means you can't use an `f1-micro` or `g1-small` to build images. The machine type must have a scratch disk, which means you can't use an
`f1-micro` or `g1-small` to build images.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment