Introduction
While working in Azure Data Factory a user can delete a resource unknowingly. We can implement Azure Locks to prevent this accidental resource deletion. You can create your own custom roles to give users read-only access to the Azure Data Factory, but developers or administrators have full access and they might delete resources accidentally in a production environment. If you are using any code version control then it will be easier to revert back any changes but otherwise, locks are very helpful to create restrictions in such scenarios.
There are two types of lock levels available CanNotDelete and ReadOnly.
- CanNotDelete - Authorized users are able to read and modify resources, but they can not delete the resource. In the portal, this lock is called Delete.
ReadOnly - Authorized users can read a resource but they can not delete or modify the resource. In the portal, this lock is called Read-only.
- Access required
You need below access to create or manage locks:
- must be owner or User Access Administrator built-in roles.
- must have access to Microsoft.Authorization/* or Microsoft.Authorization/locks/*.
Create a New Lock
You can view the lock option available in the settings option in the Azure Data Factory. Look for the Locks entry in the menu (shown here):
To create a new lock click on the Add option :
We need to provide the below information to create a new lock:
- Lock name: Provide a lock name.
- Lock type: choose between available two options Read-only and Delete.
- Notes: (Optional) You can add comments about this lock.
I provided the information below to create the new lock:
- Lock name: lock-del-test
- Lock type: Delete.
- Notes: Testing delete lock.
Once the lock is created, it is available in the Lock section. You can edit or delete the existing lock here (see the right side of the image):
Now let's go to the Azure Data Factory author page. I will try to delete a demo pipeline, Pl_Test, in the data factory:
Click on the actions options available in the pipeline name and click on the delete option:
In the next screen, you need to confirm the delete action:
Now the pipeline is deleted and we need to publish to make the changes to the live environment:
After clicking the button, we get a publishing error because the data factory contains a lock, so we must remove the lock or undo the delete action :
Conclusion
In this article, we learned about how to use locks in the Azure data factory to prevent accidental resource deletion.