Using Bicep to delete the resources

BATRA, SUDEEP 6 Reputation points
2022-12-14T05:13:35.633+00:00

I used the below command to create resources :
az deployment group create --resource-group jnfcrg01 --template-file ./deploy/main.bicep

How do I delete these resources as well ?

I need to create both deploy and destroy Pipelines, so cant find useful details for the destroy part.

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,937 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. VenkateshDodda-MSFT 24,951 Reputation points Microsoft Employee Moderator
    2022-12-14T11:46:11.19+00:00

    @BATRA, SUDEEP Thanks for reaching out to Microsoft Q&A, apologize for any inconvenience caused on this.

    We don't have any default cmdlet to delete the resources that were created using arm template or through bicep template.

    When deploying your resources, you specify that the deployment is either an incremental update or a complete update. The difference between these two modes is how Resource Manager handles existing resources in the resource group that aren't in the template.

    For both modes, Resource Manager tries to create all resources specified in the template. If the resource already exists in the resource group and its settings are unchanged, no operation is taken for that resource. If you change the property values for a resource, the resource is updated with those new values. If you try to update the location or type of an existing resource, the deployment fails with an error. Instead, deploy a new resource with the location or type that you need.

    • The default mode is incremental.
    • Complete mode: In complete mode, Resource Manager deletes resources that exist in the resource group but aren't specified in the template.

    Note : Always use the what-if operation before deploying a template in complete mode. What-if shows you which resources will be created, deleted, or modified. Use what-if to avoid unintentionally deleting resources.

    • If your deployment got failed and if you want to roll back to last successful recent deployment you can use the parameter -RollbackToLastDeployment in the az deployment group create cmdlet which has couple of limitations as well refer to this documentation.

    Feel free to reach back to me if you have any further questions on this.

    1 person found this answer helpful.
    0 comments No comments

  2. BATRA, SUDEEP 6 Reputation points
    2023-02-03T20:24:22.9366667+00:00

    Thanks so I observed in the az cli I have to use --mode complete as below

    az deployment group create --template-file deploy/delete.bicep --what-if -g testcrg01 --mode complete

    However in the Pipeline I have to use

    deploymentMode: Complete
    

    Ref : https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/azure-resource-manager-template-deployment-v3?view=azure-pipelines

    1 person found this answer helpful.
    0 comments No comments

  3. BATRA, SUDEEP 6 Reputation points
    2023-02-03T20:49:39.7233333+00:00

    I do have one question - how do I use What-if in a Pipeline ?

    Can you share an example ?


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.