packer-plugin-googlecompute
packer-plugin-googlecompute copied to clipboard
Persistent disk images not deleted
Overview of the Issue
Root disks are not being cleaned up after image builds. I have found that the VMs which are created are cleaned up, but the root disks are not. I am using c3-highcpu-8 and am attaching 100GB pd-sdd disks. The auto-delete flag does not seem to be set, so builds are just littering the Google project with costly disks.
Reproduction Steps
I used this configuration:
source "googlecompute" "debian" {
project_id = var.project_id
source_image = var.source_image
zone = var.zone
machine_type = var.machine_type
subnetwork = var.subnetwork
service_account_email = "${var.service_account_email}@${var.project_id}.iam.gserviceaccount.com"
instance_name = "${var.image_name}-image-builder-{{timestamp}}"
disk_type = "pd-ssd"
disk_size = 100
image_family = var.image_prefix
image_name = "${var.image_name}-${var.version}"
ssh_username = var.username
}
If image_name is set to "foo", I end up with lingering persistent disks named like: foo-image-builder-1732137234
Plugin and Packer version
Packer: 1.12.0 googlecompute provider: 1.1.6
Simplified Packer Buildfile
build {
sources = ["source.googlecompute.debian"]
provisioner "shell" {
inline = [
"echo 'this is just an example. All provisioners are shell provisioners but I cannot share the details.",
]
}
# ... the build contains 20+ shell provisioners
}
Operating system and Environment details
Debian 24.04 running in GitHub Actions
Log Fragments and crash.log files
Beginning of log
googlecompute.debian: output will be in this color.
==> googlecompute.debian: Checking image does not exist...
==> googlecompute.debian: Creating temporary RSA SSH key for instance...
==> googlecompute.debian: no persistent disk to create
==> googlecompute.debian: Using image: debian-11-bullseye-v20240611
==> googlecompute.debian: Creating instance...
googlecompute.debian: Loading zone: us-east1-b
googlecompute.debian: Loading machine type: c3-highcpu-8
googlecompute.debian: Requesting instance creation...
googlecompute.debian: Waiting for creation operation to complete...
googlecompute.debian: Instance has been created!
==> googlecompute.debian: Waiting for the instance to become running...
googlecompute.debian: IP: 34.23.128.19
==> googlecompute.debian: Using SSH communicator to connect: 34.23.128.19
==> googlecompute.debian: Waiting for SSH to become available...
==> googlecompute.debian: Connected to SSH!
==> googlecompute.debian: Provisioning with shell script: /tmp/packer-shell86024860
The provisioners all run without error. I cannot share details under NDA with my client. But the shells do simple things like configure logrotation, install custom Python software, and configure systemd services.
The logs end with this.
==> googlecompute.debian: Provisioning with shell script: /tmp/packer-shell3241388865
==> googlecompute.debian: Deleting instance...
googlecompute.debian: Instance has been deleted!
==> googlecompute.debian: Creating image...
==> googlecompute.debian: Deleting disk...
googlecompute.debian: Disk has been deleted!
Build 'googlecompute.debian' finished after 9 minutes 4 seconds.
At the end, I observe that the VM has been deleted, but the 100GB disk is still there.