azure-devopsazure-data-factoryazure-powershellazure-resource-lock

How to stop a Storage Event Trigger of Azure Data Factory using Powershell when there is a Delete lock on the Resource group?


I want to stop a Storage Event Trigger that is on my data factory before I make modifications to the factory using ARM deployment/Azure DevOps. There is a Delete lock on my resource group which is causing the below error when I try to stop the trigger using powershell (Stop-AzDataFactoryV2Trigger) :

Error Code: BadRequest
Error Message: The scope '/subscriptions/XXX/resourceGroups/XXX/providers/Microsoft.Storage/storageAccounts/XXX/providers/Microsoft.EventGrid/eventSubscriptions/XXX' 
cannot perform delete operation because following scope(s) are locked: '/subscriptions/XXX/resourceGroups/XXX'. Please remove the lock and try again.

Is there any way to do my ADF deployments without having to remove this Delete lock?


Solution

  • After a bit of research and digging around, I found out that the direct answer to this question is that it's not possible to Start/Stop a Storage Event Trigger on a Data Factory when there is a Delete lock on the entire Resource Group. This is because whenever a Storage Event Trigger is started or stopped, an Event Subscription (which is a resource) is created and deleted in the Resource Group but with a Delete lock in place, this deletion cannot happen.

    However, there are few workarounds to address this requirement :

    1. Have a Delete lock at the Resource level and not at the Resource Group level.
    2. Move the Data Factory and the Storage Account to a different Resource Group which doesn't have a Delete lock.
    3. Delete the "Delete lock" before the deployment of the ADF and recreate it after the deployment. For this, the Service Principal being used to do the deployments should have the permission needed to update/delete locks.

    If anyone has a direct solution to this problem, I'm happy to accept that as the answer. Thanks.