Skip to content

Instantly share code, notes, and snippets.

@ethanmdavidson
Last active March 14, 2023 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ethanmdavidson/af0c2cacd4c712a13961cf9bab8785ae to your computer and use it in GitHub Desktop.
Save ethanmdavidson/af0c2cacd4c712a13961cf9bab8785ae to your computer and use it in GitHub Desktop.
Packer Configuration for GCP spot/preemptible instances
source googlecompute preemptible-builder {
project_id = "<PROJECT_ID>"
zone = "us-west4-b" # using us-west4 because they have much cheaper spot prices right now.
ssh_username = "packer"
source_image = "debian-11-bullseye-v20230306"
wrap_startup_script = false
disk_size = 10
preemptible = true
metadata = {
#if instance gets preempted, send SIGINT to packer (prevents packer from hanging for 20m trying to reconnect)
#To see if it was really preempted, run gcloud compute operations list --filter="operationType=compute.instances.preempted"
"shutdown-script" : "for pid in $(pgrep -U packer ssh); do sudo kill -2 $pid; done"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment