I know we can create infrastructure using ARM templates. Can we do the same for deleting the Resources. I dont want to delete all the entire resource group but few resources in a resource group. Is this possible through ARM Templates?


Solution 1:

Sort of. When you deploy an ARM template you can do it in two modes, Incremental or Complete. Incremental is the default and will add resources to a resource group and change the configuration on existing ones, but it will not delete them. If you switch your ARM template deployment to using the Complete mode, then it will make your resource group match exactly what is in your ARM template, and remove anything that is outside of that.

Obviously, you need to be careful with this.

To do a Complete deployment in PowerShell run this command

New-AzureRMResourceGroupDeployment -name "deploymentName" -resourceGroup "resourceGroupName" -templateFile "path to template"  -mode complete