Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
google cloud - account.json file for packer

The problem

The document quality of Google Cloud is far away if compare with AWS. Here is a sample.

If you met below error, when running packer or other SDK,

$ cat packer.json
  "builders": [
      "type": "googlecompute",
      "account_file": "account.json",
      "project_id": "qwiklabs-gcp-03-be761527bd29",
      "source_image": "debian-7-wheezy-v20150127",
      "ssh_username": "packer",
      "zone": "us-central1-a"

Without account.json, you will get some errors.

error: google: could not find default credentials. See for more information.


Build 'googlecompute' errored: google: could not find default credentials. See for more information.

As a new user of Google cloud, I have no idea about this account.json. So if you try to get help from the url provided above (, you will totally lost.


gcloud auth application-default login

above command will generate a json file with full path

Credentials saved to file: [/Users/xxxx/.config/gcloud/application_default_credentials.json]

copy it to local, such as account.json which need be used by packer. Below is a sample of it

  "client_id": "",
  "client_secret": "d-FL95Q19q7MQmFpd7hHD0Xy",
  "refresh_token": "1//0g7OKxcamC964CgYIARAAGBASNwF-L9IrUWmjvmCGAiLIPveIbTHuli3sEVI8oKIUzVE7rZL1kB4hswsAiMDdSTrJWUC2G_9Q8aA",
  "type": "authorized_user"

You can run the packer command as normal, everything is fine now.

$ packer build packer.json
googlecompute output will be in this color.

==> googlecompute: Checking image does not exist...
==> googlecompute: Creating temporary SSH key for instance...
==> googlecompute: Using image: debian-7-wheezy-v20150127
==> googlecompute: Creating instance...
    googlecompute: Loading zone: us-central1-a
    googlecompute: Loading machine type: n1-standard-1
    googlecompute: Requesting instance creation...
    googlecompute: Waiting for creation operation to complete...
    googlecompute: Instance has been created!
==> googlecompute: Waiting for the instance to become running...
    googlecompute: IP:
==> googlecompute: Using ssh communicator to connect:
==> googlecompute: Waiting for SSH to become available...
==> googlecompute: Connected to SSH!
==> googlecompute: Deleting instance...
^@^@    googlecompute: Instance has been deleted!
==> googlecompute: Creating image...
==> googlecompute: Deleting disk...
    googlecompute: Disk has been deleted!
Build 'googlecompute' finished.

==> Builds finished. The artifacts of successful builds are:
--> googlecompute: A disk image was created: packer-1587448303


The wrong direction

Why I can't get help from google search, because it always directs you with wrong document/wiki.

If you search key words google cloud packer, you first get this url, which makes you lost that why I need cloudbuild (google's cicd) to build a image

The second url ( also makes the simple job too complex, and I don't know what it tries to teach.

Then I am back to packer homepage (, I am surprise, hashicorp packer doesn't give any explain for this file account.json as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment