-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
provider/azurerm: Fix VHD deletion when VM and Storage account are in separate resource groups #9631
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice spot on this case!
Could you add a test for this scenario?
Cheers
@@ -314,6 +315,12 @@ func (c *Config) getArmClient() (*ArmClient, error) { | |||
tc.Sender = autorest.CreateSender(withRequestLogging()) | |||
client.tagsClient = tc | |||
|
|||
rf := resources.NewClient(c.SubscriptionID) | |||
setUserAgent(&tc.Client) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tc.Client
=> rf.Client
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good spot 👍
I'm currently working on improving the current VHD opt in test case. |
0493b93
to
324e879
Compare
I will run a full set of VM tests tomorrow. If they pass, I'll make this ready for review. |
Thanks @carinadigital :) |
Original code failing with new test at
Tests after new commits added.
|
Hey @carinadigital Is there any way that we can test this within the nightly acceptance tests? P. |
ah wait, I just noticed that you have already taken care of it within a test :) |
I've improved the TestAccAzureRMVirtualMachine_deleteVHDOptIn() test. I didn't think we needed a deletion test for both disk in same resource group and separate resource group. |
Full test results passing above. On that note, a reminder to myself to proposing increasing acceptance test timeout. 120 minutes is far too short for the VM tests. Ready for review. |
// Storage Account ID is in the form | ||
// /subscriptions/[SUBSCRIPTION_ID]/resourceGroups/[RESOURCE_GROUP]/providers/Microsoft.Storage/storageAccounts/[STORAGE_ACCOUNT] | ||
idSplit := strings.Split(strings.TrimPrefix(*results[0].ID, "/"), "/") | ||
storageAccountResourceGroupName := idSplit[3] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using parseAzureResourceID
would be cleaner here, would allow you to catch any errors too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. I didn't know that existed. Fixing.
…ource group when deleting VHDs.
324e879
to
a068da0
Compare
Thanks for the work here @carinadigital :) This LGTM! P. |
… separate resource groups (hashicorp#9631) * Improve messaging when storage account isn't found. * Add client for finding resources when you don't know it's resource group. * Add function to find Storage Account resource group name. * Use the storage account resource group, not the virtual machine's resource group when deleting VHDs. * Add description of storage account ID for clarity. * Improve VHD deletion test when storage account is in different resource group. * Use common function for ID parsing of storage account.
… separate resource groups (hashicorp#9631) * Improve messaging when storage account isn't found. * Add client for finding resources when you don't know it's resource group. * Add function to find Storage Account resource group name. * Use the storage account resource group, not the virtual machine's resource group when deleting VHDs. * Add description of storage account ID for clarity. * Improve VHD deletion test when storage account is in different resource group. * Use common function for ID parsing of storage account.
… separate resource groups (hashicorp#9631) * Improve messaging when storage account isn't found. * Add client for finding resources when you don't know it's resource group. * Add function to find Storage Account resource group name. * Use the storage account resource group, not the virtual machine's resource group when deleting VHDs. * Add description of storage account ID for clarity. * Improve VHD deletion test when storage account is in different resource group. * Use common function for ID parsing of storage account.
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
delete_os_disk_on_termination
anddelete_data_disk_on_termination
don't always remove the VHD disk blob when deleting a Virtual Machine.This is because it assumes the storage account resource group is the same as the virtual machine's resource group.
Unfortunately I can't find any information on the virtual machine that stores the storage account resource group and so I've had to go back the API. The only method I've found is to list the resources here https://godoc.org/github.com/Azure/azure-sdk-for-go/arm/resources/resources#Client.List
Other suggestions are welcome.