[Solved] Google cloud packer - time out while waiting for instance to create

Hello,

I have a problem with building a simple ubuntu vm image on google cloud.

I’ve tried adding every permission I’ve found in google to my service account with no effect.

I’ve tried following this article: (with the difference that I’m trying to use packer from my local machine because I want to build a few more images for completely different purposes as well)

The permissions I’ve added to the service account so far:

larry@ubuntu2204:/host$ gcloud projects add-iam-policy-binding $PROJECT --role roles/iam.serviceAccountAdmin     --member serviceAccount:$SA_EMAIL
Updated IAM policy for project [account].
bindings:
- members:
  - serviceAccount:[email protected]
  role: roles/compute.admin
- members:
  - serviceAccount:[email protected]
  role: roles/compute.instanceAdmin.v1
- members:
  - serviceAccount:[email protected]
  role: roles/compute.networkAdmin
- members:
  - serviceAccount:[email protected]
  role: roles/compute.securityAdmin
- members:
  - serviceAccount:[email protected]
  role: roles/compute.serviceAgent
- members:
  - serviceAccount:[email protected]
  role: roles/editor
- members:
  - serviceAccount:[email protected]
  role: roles/iam.serviceAccountActor
- members:
  - serviceAccount:[email protected]
  role: roles/iam.serviceAccountAdmin
- members:
  - user:[email protected]
  role: roles/owner
- members:
  - serviceAccount:[email protected]
  role: roles/storage.admin
etag: BwYBGG7Rv2E=
version: 1

the log I get from packer:

larry@ubuntu2204:/host/jenkins-agent$ ../packer build jenkins-agent.json 
googlecompute: output will be in this color.

==> googlecompute: Checking image does not exist...
==> googlecompute: Creating temporary RSA SSH key for instance...
==> googlecompute: Using image: ubuntu-2204-jammy-v20230714
==> googlecompute: Creating instance...
    googlecompute: Loading zone: europe-west3-c
    googlecompute: Loading machine type: n1-standard-1
    googlecompute: Requesting instance creation...
    googlecompute: Waiting for creation operation to complete...
==> googlecompute: Error creating instance: time out while waiting for instance to create
Build 'googlecompute' errored after 5 minutes 5 seconds: Error creating instance: time out while waiting for instance to create

==> Wait completed after 5 minutes 5 seconds

==> Some builds didn't complete successfully and had errors:
--> googlecompute: Error creating instance: time out while waiting for instance to create

==> Builds finished but no artifacts were created.

jenkins-agent.json file

{
  "builders": [
    {
      "type": "googlecompute",
      "project_id": "mydomainjenkins",
      "source_image_family": "ubuntu-2204-lts",
      "source_image_project_id": "ubuntu-os-cloud",
      "zone": "europe-west3-c",
      "disk_size": "50",
      "image_name": "jenkins-agent-{{timestamp}}",
      "image_family": "jenkins-agent",
      "ssh_username": "ubuntu"
    }
  ],
  "provisioners": [
    {
      "type":"file",
      "source":"docker.gpg",
      "destination": "/docker.gpg"
    },
    {
      "type": "shell",
      "script": "provision.sh"
    }
  ]
}```

I fixed my issue by installing packer on the ubuntu system from here:

(I don’t mind installing random garbage on this system because its a container specifically for messing with gcp)

After doing so the cli tool acquired a capability of telling me that the region I chose is at capacity so no VM is going to be created… instead of hanging for 5 minutes and telling me that there as a timeout with no further details.

Region chage in the builder definition allowed the image to be built.