hashicorp / packer-plugin-azure

Packer plugin for Azure Virtual Machine Image Builders
https://www.packer.io/docs/builders/azure
Mozilla Public License 2.0
47 stars 76 forks source link

fix: [arm builder] storage blob VHD deletion, cleanup post build deletion #410

Closed JenGoldstrich closed 2 months ago

JenGoldstrich commented 2 months ago

This PR has three main purposes

Closes #409 Closes #273

Before this PR when building a VHD image with additional disks that should be deleted, you can see extra print statements at the bottom of 2, and my storage account as well as the failed additional disk deletion, and NIC repeated retry errors.

==> azure-arm:
==> azure-arm: Deleting Virtual Machine deployment and its attached resources...
==> azure-arm: Adding to deletion queue -> Microsoft.Compute/virtualMachines : 'replaced'
==> azure-arm: Adding to deletion queue -> Microsoft.Network/networkInterfaces : 'replaced'
==> azure-arm: Adding to deletion queue -> Microsoft.Network/virtualNetworks : 'replaced'
==> azure-arm: Adding to deletion queue -> Microsoft.Network/publicIPAddresses : 'replaced'
==> azure-arm: Waiting for deletion of all resources...
==> azure-arm: Attempting deletion -> Microsoft.Compute/virtualMachines : 'replaced'==> azure-arm: Attempting deletion -> Microsoft.Network/publicIPAddresses : 'replaced'
==> azure-arm: Attempting deletion -> Microsoft.Network/virtualNetworks : 'replaced'==> azure-arm: Attempting deletion -> Microsoft.Network/networkInterfaces : 'replaced'
==> azure-arm: Couldn't delete Microsoft.Network/publicIPAddresses resource. Will retry.
==> azure-arm: Name: replaced
==> azure-arm: Couldn't delete Microsoft.Network/virtualNetworks resource. Will retry.
==> azure-arm: Name: replaced
==> azure-arm: Attempting deletion -> Microsoft.Network/publicIPAddresses : 'replaced'
==> azure-arm: Attempting deletion -> Microsoft.Network/virtualNetworks : 'replaced'==> azure-arm: Skipping deletion -> image : 'https://removedstorageaccount.blob.core.windows.net/images/removed.vhd' since 'keep_os_disk' is set to true
==> azure-arm:  Deleting Additional Disk -> 1: 'https://removedstorageaccount.blob.core.windows.net/images/pkrdisk-1.vhd'
==> azure-arm: Failed to delete the managed Additional Disk!
==> azure-arm:  Deleting Additional Disk -> 2: 'https://removedstorageaccount.blob.core.windows.net/images/pkrdisk-2.vhd'
==> azure-arm: Failed to delete the managed Additional Disk!
==> azure-arm: Removing the created Deployment object: 'pkrdplafewlqjyv'
==> azure-arm:
==> azure-arm: The resource group was not created by Packer, not deleting ...
==> azure-arm: https://removedstorageaccount.blob.core.windows.net/
==> azure-arm: 2
Build 'azure-arm' finished after 3 minutes 6 seconds.

After

==> azure-arm: Deleting Virtual Machine deployment and its attached resources...
==> azure-arm: Deleted -> Microsoft.Compute/virtualMachines : 'pkrvmq58v6zr4b1'
==> azure-arm: Deleted -> Microsoft.Network/networkInterfaces : 'pkrniq58v6zr4b1'
==> azure-arm: Deleted -> Microsoft.Network/publicIPAddresses : 'pkripq58v6zr4b1'
==> azure-arm: Deleted -> Microsoft.Network/virtualNetworks : 'pkrvnq58v6zr4b1'
==> azure-arm: Skipping deletion -> image : 'https://removed.blob.core.windows.net/images/removed.vhd' since 'keep_os_disk' is set to true
==> azure-arm:  Deleted Additional Disk -> 1: 'https://removed.blob.core.windows.net/images/removed-1.vhd'
==> azure-arm:  Deleted Additional Disk -> 2: 'https://removed.blob.core.windows.net/images/removed-2.vhd'
==> azure-arm: Removing the created Deployment object: 'pkrdpq58v6zr4b1'
==> azure-arm:
==> azure-arm: The resource group was not created by Packer, not deleting ...
Build 'azure-arm' finished after 3 minutes 1 second.