1

We can do a deploy using the Az CLI with the following command, for example:

az deployment group create --resource-group testrg --name rollout01 \
    --template-uri https://myresource/azuredeploy.json --parameters @myparameters.json

The mode by default is Incremental and it could be changed Complete, which deletes everything in the resource group when we do a deploy.

But what if i simply want to do a revert of the previous infrastructure deploy? lets suppose the deploy added an app service in a resource group that already had many things. Now i only want to delete that app service, i don't want to do it manually (it could have been a lot more complex infrastructure deployment, i mention an app service to simplify), i just want to revert everything from the deploy and have the app service deleted.

I found this command az deployment group delete but it only seems to delete the history of the deployment resource, that is not what i want, i want to delete the resources created by the deployment.

Is there a way to do this?

old_timer
  • 69,149
  • 8
  • 89
  • 168
Nmaster88
  • 1,405
  • 2
  • 23
  • 65
  • 1
    Use Deployment Slot.Please refer [Rollback Your Deployment Using Deployment Slot](https://www.c-sharpcorner.com/article/azure-webapp-rollback-your-deployment-using-deployment-slot/#:~:text=Azure%20WebApp%20-%20Rollback%20Your%20Deployment%20Using%20Deployment,Click%20ok%20to%20create%20new%20deployment%20slot.%20) – Harshitha Veeramalla Feb 14 '22 at 12:05
  • 1
    @HarshithaVeeramalla-MT thanks for the reply. This is not an app service deployment slot problem. Sry for not making it clear, but i'm referring to infrastructure deploy. – Nmaster88 Feb 14 '22 at 14:05

2 Answers2

0

The short answer to your question is it isn't possible. The concept in Azure is that all resources that are part of the same lifecycle should be placed into a separate resource group.

To see a more complete discussion around that topic you can check out: How to remove all deployed resources based on deployment name in Azure

Everton Oliveira
  • 810
  • 7
  • 15
  • Yes, unfortunately i think for now if we want to do something like this we should deploy everything to the same resource group and delete the resource group if we want a "rollback", but sometimes thats not an option since we want to do a deploy to an already existing resource group. – Nmaster88 Feb 14 '22 at 16:21
  • Yes, It'd be useful to have a feature like that. – Everton Oliveira Feb 14 '22 at 16:45
  • The concept you explain here is incorrect. Of course you can deploy to multiple resource groups in the same deployment. and you can roll back specific version by simply redeploying an earlier version – Muhammad Gouda Jul 29 '22 at 11:11
0

There are 2 points of time when you can rollback your current deployment to a previous stable version

1- During the deployment:

Let's assume you have version 1 deployed to your environment, and while deploying version 2, something went wrong in the middle of the deployment. In such case, your IaC should include a mitigation step which rolls back on error as explained here

2- After the deployment:

Let's assume you have completed the deployment of version 2 which includes punch of new resources, then you want to roll back to version 1. In such case, you simply redeploy version 1.

Note: For the second scenario, you need to pay attentions to stateful resources (i.e. data storages) because redeploying version 1 may destroy and recreate those resources leading to data loss. If this is your case, you should consider data migration in your roll back plan

Muhammad Gouda
  • 849
  • 8
  • 20
  • The 'rollback' approach you're suggesting is misleading, read carefully what was the question and the considerations in the article you quoted. Rollback should undo any resource created or modified when a failure occurs, and not create a new deployment. In addition to that, what you are suggesting wipes out the Resource Group by issuing a 'Complete' mode even if you used Incremental mode in previous deployments, in other words, resources that were not touched by the current deployment will also be affected. This is not a rollback. – Everton Oliveira Jul 30 '22 at 17:53