github.com/kaixiang/packer@v0.5.2-0.20140114230416-1f5786b0d7f1/website/source/docs/builders/googlecompute.markdown (about) 1 --- 2 layout: "docs" 3 --- 4 5 # Google Compute Builder 6 7 Type: `googlecompute` 8 9 The `googlecompute` builder is able to create 10 [images](https://developers.google.com/compute/docs/images) 11 for use with [Google Compute Engine](https://cloud.google.com/products/compute-engine) 12 (GCE) based on existing images. Google Compute Engine doesn't allow the creation 13 of images from scratch. 14 15 ## Setting Up API Access 16 17 There is a small setup step required in order to obtain the credentials 18 that Packer needs to use Google Compute Engine. This needs to be done only 19 once if you intend to share the credentials. 20 21 In order for Packer to talk to Google Compute Engine, it will need 22 a _client secrets_ JSON file and a _client private key_. Both of these are 23 obtained from the [Google Cloud Console](https://cloud.google.com/console). 24 25 Follow the steps below: 26 27 1. Log into the [Google Cloud Console](https://cloud.google.com/console) 28 2. Click on the project you want to use Packer with (or create one if you 29 don't have one yet). 30 3. Click "APIs & auth" in the left sidebar 31 4. Click "Registered apps" in the left sidebar 32 5. Click "Register App" and register a "Web Application". Choose any 33 name you'd like. 34 7. After creating the app, click "Certificate" (below the OAuth 2.0 Client 35 ID section), and click "Download JSON". This is your _client secrets JSON_ 36 file. Make sure you didn't download the JSON from the "OAuth 2.0" section! 37 This is a common mistake and will cause the builder to not work. 38 8. Next, click "Generate Certificate". You should be prompted to download 39 a private key. Note the password for the private key! This private key 40 is your _client private key_. 41 42 Finally, one last step, you'll have to convert the `p12` file you 43 got from Google into the PEM format. You can do this with OpenSSL, which 44 is installed standard on most Unixes: 45 46 ``` 47 $ openssl pkcs12 -in <path to .p12> -nocerts -passin pass:notasecret \ 48 -nodes -out private_key.pem 49 ``` 50 51 The client secrets JSON you downloaded along with the new "private\_key.pem" 52 file are the two files you need to configure Packer with to talk to GCE. 53 54 ## Basic Example 55 56 Below is a fully functioning example. It doesn't do anything useful, 57 since no provisioners are defined, but it will effectively repackage an 58 existing GCE image. The client secrets file and private key file are the 59 files obtained in the previous section. 60 61 <pre class="prettyprint"> 62 { 63 "type": "googlecompute", 64 "bucket_name": "packer-images", 65 "client_secrets_file": "client_secret.json", 66 "private_key_file": "XXXXXX-privatekey.p12", 67 "project_id": "my-project", 68 "source_image": "debian-7-wheezy-v20131014", 69 "zone": "us-central1-a" 70 } 71 </pre> 72 73 ## Configuration Reference 74 75 Configuration options are organized below into two categories: required and optional. Within 76 each category, the available options are alphabetized and described. 77 78 Required: 79 80 * `bucket_name` (string) - The Google Cloud Storage bucket to store the 81 images that are created. 82 83 * `client_secrets_file` (string) - The client secrets JSON file that 84 was set up in the section above. 85 86 * `private_key_file` (string) - The client private key file that was 87 generated in the section above. 88 89 * `project_id` (string) - The project ID that will be used to launch instances 90 and store images. 91 92 * `source_image` (string) - The source image to use to create the new image 93 from. Example: "debian-7" 94 95 * `zone` (string) - The zone in which to launch the instance used to create 96 the image. Example: "us-central1-a" 97 98 Optional: 99 100 * `image_name` (string) - The unique name of the resulting image. 101 Defaults to `packer-{{timestamp}}`. 102 103 * `image_description` (string) - The description of the resulting image. 104 105 * `machine_type` (string) - The machine type. Defaults to `n1-standard-1`. 106 107 * `network` (string) - The Google Compute network to use for the launched 108 instance. Defaults to `default`. 109 110 * `passphrase` (string) - The passphrase to use if the `private_key_file` 111 is encrypted. 112 113 * `ssh_port` (int) - The SSH port. Defaults to 22. 114 115 * `ssh_timeout` (string) - The time to wait for SSH to become available. 116 Defaults to "1m". 117 118 * `ssh_username` (string) - The SSH username. Defaults to "root". 119 120 * `state_timeout` (string) - The time to wait for instance state changes. 121 Defaults to "5m". 122 123 ## Gotchas 124 125 Centos images have root ssh access disabled by default. Set `ssh_username` to any user, which will be created by packer with sudo access. 126 127 The machine type must have a scratch disk, which means you can't use an `f1-micro` or `g1-small` to build images.