The Event Grid is a simple but powerful builder that links events from Azure services such as Storage and App Service to one or many subscribers which can consume the events. The event grid builder supports a degree of type safety - all system events are provided from a strongly-typed list, and events are directly linked to specific builders - so, for example, you cannot accidentally subscribe to Storage Account events if the event publisher is a Web App. It supports the following ARM resources.
Microsoft.EventGrid/systemTopics)Microsoft.EventGrid/systemTopics/eventSubscriptions)| Keyword | Purpose |
|---|---|
| topic_name | The name of the topic that will be created. |
| source | Optional, defaults to the current resource group. The source of the events. See below for the full list of builder configurations that are supported. |
| event_delivery_schema | Optional. Sets the event delivery schema for all subscriptions on this topic. Valid values: EventGridSchema (default), CloudEventSchemaV1_0, CustomInputSchema. |
| add_queue_subscriber | Adds a new storage queue subscriber. Requires the storage account config that will receive the events, the queue name and the list of events to subscribe to. |
| add_webhook_subscriber | Adds a new webhook (HTTP) subscriber. Requires the web app config that will receive the event, associated URI local path and the list of events to subscribe to. Also contains an overload that takes in a Web App name and the full Uri of the webhook. |
| add_eventhub_subscriber | Adds a new event hub subscriber. Requires the event hub builder config that will receive the events and the list of events to subscribe to. |
| add_function_subscriber | Adds a new Azure Functions subscriber. Requires the function app, the handler name and the list of events to subscribe to. |
| add_monitor_alert_subscriber | Adds a new Azure Monitor Alert subscriber. Requires a list of action groups (either ActionGroupConfig list or ResourceId list), a severity level (Sev0–Sev4), and the list of events to subscribe to. |
Farmer supports the following Event Grid sources using Farmer builders:
| Builder | Events namespace | |
|---|---|---|
| StorageAccount | SystemEvents.Storage | |
| WebApp | SystemEvents.AppServer | |
| KeyVault | SystemEvents.KeyVault | |
| SignalR | SystemEvents.SignalR | |
| Maps | SystemEvents.Maps | |
| ContainerRegistry | SystemEvents.ContainerRegistry | |
| ServiceBus | SystemEvents.ServiceBus | |
| IotHub | SystemEvents.IotHub | |
| EventHub | SystemEvents.EventHub |
add_eventhub_subscriber)add_queue_subscriber)add_webhook_subscriber)add_servicebus_queue_subscriber)add_servicebus_topic_subscriber)add_monitor_alert_subscriber)The following sample routes Key Vault secret expiry events to Azure Monitor Alerts using the CloudEvent schema:
open Farmer
open Farmer.Builders
open Farmer.Arm.EventGrid
let myKeyVault = keyVault { name "mykeyvault" }
// Reference an existing action group by resource ID
let actionGroupId =
Arm.ActionGroups.actionGroups.resourceId (ResourceName "myActionGroup")
let kvExpiryGrid = eventGrid {
topic_name "kv-expiry-topic"
source myKeyVault
event_delivery_schema CloudEventSchemaV1_0
add_monitor_alert_subscriber
[ actionGroupId ]
Sev3
[ SystemEvents.KeyVault.SecretNearExpiry
SystemEvents.KeyVault.SecretExpired ]
}
Alternatively, reference a Farmer-managed action group directly:
let alertGroup = actionGroup {
name "myActionGroup"
short_name "myAG"
}
let kvExpiryGrid = eventGrid {
topic_name "kv-expiry-topic"
source myKeyVault
event_delivery_schema CloudEventSchemaV1_0
add_monitor_alert_subscriber [ alertGroup ] Sev3 [ SystemEvents.KeyVault.SecretNearExpiry ]
}
The following sample creates a source storage account that emits events on the event grid topic, whilst two destinations are created: an event hub and a storage queue, each listening for different events.
open Farmer
open Farmer.Builders
let queueName = "events"
let storageSource = storageAccount { name "isaacstorageacc"; add_private_container "data" }
let destionationHub = eventHub { name "isaachub"; namespace_name "isaacns" }
let destinationStorage = storageAccount { name "destinationstorage"; add_queue queueName; add_private_container "events" }
let eventHubGrid = eventGrid {
topic_name "isaacHubTopic"
source storageSource
add_eventhub_subscriber destionationHub [ SystemEvents.Storage.BlobCreated; SystemEvents.Storage.BlobDeleted ]
add_queue_subscriber destinationStorage queueName [ SystemEvents.Storage.BlobCreated ]
}
let template =
arm {
add_resources [
storageSource
eventHubGrid
destinationStorage
destionationHub
]
}