github.com/aspring/packer@v0.8.1-0.20150629211158-9db281ac0f89/website/source/docs/builders/googlecompute.markdown (about) 1 --- 2 layout: "docs" 3 page_title: "Google Compute Builder" 4 description: |- 5 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. 6 --- 7 8 # Google Compute Builder 9 10 Type: `googlecompute` 11 12 The `googlecompute` Packer builder is able to create [images](https://developers.google.com/compute/docs/images) for use with 13 [Google Compute Engine](https://cloud.google.com/products/compute-engine)(GCE) based on existing images. Google 14 Compute Engine doesn't allow the creation of images from scratch. 15 16 ## Authentication 17 18 Authenticating with Google Cloud services requires at most one JSON file, 19 called the _account file_. The _account file_ is **not** required if you are running 20 the `googlecompute` Packer builder from a GCE instance with a properly-configured 21 [Compute Engine Service Account](https://cloud.google.com/compute/docs/authentication). 22 23 ### Running With a Compute Engine Service Account 24 If you run the `googlecompute` Packer builder from a GCE instance, you can configure that 25 instance to use a [Compute Engine Service Account](https://cloud.google.com/compute/docs/authentication). This will allow Packer to authenticate 26 to Google Cloud without having to bake in a separate credential/authentication file. 27 28 To create a GCE instance that uses a service account, provide the required scopes when 29 launching the instance. 30 31 For `gcloud`, do this via the `--scopes` parameter: 32 33 ```sh 34 gcloud compute --project YOUR_PROJECT instances create "INSTANCE-NAME" ... \ 35 --scopes "https://www.googleapis.com/auth/compute" \ 36 "https://www.googleapis.com/auth/devstorage.full_control" \ 37 ... 38 ``` 39 40 For the [Google Developers Console](https://console.developers.google.com): 41 42 1. Choose "Show advanced options" 43 2. Tick "Enable Compute Engine service account" 44 3. Choose "Read Write" for Compute 45 4. Chose "Full" for "Storage" 46 47 **The service account will be used automatically by Packer as long as there is 48 no _account file_ specified in the Packer configuration file.** 49 50 ### Running Without a Compute Engine Service Account 51 52 The [Google Developers Console](https://console.developers.google.com) allows you to 53 create and download a credential file that will let you use the `googlecompute` Packer 54 builder anywhere. To make 55 the process more straightforwarded, it is documented here. 56 57 1. Log into the [Google Developers Console](https://console.developers.google.com) 58 and select a project. 59 60 2. Under the "APIs & Auth" section, click "Credentials." 61 62 3. Click the "Create new Client ID" button, select "Service account", and click "Create Client ID" 63 64 4. Click "Generate new JSON key" for the Service Account you just created. A JSON file will be downloaded automatically. This is your 65 _account file_. 66 67 ## Basic Example 68 69 Below is a fully functioning example. It doesn't do anything useful, 70 since no provisioners are defined, but it will effectively repackage an 71 existing GCE image. The account file is obtained in the previous section. 72 73 ```javascript 74 { 75 "type": "googlecompute", 76 "account_file": "account.json", 77 "project_id": "my-project", 78 "source_image": "debian-7-wheezy-v20150127", 79 "zone": "us-central1-a" 80 } 81 ``` 82 83 ## Configuration Reference 84 85 Configuration options are organized below into two categories: required and optional. Within 86 each category, the available options are alphabetized and described. 87 88 In addition to the options listed here, a 89 [communicator](/docs/templates/communicator.html) 90 can be configured for this builder. 91 92 ### Required: 93 94 * `project_id` (string) - The project ID that will be used to launch instances 95 and store images. 96 97 * `source_image` (string) - The source image to use to create the new image 98 from. Example: `"debian-7-wheezy-v20150127"` 99 100 * `zone` (string) - The zone in which to launch the instance used to create 101 the image. Example: `"us-central1-a"` 102 103 ### Optional: 104 105 * `account_file` (string) - The JSON file containing your account credentials. 106 Not required if you run Packer on a GCE instance with a service account. 107 Instructions for creating file or using service accounts are above. 108 109 * `disk_size` (integer) - The size of the disk in GB. 110 This defaults to `10`, which is 10GB. 111 112 * `image_name` (string) - The unique name of the resulting image. 113 Defaults to `"packer-{{timestamp}}"`. 114 115 * `image_description` (string) - The description of the resulting image. 116 117 * `instance_name` (string) - A name to give the launched instance. Beware 118 that this must be unique. Defaults to `"packer-{{uuid}}"`. 119 120 * `machine_type` (string) - The machine type. Defaults to `"n1-standard-1"`. 121 122 * `metadata` (object of key/value strings) 123 124 * `network` (string) - The Google Compute network to use for the launched 125 instance. Defaults to `"default"`. 126 127 * `state_timeout` (string) - The time to wait for instance state changes. 128 Defaults to `"5m"`. 129 130 * `tags` (array of strings) 131 132 ## Gotchas 133 134 Centos images have root ssh access disabled by default. Set `ssh_username` to any user, which will be created by packer with sudo access. 135 136 The machine type must have a scratch disk, which means you can't use an `f1-micro` or `g1-small` to build images.