2013-12-08 18:02:03 -05:00
|
|
|
---
|
2015-07-28 18:30:32 -04:00
|
|
|
description: |
|
|
|
|
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.
|
|
|
|
layout: docs
|
|
|
|
page_title: Google Compute Builder
|
|
|
|
...
|
2013-12-08 18:02:03 -05:00
|
|
|
|
|
|
|
# Google Compute Builder
|
|
|
|
|
|
|
|
Type: `googlecompute`
|
|
|
|
|
2015-07-28 18:30:32 -04:00
|
|
|
The `googlecompute` Packer 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.
|
2013-12-12 22:59:29 -05:00
|
|
|
|
2014-09-05 12:49:40 -04:00
|
|
|
## Authentication
|
2013-12-12 22:59:29 -05:00
|
|
|
|
2015-07-28 18:30:32 -04:00
|
|
|
Authenticating with Google Cloud services requires at most one JSON file, called
|
|
|
|
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 [Compute Engine Service
|
|
|
|
Account](https://cloud.google.com/compute/docs/authentication).
|
2013-12-12 22:59:29 -05:00
|
|
|
|
2014-11-17 13:06:22 -05:00
|
|
|
### Running With a Compute Engine Service Account
|
|
|
|
|
2015-07-28 18:30:32 -04:00
|
|
|
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 launching the instance.
|
2014-11-17 13:06:22 -05:00
|
|
|
|
|
|
|
For `gcloud`, do this via the `--scopes` parameter:
|
|
|
|
|
2015-07-28 18:30:32 -04:00
|
|
|
``` {.sh}
|
2014-11-17 13:06:22 -05:00
|
|
|
gcloud compute --project YOUR_PROJECT instances create "INSTANCE-NAME" ... \
|
|
|
|
--scopes "https://www.googleapis.com/auth/compute" \
|
|
|
|
"https://www.googleapis.com/auth/devstorage.full_control" \
|
|
|
|
...
|
|
|
|
```
|
|
|
|
|
|
|
|
For the [Google Developers Console](https://console.developers.google.com):
|
|
|
|
|
2015-07-28 18:30:32 -04:00
|
|
|
1. Choose "Show advanced options"
|
|
|
|
2. Tick "Enable Compute Engine service account"
|
|
|
|
3. Choose "Read Write" for Compute
|
|
|
|
4. Chose "Full" for "Storage"
|
2014-11-17 13:06:22 -05:00
|
|
|
|
|
|
|
**The service account will be used automatically by Packer as long as there is
|
2015-07-28 18:30:32 -04:00
|
|
|
no *account file* specified in the Packer configuration file.**
|
2014-11-17 13:06:22 -05:00
|
|
|
|
|
|
|
### Running Without a Compute Engine Service Account
|
|
|
|
|
2015-07-28 18:30:32 -04:00
|
|
|
The [Google Developers Console](https://console.developers.google.com) allows
|
|
|
|
you to create and download a credential file that will let you use the
|
|
|
|
`googlecompute` Packer builder anywhere. To make the process more
|
|
|
|
straightforwarded, it is documented here.
|
2013-12-12 22:59:29 -05:00
|
|
|
|
2015-07-28 18:30:32 -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
|
|
|
|
2015-07-28 18:30:32 -04:00
|
|
|
2. Under the "APIs & Auth" section, click "Credentials."
|
2013-12-12 22:59:29 -05:00
|
|
|
|
2015-07-28 18:30:32 -04:00
|
|
|
3. Click the "Create new Client ID" button, select "Service account", and click
|
|
|
|
"Create Client ID"
|
2013-12-13 00:52:25 -05:00
|
|
|
|
2015-07-28 18:30:32 -04:00
|
|
|
4. Click "Generate new JSON key" for the Service Account you just created. A
|
|
|
|
JSON file will be downloaded automatically. This is your *account file*.
|
2013-12-08 18:02:03 -05:00
|
|
|
|
|
|
|
## Basic Example
|
|
|
|
|
2015-07-28 18:30:32 -04: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
|
2015-10-08 00:36:31 -04:00
|
|
|
image. The account_file is obtained in the previous section. If it parses as
|
|
|
|
JSON it is assumed to be the file itself, otherwise it is assumed to be
|
|
|
|
the path to the file containing the JSON.
|
2013-12-08 18:02:03 -05:00
|
|
|
|
2015-07-28 18:30:32 -04:00
|
|
|
``` {.javascript}
|
2013-12-08 18:02:03 -05:00
|
|
|
{
|
|
|
|
"type": "googlecompute",
|
2014-09-05 12:49:40 -04:00
|
|
|
"account_file": "account.json",
|
2013-12-08 18:02:03 -05:00
|
|
|
"project_id": "my-project",
|
2015-02-10 22:02:36 -05:00
|
|
|
"source_image": "debian-7-wheezy-v20150127",
|
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
|
|
|
|
|
2015-07-28 18:30:32 -04:00
|
|
|
Configuration options are organized below into two categories: required and
|
|
|
|
optional. Within each category, the available options are alphabetized and
|
|
|
|
described.
|
2013-12-08 18:02:03 -05:00
|
|
|
|
2015-06-23 17:44:57 -04:00
|
|
|
In addition to the options listed here, a
|
2015-07-28 18:30:32 -04:00
|
|
|
[communicator](/docs/templates/communicator.html) can be configured for this
|
|
|
|
builder.
|
2015-06-23 17:44:57 -04:00
|
|
|
|
2014-05-04 13:47:40 -04:00
|
|
|
### Required:
|
2013-12-08 18:02:03 -05:00
|
|
|
|
2015-07-28 18:30:32 -04:00
|
|
|
- `project_id` (string) - The project ID that will be used to launch instances
|
|
|
|
and store images.
|
2013-12-12 22:59:29 -05:00
|
|
|
|
2015-07-28 18:30:32 -04:00
|
|
|
- `source_image` (string) - The source image to use to create the new
|
|
|
|
image from. Example: `"debian-7-wheezy-v20150127"`
|
2013-12-12 22:59:29 -05:00
|
|
|
|
2015-07-28 18:30:32 -04:00
|
|
|
- `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
|
|
|
|
2015-07-28 18:30:32 -04:00
|
|
|
- `account_file` (string) - The JSON file containing your account credentials.
|
|
|
|
Not required if you run Packer on a GCE instance with a service account.
|
|
|
|
Instructions for creating file or using service accounts are above.
|
2014-11-17 13:06:22 -05:00
|
|
|
|
2016-01-04 17:25:39 -05:00
|
|
|
- `address` (string) - The name of a pre-allocated static external IP address.
|
|
|
|
Note, must be the name and not the actual IP address.
|
|
|
|
|
2015-07-28 18:30:32 -04:00
|
|
|
- `disk_size` (integer) - The size of the disk in GB. This defaults to `10`,
|
|
|
|
which is 10GB.
|
2014-08-07 15:34:08 -04:00
|
|
|
|
2015-07-28 18:30:32 -04:00
|
|
|
- `image_name` (string) - The unique name of the resulting image. Defaults to
|
|
|
|
`"packer-{{timestamp}}"`.
|
2013-12-12 22:59:29 -05:00
|
|
|
|
2015-07-28 18:30:32 -04:00
|
|
|
- `image_description` (string) - The description of the resulting image.
|
2013-12-12 22:59:29 -05:00
|
|
|
|
2015-07-28 18:30:32 -04:00
|
|
|
- `instance_name` (string) - A name to give the launched instance. Beware that
|
|
|
|
this must be unique. Defaults to `"packer-{{uuid}}"`.
|
2014-04-26 14:02:25 -04:00
|
|
|
|
2015-07-28 18:30:32 -04:00
|
|
|
- `machine_type` (string) - The machine type. Defaults to `"n1-standard-1"`.
|
2014-05-04 13:53:57 -04:00
|
|
|
|
2015-07-28 18:30:32 -04:00
|
|
|
- `metadata` (object of key/value strings)
|
2014-05-04 13:47:40 -04:00
|
|
|
|
2015-07-28 18:30:32 -04:00
|
|
|
- `network` (string) - The Google Compute network to use for the
|
|
|
|
launched instance. Defaults to `"default"`.
|
2013-12-12 22:59:29 -05:00
|
|
|
|
2016-02-11 04:08:32 -05:00
|
|
|
- `region` (string) - The region in which to launch the instance. Defaults to
|
|
|
|
to the region hosting the specified `zone`.
|
|
|
|
|
2015-07-28 18:30:32 -04:00
|
|
|
- `state_timeout` (string) - The time to wait for instance state changes.
|
|
|
|
Defaults to `"5m"`.
|
2013-12-08 18:02:03 -05:00
|
|
|
|
2016-02-11 03:54:48 -05:00
|
|
|
- `subnetwork` (string) - The Google Compute subnetwork to use for the launced
|
|
|
|
instance. Only required if the `network` has been created with custom
|
|
|
|
subnetting.
|
2016-02-11 04:08:32 -05:00
|
|
|
Note, the region of the subnetwork must match the `region` or `zone` in
|
|
|
|
which the VM is launched.
|
2016-02-11 03:54:48 -05:00
|
|
|
|
2015-07-28 18:30:32 -04:00
|
|
|
- `tags` (array of strings)
|
2014-05-04 13:47:40 -04:00
|
|
|
|
2015-07-28 18:30:32 -04:00
|
|
|
- `use_internal_ip` (boolean) - If true, use the instance's internal IP
|
|
|
|
instead of its external IP during building.
|
2015-07-27 22:32:21 -04:00
|
|
|
|
2015-12-05 00:17:55 -05:00
|
|
|
- `preemptible` (boolean) - If true, launch a preembtible instance.
|
|
|
|
|
2013-12-08 18:02:03 -05:00
|
|
|
## Gotchas
|
|
|
|
|
2015-07-28 18:30:32 -04:00
|
|
|
Centos images have root ssh access disabled by default. Set `ssh_username` to
|
|
|
|
any user, which will be created by packer with sudo access.
|
2013-12-08 18:02:03 -05:00
|
|
|
|
2015-07-28 18:30:32 -04:00
|
|
|
The machine type must have a scratch disk, which means you can't use an
|
|
|
|
`f1-micro` or `g1-small` to build images.
|