I’ve been using the tools from HashiCorp (Packer and Terraform) to create images and then build VMs by using Jenkins on AWS. Now I have a project that is on GCloud and I have successfully configured Terraform to create a VM but when I try to run packer I get the following error
root@packer packer]# packer build createImage.json
googlecompute output will be in this color.
==> googlecompute: Checking image does not exist...
==> googlecompute: Creating temporary SSH key for instance...
==> googlecompute: Error getting source image for instance creation: Could not find image, centos-7, in projects, [<PROJECT_ID> centos-cloud coreos-cloud debian-cloud google-containers opensuse-cloud rhel-cloud suse-cloud ubuntu-os-cloud windows-cloud gce-nvme]: 11 error(s) occurred:
==> googlecompute:
==> googlecompute: * googleapi: got HTTP response code 400 with body:
==> googlecompute: * googleapi: got HTTP response code 400 with body:
==> googlecompute: * googleapi: got HTTP response code 400 with body:
==> googlecompute: * googleapi: got HTTP response code 400 with body:
==> googlecompute: * googleapi: got HTTP response code 400 with body:
==> googlecompute: * googleapi: got HTTP response code 400 with body:
==> googlecompute: * googleapi: got HTTP response code 400 with body:
==> googlecompute: * googleapi: got HTTP response code 400 with body:
==> googlecompute: * googleapi: got HTTP response code 400 with body:
==> googlecompute: * googleapi: got HTTP response code 400 with body:
==> googlecompute: * googleapi: got HTTP response code 400 with body:
Build 'googlecompute' errored: Error getting source image for instance creation: Could not find image, centos-7, in projects, [PROJECT_ID centos-cloud coreos-cloud debian-cloud google-containers opensuse-cloud rhel-cloud suse-cloud ubuntu-os-cloud windows-cloud gce-nvme]: 11 error(s) occurred:
* googleapi: got HTTP response code 400 with body:
* googleapi: got HTTP response code 400 with body:
* googleapi: got HTTP response code 400 with body:
* googleapi: got HTTP response code 400 with body:
* googleapi: got HTTP response code 400 with body:
* googleapi: got HTTP response code 400 with body:
* googleapi: got HTTP response code 400 with body:
* googleapi: got HTTP response code 400 with body:
* googleapi: got HTTP response code 400 with body:
* googleapi: got HTTP response code 400 with body:
* googleapi: got HTTP response code 400 with body:
==> Some builds didn't complete successfully and had errors:
--> googlecompute: Error getting source image for instance creation: Could not find image, centos-7, in projects, [PROJECT_ID centos-cloud coreos-cloud debian-cloud google-containers opensuse-cloud rhel-cloud suse-cloud ubuntu-os-cloud windows-cloud gce-nvme]: 11 error(s) occurred:
* googleapi: got HTTP response code 400 with body:
* googleapi: got HTTP response code 400 with body:
* googleapi: got HTTP response code 400 with body:
* googleapi: got HTTP response code 400 with body:
* googleapi: got HTTP response code 400 with body:
* googleapi: got HTTP response code 400 with body:
* googleapi: got HTTP response code 400 with body:
* googleapi: got HTTP response code 400 with body:
* googleapi: got HTTP response code 400 with body:
* googleapi: got HTTP response code 400 with body:
* googleapi: got HTTP response code 400 with body:
==> Builds finished but no artifacts were created.
This is my createImage.json
{
"variables": {
"project_id": "PROJECT_ID"
},
"builders": [
{
"type": "googlecompute",
"region": "europe-west1",
"zone": "europe-west1-b",
"project_id": "{{user `project_id`}}",
"source_image_family": "centos-7",
"image_name": "My-Test-Image",
"disk_size": 10,
"machine_type": "f1-micro",
"ssh_username": "centos"
}
]
}
I should mention that the service account that I am using is even given a owner permission just to be sure that I have no issues with the permissions.
Does anybody has any idea why I have this issue while on AWS it works great.
2
Answers
As you’re not using
"account_file"
to specify a JSON Service Account key, I assume that you’re running packer from a VM instance in GCP that is running as a Service Account, and that such service account is the one withOwner
role.I would first check that the service account is properly configured in the VM details and that the Cloud API Access Scopes are defined as described in this Packer doc:
Additionally, even though I think it’s not related to this issue, you shouldn’t build images using
f1-micro
norg1-small
machine types as per this doc.Finally, I would suggest to post this question also in the Packer Community Forum or any other of the official channels.
Can you list the available images on GCloud and use this information for your json configuration file: