Skip to content

Commit

Permalink
add event hubs integration
Browse files Browse the repository at this point in the history
  • Loading branch information
jmservera committed Apr 17, 2024
1 parent 82484d0 commit 4d7a748
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 95 deletions.
1 change: 1 addition & 0 deletions eventgrid/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
3 changes: 2 additions & 1 deletion eventgrid/templates/eventgrid.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
param location string = resourceGroup().location
@description('The name of the Event Grid namespace.')
param namespaces_name string = 'jmeventgrid'
param custom_topic_name string ='test'
@description('An array containing the clients that will be allowed to interact with the Event Grid namespace. Each client must have a name, a thumbprint, and a role. The role can be either "service" or "device".')
param clients array = [
{
Expand Down Expand Up @@ -110,7 +111,7 @@ resource namespace_devicessubscribe 'Microsoft.EventGrid/namespaces/permissionBi

resource namespace_test 'Microsoft.EventGrid/namespaces/topics@2023-12-15-preview' = {
parent: namespace_resource
name: 'test'
name: custom_topic_name
properties: {
publisherType: 'Custom'
inputSchema: 'CloudEventSchemaV1_0'
Expand Down
79 changes: 79 additions & 0 deletions eventgrid/templates/eventhubintegration.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
param eventhub_namespace_name string
param topic_name string
param eventhub_name string
@description('The name of the Event Grid namespace.')
param eventgrid_name string

resource eventhub 'Microsoft.EventHub/namespaces/eventhubs@2023-01-01-preview' existing = {
name: '${eventhub_namespace_name}/${eventhub_name}'
}

resource eventgrid_namespace 'Microsoft.EventGrid/namespaces@2023-12-15-preview' existing = {
name: eventgrid_name
}

resource eventgrid_topic 'Microsoft.EventGrid/namespaces/topics@2023-12-15-preview' existing = {
parent: eventgrid_namespace
name: topic_name
}

@description('This is the built-in Azure Event Hubs Data Sender. See https://docs.microsoft.com/azure/role-based-access-control/built-in-roles#contributor')
resource eventHubsDataSenderRoleDefinition 'Microsoft.Authorization/roleDefinitions@2018-01-01-preview' existing = {
scope: eventhub
name: '2b629674-e913-4c01-ae53-ef4638d8f975'
}

// Event Grid needs permissions to send messages to the Event Hub, so we use a role assignment
// to grant the Event Grid namespace the built-in Azure Event Hubs Data Sender role.
resource roleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
name: guid('roleAssignment')
scope: eventhub
properties: {
principalId: eventgrid_namespace.identity.principalId
roleDefinitionId: eventHubsDataSenderRoleDefinition.id
}
}


resource eventHubEventSubscription 'Microsoft.EventGrid/namespaces/topics/eventSubscriptions@2023-12-15-preview' = {
parent: eventgrid_topic
name: 'ehsub2'
properties: {
deliveryConfiguration: {
deliveryMode: 'Push'
push: {
maxDeliveryCount: 10
eventTimeToLive: 'P7D'
deliveryWithResourceIdentity: {
identity: {
type: 'SystemAssigned'
}
destination: {
properties: {
resourceId: eventhub.id
deliveryAttributeMappings: []
}
endpointType: 'EventHub'
}
}
}
}
eventDeliverySchema: 'CloudEventSchemaV1_0'
filtersConfiguration: {
includedEventTypes: []
filters: [
{
values: [
'data/'
]
operatorType: 'StringBeginsWith'
key: 'subject'
}
]
}
}
dependsOn: [
eventhub
roleAssignment
]
}
20 changes: 1 addition & 19 deletions eventgrid/templates/eventhubs.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ resource eventhub_namespace 'Microsoft.EventHub/namespaces@2023-01-01-preview' =
}
}



resource eventhubs_eventgridsink 'Microsoft.EventHub/namespaces/eventhubs@2023-01-01-preview' = {
parent: eventhub_namespace
name: eventhub_name
Expand All @@ -38,20 +36,4 @@ resource eventhubs_eventgridsink 'Microsoft.EventHub/namespaces/eventhubs@2023-0
}
}

// resource namespaces_jmevgrid_name_default 'Microsoft.EventHub/namespaces/networkrulesets@2023-01-01-preview' = {
// parent: namespaces_jmevgrid_name_resource
// name: 'default'
// properties: {
// publicNetworkAccess: 'Enabled'
// defaultAction: 'Allow'
// virtualNetworkRules: []
// ipRules: []
// trustedServiceAccessEnabled: false
// }
// }

// resource namespaces_jmevgrid_name_evengridsink_Default 'Microsoft.EventHub/namespaces/eventhubs/consumergroups@2023-01-01-preview' = {
// parent: namespaces_jmevgrid_name_evengridsink
// name: '$Default'
// properties: {}
// }
output eventhub object= eventhub_namespace
73 changes: 0 additions & 73 deletions eventgrid/templates/future/eventhubintegration.bicep

This file was deleted.

15 changes: 13 additions & 2 deletions eventgrid/templates/template.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ param clients array = [
role: 'service or device'
}
]
param topic_name string = 'test'

module eventgrid 'eventgrid.bicep' = {
name: 'clients'
name: 'eventgrid'
params: {
location: location
namespaces_name: name_base
clients: clients
custom_topic_name: topic_name
}
}

Expand All @@ -29,5 +31,14 @@ module eventhub 'eventhubs.bicep' = {
}
}

output namespace_mqtt_hostname string = eventgrid.outputs.namespace_mqtt_hostname
module eventhubintegration 'eventhubintegration.bicep' = {
name: 'eventhubintegration'
params: {
eventgrid_name: name_base
eventhub_namespace_name: name_base
eventhub_name: '${name_base}sink'
topic_name: topic_name
}
}

output namespace_mqtt_hostname string = eventgrid.outputs.namespace_mqtt_hostname

0 comments on commit 4d7a748

Please sign in to comment.