hashicorp / packer-plugin-googlecompute

Packer plugin for Google Compute Builder
https://www.packer.io/docs/builders/googlecompute
Mozilla Public License 2.0
24 stars 54 forks source link

builder/googlecompute: Disk not deleted when using custom `disk_name` option #35

Closed hc-github-team-packer closed 2 years ago

hc-github-team-packer commented 3 years ago

This issue was originally opened by @vmoravec in https://github.com/hashicorp/packer/issues/9960 and has been migrated to this repository. The original issue description is below.


Overview of the Issue

While using the googlecompute builder together with the option disk_name, such a disk resource is not deleted when an instance is going to be deleted. Packer ignores the given configuration and creates a VM disk with the name of the instance. However, when deleting the instance, it is looking for the disk set by disk_name although it hasn't been created in the first place . In the end the disk named by the instance, must be deleted manually.

Reproduction Steps

Set disk_name option for the googlecompute builder

Packer version

Packer version: 1.6.2 [go1.13.15 linux amd64]

Simplified Packer Buildfile

{
    "variables": {
      "username": "{{ env `USER` }}",
      "project": "{{ env `GCP_PROJECT` }}",
      "zone": "{{ env `ZONE` }}",
      "subnet": "{{ env `SUBNETWORK` }}"
    },
"builders": [
      {
        "type": "googlecompute",
        "account_file": "/etc/path/{{ user `project` }}-{{ user `username` }}.json",
        "project_id": "{{ user `project` }}",
        "disable_default_service_account": true,
        "source_image": "sles-15-sp2-v20200804",
        "source_image_family": "suse-cloud",
        "ssh_username": "{{ user `username` }}",
        "subnetwork": "{{ user `subnet` }}",
        "zone": "{{ user `zone` }}",
        "tags": [ "packer" ],
        "use_os_login": true,
        "disk_name": "fde-boot-{{ timestamp }}",
        "image_name": "fde-image-{{ timestamp }}",
        "instance_name": "fde-packer-{{ uuid }}",
        "use_internal_ip": true,
        "omit_external_ip": true
      }
    ]
}

Operating system and Environment details

SUSE Linux Enterprise Server 12 SP5

Log Fragments and crash.log files

googlecompute: Instance has been deleted! googlecompute: Deleting disk... ==> googlecompute: ==> googlecompute: Name: fde-packer-5f648664-fdd4-7c62-7474-2358ee05bdd9 ==> googlecompute: Error: googleapi: Error 404: The resource 'projects/project-name/zones/us-central1-a/disks/fde-boot-1600423524' was not found, notFound ==> googlecompute: Error deleting disk. Please delete it manually. ==> googlecompute: ==> googlecompute: Name: fde-packer-5f648664-fdd4-7c62-7474-2358ee05bdd9 ==> googlecompute: Error: googleapi: Error 404: The resource 'projects/project-name/zones/us-central1-a/disks/fde-boot-1600423524' was not found, notFound googlecompute: Disk has been deleted!

nywilken commented 2 years ago

hi @vmoravec I believe this was fixed in https://github.com/hashicorp/packer-plugin-googlecompute/pull/51. Please upgrade to the latest release of the Google Compute plugin for the fix.

packer {
  required_plugins {
    googlecompute = {
      version = ">= 1.0.6"
      source  = "github.com/hashicorp/googlecompute"
    }
  }
}

I am going to close this issue as I believe it has been resolved. But if you are still running into issues with the latest release please leave a comment on this thread and I will gladly reopen. Cheers.