9

How can I delete or update bicep template and all the resources it has deployed? just like we can delete or update cloudformation and terraform template

az deployment commands don't have update option and while using az deployment delete it does not delete the resources

Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107
Jazib Humayun
  • 111
  • 1
  • 2

2 Answers2

13

It has. You need to use Complete mode

az deployment group create -f ./main.bicep -g my-rg --mode Complete

As it is written here

In complete mode, Resource Manager deletes resources that exist in the resource group but aren't specified in the template.

Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107
  • Hey @Krzysztof Madej, thanks for your reply. I am writing Azure Policy which are scoped to subscription and management level. In that case I don't have any resource group where I deploy Azure policies. Do you know how to update or delete resources then ? – Jazib Humayun Jun 17 '21 at 17:41
  • No, it works only with deployments to resource group. I don't know a way how to achieve on deployments on Managemnt Groupe scope. – Krzysztof Madej Jun 17 '21 at 18:17
  • Thankyou for responding back. – Jazib Humayun Jun 17 '21 at 21:44
  • 1
    This won't delete the resources deployed by the bicep template (as the OP asked). Instead, it will delete resources that are *not* in the template. You could remove the resources from the template and then run it again, but it would then still delete any resources that were never in the template... This is not the equivalent of Terraform. – danielvdende Aug 16 '22 at 14:49
  • This only delete the resource. The existing configuration or sub-resource won't be deleted, eg a Cosmos Container, Blob Container ... – Thiện Sinh Sep 03 '22 at 00:45
0

Create an empty bicep file and deploy it in complete mode.

# Create an empty bicep file
echo '' > empty.bicep
# Deploy it into the resource group in 'complete' mode
az deployment group create --template-file empty.bicep --resource-group 'my-rg' --mode complete
# Clean up
rm empty.bicep
Jani Hyytiäinen
  • 5,293
  • 36
  • 45