github.com/daniellockard/packer@v0.7.6-0.20141210173435-5a9390934716/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 intance. 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-v20140718", 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 ### Required: 89 90 * `project_id` (string) - The project ID that will be used to launch instances 91 and store images. 92 93 * `source_image` (string) - The source image to use to create the new image 94 from. Example: "debian-7" 95 96 * `zone` (string) - The zone in which to launch the instance used to create 97 the image. Example: "us-central1-a" 98 99 ### Optional: 100 101 * `account_file` (string) - The JSON file containing your account credentials. 102 Not required if you run Packer on a GCE instance with a service account. 103 Instructions for creating file or using service accounts are above. 104 105 * `disk_size` (integer) - The size of the disk in GB. 106 This defaults to 10, which is 10GB. 107 108 * `image_name` (string) - The unique name of the resulting image. 109 Defaults to `packer-{{timestamp}}`. 110 111 * `image_description` (string) - The description of the resulting image. 112 113 * `instance_name` (string) - A name to give the launched instance. Beware 114 that this must be unique. Defaults to "packer-{{uuid}}". 115 116 * `machine_type` (string) - The machine type. Defaults to `n1-standard-1`. 117 118 * `metadata` (object of key/value strings) 119 120 * `network` (string) - The Google Compute network to use for the launched 121 instance. Defaults to `default`. 122 123 * `ssh_port` (integer) - The SSH port. Defaults to 22. 124 125 * `ssh_timeout` (string) - The time to wait for SSH to become available. 126 Defaults to "1m". 127 128 * `ssh_username` (string) - The SSH username. Defaults to "root". 129 130 * `state_timeout` (string) - The time to wait for instance state changes. 131 Defaults to "5m". 132 133 * `tags` (array of strings) 134 135 ## Gotchas 136 137 Centos images have root ssh access disabled by default. Set `ssh_username` to any user, which will be created by packer with sudo access. 138 139 The machine type must have a scratch disk, which means you can't use an `f1-micro` or `g1-small` to build images.