An Azure service that is used to automate, configure, and install updates across hybrid environments.
Hello Varma !
Thank you for posting on MS Learn Q&A.
You can use one PS runbook to deploy resources and another runbook to delete them.
Azure Automation supports PS runbooks, and Microsoft documents using a runbook to deploy Azure resources from an ARM template. It also supports managed identity so the runbook can authenticate to Azure without storing credentials.
To deploy runbook, you need to authenticate with the automation account managed identity and create your resources by deploying an ARM template, Bicep or direct Az PS commands. Then put everything in a dedicated resource group if possible
To delete runbook, authenticate the same way and delete the whole resource group or delete individual resources if needed. If you delete the resource group, Azure removes all resources in it
The delete the whole resource group approach is usually best because it is simpler and avoid missing dependent resources.
# Deploy runbook
Connect-AzAccount -Identity
$rg = "rg-cloudcompute-dev-01"
$location = "westeurope"
New-AzResourceGroup -Name $rg -Location $location -Force
New-AzResourceGroupDeployment `
-ResourceGroupName $rg `
-TemplateFile "C:\Templates\main.json" `
-TemplateParameterFile "C:\Templates\main.parameters.json"
# Delete runbook
Connect-AzAccount -Identity
$rg = "rg-cloudcompute-dev-01"
Remove-AzResourceGroup -Name $rg -Force