Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged

Conversation

JenGoldstrich
Copy link
Contributor

@JenGoldstrich JenGoldstrich commented Apr 17, 2024

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.

@JenGoldstrich JenGoldstrich force-pushed the fix_storage_account_delete_and_tidy_deletion_process branch from 1134baf to 94d542c Compare April 17, 2024 21:38
@JenGoldstrich JenGoldstrich changed the title Fix incorrect arguments passed into storage account and delete VM and… fix: storage account deletion wrong params, nic disaccoiation repeated errors every build Apr 17, 2024
storageAccountAuthorizer, err := commonclient.BuildStorageAuthorizer(ctx, authOptions, *cloud)
if err != nil {
return nil, err
}

blobClient, err := giovanniBlobStorageSDK.NewWithBaseUri(cloud.Storage.Name())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually was just passing in "AzureStorage" as a string, however the client never invoked this so we never ran into the issue since Delete blobs endpoint previously accepted storage account, now we had to give it this URL.

See https://learn.microsoft.com/en-us/azure/storage/common/storage-account-overview#standard-endpoints for more info

@JenGoldstrich JenGoldstrich marked this pull request as ready for review April 17, 2024 23:14
@JenGoldstrich JenGoldstrich requested a review from a team as a code owner April 17, 2024 23:14
@@ -143,7 +143,7 @@ func (s *StepDeployTemplate) Cleanup(state multistep.StateBag) {

err := s.deleteImage(ctx, additionaldisk, resourceGroupName, (isManagedDisk || isSIGImage), subscriptionId, armStorageAccountName)
if err != nil {
s.say("Failed to delete the managed Additional Disk!")
s.say(fmt.Sprintf("Failed to delete the managed Additional Disk! %s", err))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We weren't actually logging the error here 🤦‍♀️

@@ -22,7 +22,7 @@ require (
github.com/hashicorp/go-azure-sdk/resource-manager v0.20240411.1145857
github.com/hashicorp/go-azure-sdk/sdk v0.20240411.1145857
github.com/mitchellh/go-homedir v1.1.0
github.com/tombuildsstuff/giovanni v0.25.3
github.com/tombuildsstuff/giovanni v0.26.1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This update isn't required, I was just seeing when the change was introduced and figured I'd upgrade while testing

builder/azure/arm/step_deploy_template.go Outdated Show resolved Hide resolved
builder/azure/arm/step_deploy_template.go Outdated Show resolved Hide resolved
builder/azure/arm/step_deploy_template.go Outdated Show resolved Hide resolved
builder/azure/arm/step_deploy_template.go Outdated Show resolved Hide resolved
@JenGoldstrich JenGoldstrich changed the title fix: storage account deletion wrong params, nic disaccoiation repeated errors every build fix: storage account deletion wrong params, cleanup post build deletion Apr 19, 2024
@JenGoldstrich JenGoldstrich force-pushed the fix_storage_account_delete_and_tidy_deletion_process branch 4 times, most recently from b4959b7 to f555542 Compare April 20, 2024 00:59
@@ -191,9 +274,6 @@ func (s *StepDeployTemplate) getImageDetails(ctx context.Context, subscriptionId
defer cancel()
vmID := virtualmachines.NewVirtualMachineID(subscriptionId, resourceGroupName, computeName)
vm, err := s.client.VirtualMachinesClient.Get(pollingContext, vmID, virtualmachines.DefaultGetOperationOptions())
if err != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was invalid code, the lower error was unreachable

@JenGoldstrich JenGoldstrich changed the title fix: storage account deletion wrong params, cleanup post build deletion fix: [arm builder] storage account deletion wrong params, cleanup post build deletion Apr 20, 2024
@JenGoldstrich JenGoldstrich changed the title fix: [arm builder] storage account deletion wrong params, cleanup post build deletion fix: [arm builder] storage blob deletion wrong params, cleanup post build deletion Apr 20, 2024
builder/azure/arm/step_deploy_template.go Outdated Show resolved Hide resolved
builder/azure/arm/step_deploy_template.go Outdated Show resolved Hide resolved
builder/azure/arm/step_deploy_template.go Outdated Show resolved Hide resolved
builder/azure/arm/step_deploy_template.go Outdated Show resolved Hide resolved
@lbajolet-hashicorp lbajolet-hashicorp force-pushed the fix_storage_account_delete_and_tidy_deletion_process branch from 0d99043 to 5362dbe Compare April 24, 2024 17:48
s.reportResourceDeletionFailure(err, resourceName)
}
return err

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiniest of nits: extra blank line here

Copy link
Contributor

@lbajolet-hashicorp lbajolet-hashicorp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few last nits, but overall this LGTM!

builder/azure/arm/step_deploy_template.go Outdated Show resolved Hide resolved
@JenGoldstrich JenGoldstrich force-pushed the fix_storage_account_delete_and_tidy_deletion_process branch from 0eebcbe to a542433 Compare April 29, 2024 16:01
@JenGoldstrich JenGoldstrich changed the title fix: [arm builder] storage blob deletion wrong params, cleanup post build deletion fix: [arm builder] storage blob VHD deletion, cleanup post build deletion Apr 29, 2024
@JenGoldstrich JenGoldstrich force-pushed the fix_storage_account_delete_and_tidy_deletion_process branch from 9ed6f31 to 8090c68 Compare April 29, 2024 20:44
@JenGoldstrich JenGoldstrich merged commit d474ba5 into main Apr 29, 2024
12 checks passed
@JenGoldstrich JenGoldstrich deleted the fix_storage_account_delete_and_tidy_deletion_process branch April 29, 2024 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

v2.1.0: Storage account deletion URI invalid, wrong parameters sent NIC not disassociated before deletion
2 participants