"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)
Use the Azure Fluent API to deploy the arm template - azure-sql-managed-instance
[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)
AzureClient.Deployments.Define(deploymentName) .WithExistingResourceGroup(resourceGroupName) .WithTemplate(templateJson) .WithParameters(templateParams) .WithMode(DeploymentMode.Incremental) .CreateAsync();
AzureClient.ResourceGroups.DeleteByNameAsync(resourceGroupName);