2013-12-08 18:02:03 -05:00
|
|
|
---
|
|
|
|
layout: "docs"
|
2014-08-21 20:41:35 -04:00
|
|
|
page_title: "Google Compute Builder"
|
2013-12-08 18:02:03 -05:00
|
|
|
---
|
|
|
|
|
|
|
|
# Google Compute Builder
|
|
|
|
|
|
|
|
Type: `googlecompute`
|
|
|
|
|
2013-12-12 22:59:29 -05:00
|
|
|
The `googlecompute` builder is able to create
|
|
|
|
[images](https://developers.google.com/compute/docs/images)
|
|
|
|
for use with [Google 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.
|
|
|
|
|
2014-09-05 12:49:40 -04:00
|
|
|
## Authentication
|
2013-12-12 22:59:29 -05:00
|
|
|
|
2014-09-05 12:49:40 -04:00
|
|
|
Authenticating with Google Cloud services requires two separate JSON
|
|
|
|
files: one which we call the _account file_ and the _client secrets file_.
|
2013-12-12 22:59:29 -05:00
|
|
|
|
2014-09-05 12:49:40 -04:00
|
|
|
Both of these files are downloaded directly from the
|
|
|
|
[Google Developers Console](https://console.developers.google.com). To make
|
|
|
|
the process more straightforwarded, it is documented here.
|
2013-12-12 22:59:29 -05:00
|
|
|
|
2014-09-05 12:49:40 -04:00
|
|
|
1. Log into the [Google Developers Console](https://console.developers.google.com)
|
|
|
|
and select a project.
|
2013-12-12 22:59:29 -05:00
|
|
|
|
2014-09-05 12:49:40 -04:00
|
|
|
2. Under the "APIs & Auth" section, click "Credentials."
|
2013-12-12 22:59:29 -05:00
|
|
|
|
2014-09-05 12:49:40 -04:00
|
|
|
3. Click the "Download JSON" button under the "Compute Engine and App Engine"
|
|
|
|
account in the OAuth section. The file should start with "client\_secrets".
|
|
|
|
This is your _client secrets file_.
|
2013-12-13 00:52:25 -05:00
|
|
|
|
2014-09-05 12:49:40 -04:00
|
|
|
4. Create a new OAuth client ID and select "Service Account" as the type
|
|
|
|
of account. Once created, a JSON file should be downloaded. This is your
|
|
|
|
_account file_.
|
2013-12-08 18:02:03 -05:00
|
|
|
|
|
|
|
## Basic Example
|
|
|
|
|
2013-12-12 22:59:29 -05:00
|
|
|
Below is a fully functioning example. It doesn't do anything useful,
|
|
|
|
since no provisioners are defined, but it will effectively repackage an
|
|
|
|
existing GCE image. The client secrets file and private key file are the
|
|
|
|
files obtained in the previous section.
|
2013-12-08 18:02:03 -05:00
|
|
|
|
2014-10-20 13:55:16 -04:00
|
|
|
```javascript
|
2013-12-08 18:02:03 -05:00
|
|
|
{
|
|
|
|
"type": "googlecompute",
|
2014-03-06 06:14:44 -05:00
|
|
|
"bucket_name": "my-project-packer-images",
|
2014-09-05 12:49:40 -04:00
|
|
|
"account_file": "account.json",
|
2013-12-12 22:59:29 -05:00
|
|
|
"client_secrets_file": "client_secret.json",
|
2013-12-08 18:02:03 -05:00
|
|
|
"project_id": "my-project",
|
2014-07-28 12:06:26 -04:00
|
|
|
"source_image": "debian-7-wheezy-v20140718",
|
2013-12-08 18:02:03 -05:00
|
|
|
"zone": "us-central1-a"
|
|
|
|
}
|
2014-10-20 13:55:16 -04:00
|
|
|
```
|
2013-12-08 18:02:03 -05:00
|
|
|
|
|
|
|
## Configuration Reference
|
|
|
|
|
|
|
|
Configuration options are organized below into two categories: required and optional. Within
|
|
|
|
each category, the available options are alphabetized and described.
|
|
|
|
|
2014-05-04 13:47:40 -04:00
|
|
|
### Required:
|
2013-12-08 18:02:03 -05:00
|
|
|
|
2014-09-05 12:49:40 -04:00
|
|
|
* `account_file` (string) - The JSON file containing your account credentials.
|
|
|
|
Instructions for how to retrieve these are above.
|
|
|
|
|
2013-12-12 22:59:29 -05:00
|
|
|
* `bucket_name` (string) - The Google Cloud Storage bucket to store the
|
2014-03-06 06:14:44 -05:00
|
|
|
images that are created. The bucket must already exist in your project.
|
2013-12-12 22:59:29 -05:00
|
|
|
|
|
|
|
* `client_secrets_file` (string) - The client secrets JSON file that
|
|
|
|
was set up in the section above.
|
|
|
|
|
|
|
|
* `private_key_file` (string) - The client private key file that was
|
|
|
|
generated in the section above.
|
|
|
|
|
|
|
|
* `project_id` (string) - The project ID that will be used to launch instances
|
|
|
|
and store images.
|
|
|
|
|
|
|
|
* `source_image` (string) - The source image to use to create the new image
|
|
|
|
from. Example: "debian-7"
|
|
|
|
|
|
|
|
* `zone` (string) - The zone in which to launch the instance used to create
|
|
|
|
the image. Example: "us-central1-a"
|
2013-12-08 18:02:03 -05:00
|
|
|
|
2014-05-04 13:47:40 -04:00
|
|
|
### Optional:
|
2013-12-08 18:02:03 -05:00
|
|
|
|
2014-08-07 15:34:08 -04:00
|
|
|
* `disk_size` (integer) - The size of the disk in GB.
|
|
|
|
This defaults to 10, which is 10GB.
|
|
|
|
|
2013-12-12 22:59:29 -05:00
|
|
|
* `image_name` (string) - The unique name of the resulting image.
|
|
|
|
Defaults to `packer-{{timestamp}}`.
|
|
|
|
|
2013-12-08 18:02:03 -05:00
|
|
|
* `image_description` (string) - The description of the resulting image.
|
2013-12-12 22:59:29 -05:00
|
|
|
|
2014-04-26 14:02:25 -04:00
|
|
|
* `instance_name` (string) - A name to give the launched instance. Beware
|
|
|
|
that this must be unique. Defaults to "packer-{{uuid}}".
|
|
|
|
|
2014-05-04 13:53:57 -04:00
|
|
|
* `machine_type` (string) - The machine type. Defaults to `n1-standard-1`.
|
|
|
|
|
2014-05-04 13:47:40 -04:00
|
|
|
* `metadata` (object of key/value strings)
|
|
|
|
|
2013-12-12 22:59:29 -05:00
|
|
|
* `network` (string) - The Google Compute network to use for the launched
|
|
|
|
instance. Defaults to `default`.
|
|
|
|
|
2014-05-04 13:47:40 -04:00
|
|
|
* `ssh_port` (integer) - The SSH port. Defaults to 22.
|
2013-12-12 22:59:29 -05:00
|
|
|
|
|
|
|
* `ssh_timeout` (string) - The time to wait for SSH to become available.
|
|
|
|
Defaults to "1m".
|
|
|
|
|
|
|
|
* `ssh_username` (string) - The SSH username. Defaults to "root".
|
|
|
|
|
|
|
|
* `state_timeout` (string) - The time to wait for instance state changes.
|
|
|
|
Defaults to "5m".
|
2013-12-08 18:02:03 -05:00
|
|
|
|
2014-05-04 13:47:40 -04:00
|
|
|
* `tags` (array of strings)
|
|
|
|
|
2013-12-08 18:02:03 -05:00
|
|
|
## 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.
|
|
|
|
|
|
|
|
The machine type must have a scratch disk, which means you can't use an `f1-micro` or `g1-small` to build images.
|