Azure automatically edit resource after deployment - azure

I am trying to create an automation with an event grid on a subscription so that whenever a resource is deployed it will send the event to a webhook that belongs to a runbook that adds a tag to the resource.
(resource deployed -> event grid -> runbooks webhook -> add tag)
However, when I add the tag it triggers a similar event which triggers the event grid again and a cycle begins. The event grid only allow write/action success type of event and there is no way of filtering only the creation events from the other event created by editing the resource.
I want to know if there's a workaround or maybe an alternative to using automation (I don't want to use a modify policy because I want to change other fields in the future not just change tags)
Thanks

You can use Azure Policy for that although you say you don't want. With a custom Azure Policy, you can modify the different properties of a resource.
Another advantage is that Azure Policy is free whereas you will pay for Automation Account.
On the other hand, for your current situation, I guess the Event Grid is triggered even when the resource is modified. So you need to modify that in order to avoid the loop.

Related

Automatically link newly created logic apps to an existing alert rule

I have created an Alert action group which will simply call a "error" logic app when the conditions are met. And I have set up an event grid which will be called whenever an logic app gets created for the first time.
Now the challenge is that I want to somehow automatically link this newly created logic app to the action group.
I have searched for way to do this but had no luck, anyone knows if this is possible?
One way of updating an action group would be by using the management API, see the docs.
However, you might want to think about this a bit differently.
How are you going to deploy everything?
Assuming you're not going to be doing this manually, you will be using ARM-/Bicep-files. So, you could include the configuration of an action group in these deployment files.
Meaning, when you initially deploy the Logic App, it will immediately be added to an action group, allowing it to trigger the required alerts. Next to that, it also allows you to create the event subscriptions in your Azure Event Grid topic.
This way you avoid missing the first alert because the action group wasn't updated before the first run of the Logic App.
The template to create an action group can be found here.
The template to create an event grid subscription can be found here.

Is it possible to detect an table/queue/fileShare creation with eventGrid?

In the MS documentation, at the resources of EventGrid Azure Blob Storage as event sources. There is nothing about table/queue/fileShare creations.
I saw also custom events in EventGrid, so i wondered if it is possible to use table/queue/fileShare creations as custom events. If yes, how?
Unfortunately, there is no direct way you can pass events like table/queue/fileshare creation to Event grid. Event grid supports mostly blob actions like what is listed HERE.
As a work around, you can look at is using alerts. Click on "Alerts" under the Monitoring tab on the left pane of your storage account. There are different types of actions available by which you can pass the administrative events to Azure functions, logic apps or webhooks. If you really need the events in Event grid, you can use logic apps/functions to pass those events/alerts to Event grid.
You may need to do some more filtering before doing this though to get exactly what you want. Else you may end up getting all the admin activities which I don't think you would need.
For example, what I setup below alerted me on creation and deletion of queues(among other things). I would also get alerts for List of storage keys and other admin activities.

How to getting event from Event grid on successfully deplying Azure template

Say I have a https end point that can serve as a webhook url for azure event grid that I can provide in the Azure template. But that endpoint has not been validated yet. I also have an azure template that I wish for a tenant/customer to deploy. What is the way for me to receive an event that deployment of the template has finished successfully?
You may leverage Azure Monitor's capability to view activity logs to monitor actions on resources. More specifically, you'll be interested in events from the Deployments resource (Microsoft.Resources/deployments).
From there you may create an alert rule + action group that will push the event to a webhook of your choice. You may also scope your alerting to a single resource group or a whole subscription. See Create an alert rule and Create and manage action groups in the Azure portal.

Trigger Azure logic app on resource creation

I'm working on an Azure Logic app that should trigger when a new resource is created.
However, if I trigger the app based on a webhook using monitor alerts or an event subscription, I run into the problem of each creation event will have 2 identical events with all the output being identical which means I can't filter it out and therefore triggers the logic app twice.
If there a different route around to just get the app to trigger once?
I believe the multiple events are because the event type for both create or update is the same as documented.
One way to workaround this would be to keep track of resourceIds touched by your Logic App, OR add a tag to your resource which signals that it has been touched. This way you wouldn't need an extra store for this metadata.

Is it possible to receive an event when a new resource is created

I would like to run some automation to take some actions whenever a new resource is created in One of my subscriptions in Azure. Is this possible?
You can use Azure Event grid for this, a solution that is built for exactly this purpose. Taken from https://learn.microsoft.com/en-us/azure/event-grid/overview
Azure Event Grid allows you to easily build applications with event-based architectures. You select the Azure resource you would like to subscribe to, and give the event handler or WebHook endpoint to send the event to. Event Grid has built-in support for events coming from Azure services, like storage blobs and resource groups.
You basically create a subscription to a certain event (such as specific resources being created) that can then be picked up by a webhook, or processed by Azure Automation or Azure Functions

Resources