Azure / Azure/azure-quickstart-templates
Failed to delete the resource group after deploying azure-sql-managed-instance arm template
- Dominant language
- Bicep
- Stars
- 14.9k
- Forks
- 16.2k
- Avg merge
- 6d 21h
- Merged PRs (30d)
- 6
Description
[Template Name goes here](Template link goes here)
https://github.com/Azure/azure-quickstart-templates/tree/master/azure-sql-managed-instance
### Issue Details
Failed to delete the resource group after deploying the template - https://github.com/Azure/azure-quickstart-templates/tree/master/azure-sql-managed-instance, the errors are:
"errorMessage": "{\"Error\":{\"Code\":\"ResourceGroupDeletionBlocked\",\"Target\":null,\"Message\":\"Deletion of resource group 'RVT_201907200320595942' failed as resources with identifiers 'Microsoft.Network/networkSecurityGroups/mi-NSG,Microsoft.Network/routeTables/mi-RouteTable,Microsoft.Network/virtualNetworks/virtualNetwork,Microsoft.Network/networkIntentPolicies/1467cb73-bbcd-4757-bd4b-b87c02b514be' could not be deleted. The provisioning state of the resource group will be rolled back. The tracking Id is '0ca27bec-e01a-4a5a-b6f9-fccad58c8735'. Please check audit logs for more details.\",\"Details\":[{\"Code\":null,\"Target\":\"/subscriptions/dfba1966-11a1-444b-a6bf-10f70f247a4e/resourceGroups/RVT_201907200320595942/providers/Microsoft.Network/networkSecurityGroups/mi-NSG\",\"Message\":\"{\\\"error\\\":{\\\"code\\\":\\\"InUseNetworkSecurityGroupCannotBeDeleted\\\",\\\"message\\\":\\\"Network security group /subscriptions/dfba1966-11a1-444b-a6bf-10f70f247a4e/resourceGroups/RVT_201907200320595942/providers/Microsoft.Network/networkSecurityGroups/mi-NSG cannot be deleted because it is in use by the following resources: /subscriptions/dfba1966-11a1-444b-a6bf-10f70f247a4e/resourceGroups/RVT_201907200320595942/providers/Microsoft.Network/virtualNetworks/virtualNetwork/subnets/mi-subnet. In order to delete the Network security group, remove the association with the resource(s). To learn how to do this, see aka.ms/deletensg.\\\",\\\"details\\\":[]}}\",\"Details\":null,\"AdditionalInfo\":null},{\"Code\":null,\"Target\":\"/subscriptions/dfba1966-11a1-444b-a6bf-10f70f247a4e/resourceGroups/RVT_201907200320595942/providers/Microsoft.Network/routeTables/mi-RouteTable\",\"Message\":\"{\\\"error\\\":{\\\"code\\\":\\\"InUseRouteTableCannotBeDeleted\\\",\\\"message\\\":\\\"Route table mi-RouteTable is in use and cannot be deleted.\\\",\\\"details\\\":[]}}\",\"Details\":null,\"AdditionalInfo\":null},{\"Code\":null,\"Target\":\"/subscriptions/dfba1966-11a1-444b-a6bf-10f70f247a4e/resourceGroups/RVT_201907200320595942/providers/Microsoft.Network/virtualNetworks/virtualNetwork\",\"Message\":\"{\\\"error\\\":{\\\"code\\\":\\\"InUseSubnetCannotBeDeleted\\\",\\\"message\\\":\\\"Subnet mi-subnet is in use by /subscriptions/dfba1966-11a1-444b-a6bf-10f70f247a4e/resourceGroups/RVT_201907200320595942/providers/Microsoft.Sql/virtualClusters/VirtualCluster3d31c30d-1da4-48ac-86fe-47de80620cdb?api-version=2015-05-01-preview and cannot be deleted. In order to delete the subnet, delete all the resources within the subnet. See aka.ms/deletesubnet.\\\",\\\"details\\\":[]}}\",\"Details\":null,\"AdditionalInfo\":null},{\"Code\":null,\"Target\":\"/subscriptions/dfba1966-11a1-444b-a6bf-10f70f247a4e/resourceGroups/RVT_201907200320595942/providers/Microsoft.Network/networkIntentPolicies/1467cb73-bbcd-4757-bd4b-b87c02b514be\",\"Message\":\"{\\\"error\\\":{\\\"code\\\":\\\"NetworkIntentPolicyCannotBeDeletedIfReferencedBySubnet\\\",\\\"message\\\":\\\"Network Intent Policy /subscriptions/dfba1966-11a1-444b-a6bf-10f70f247a4e/resourceGroups/RVT_201907200320595942/providers/Microsoft.Network/networkIntentPolicies/1467cb73-bbcd-4757-bd4b-b87c02b514be cannot be deleted because it is in use with subnet(s) mi-subnet.\\\",\\\"details\\\":[]}}\",\"Details\":null,\"AdditionalInfo\":null}],\"AdditionalInfo\":null}}"
We need to perform the cleanup by deleting the resource group, how can we delete the resource group successfully?
### Repro steps (*if necessary, delete otherwise*)
1. Use the Azure Fluent API to deploy the arm template - azure-sql-managed-instance
AzureClient.Deployments.Define(deploymentName)
.WithExistingResourceGroup(resourceGroupName)
.WithTemplate(templateJson)
.WithParameters(templateParams)
.WithMode(DeploymentMode.Incremental)
.CreateAsync();
2. After the deployment was finished successfully, we again use the Azure Fluent API to delete the template
AzureClient.ResourceGroups.DeleteByNameAsync(resourceGroupName);
3. Get the above errors
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by inspecting the azure-sql-managed-instance template and the Azure Fluent API deployment and resource-group deletion calls described in the repro steps. Review the reported dependencies among mi-NSG, mi-RouteTable, virtualNetwork, mi-subnet, and the SQL virtual cluster. Done means the template can be deployed and its resource group deleted successfully without the reported in-use resource errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure
- Domain
- cloud, databases, networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100