|
|
|
|
@ -9,19 +9,49 @@ description: |-
|
|
|
|
|
|
|
|
|
|
Type: `googlecompute`
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
## Authentication
|
|
|
|
|
|
|
|
|
|
Authenticating with Google Cloud services requires two separate JSON
|
|
|
|
|
files: one which we call the _account file_ and the _client secrets file_.
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
Both of these files are downloaded directly from the
|
|
|
|
|
[Google Developers Console](https://console.developers.google.com). To make
|
|
|
|
|
### 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
|
|
|
|
|
launching the intance.
|
|
|
|
|
|
|
|
|
|
For `gcloud`, do this via the `--scopes` parameter:
|
|
|
|
|
|
|
|
|
|
```sh
|
|
|
|
|
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):
|
|
|
|
|
|
|
|
|
|
1. Choose "Show advanced options"
|
|
|
|
|
2. Tick "Enable Compute Engine service account"
|
|
|
|
|
3. Choose "Read Write" for Compute
|
|
|
|
|
4. Chose "Full" for "Storage"
|
|
|
|
|
|
|
|
|
|
**The service account will be used automatically by Packer as long as there is
|
|
|
|
|
no _account file_ specified in the Packer configuration file.**
|
|
|
|
|
|
|
|
|
|
### Running Without a Compute Engine Service Account
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
1. Log into the [Google Developers Console](https://console.developers.google.com)
|
|
|
|
|
@ -29,27 +59,22 @@ the process more straightforwarded, it is documented here.
|
|
|
|
|
|
|
|
|
|
2. Under the "APIs & Auth" section, click "Credentials."
|
|
|
|
|
|
|
|
|
|
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_.
|
|
|
|
|
3. Click the "Create new Client ID" button, select "Service account", and click "Create Client ID"
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
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_.
|
|
|
|
|
|
|
|
|
|
## Basic Example
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
existing GCE image. The account file is obtained in the previous section.
|
|
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
|
{
|
|
|
|
|
"type": "googlecompute",
|
|
|
|
|
"bucket_name": "my-project-packer-images",
|
|
|
|
|
"account_file": "account.json",
|
|
|
|
|
"client_secrets_file": "client_secret.json",
|
|
|
|
|
"project_id": "my-project",
|
|
|
|
|
"source_image": "debian-7-wheezy-v20140718",
|
|
|
|
|
"zone": "us-central1-a"
|
|
|
|
|
@ -63,17 +88,8 @@ each category, the available options are alphabetized and described.
|
|
|
|
|
|
|
|
|
|
### Required:
|
|
|
|
|
|
|
|
|
|
* `account_file` (string) - The JSON file containing your account credentials.
|
|
|
|
|
Instructions for how to retrieve these are above.
|
|
|
|
|
|
|
|
|
|
* `bucket_name` (string) - The Google Cloud Storage bucket to store the
|
|
|
|
|
images that are created. The bucket must already exist in your project.
|
|
|
|
|
|
|
|
|
|
* `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.
|
|
|
|
|
images that are created. The bucket must already exist in your project
|
|
|
|
|
|
|
|
|
|
* `project_id` (string) - The project ID that will be used to launch instances
|
|
|
|
|
and store images.
|
|
|
|
|
@ -86,6 +102,10 @@ each category, the available options are alphabetized and described.
|
|
|
|
|
|
|
|
|
|
### Optional:
|
|
|
|
|
|
|
|
|
|
* `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.
|
|
|
|
|
|
|
|
|
|
* `disk_size` (integer) - The size of the disk in GB.
|
|
|
|
|
This defaults to 10, which is 10GB.
|
|
|
|
|
|
|
|
|
|
|