diff --git a/eventgrid/.gitignore b/eventgrid/.gitignore new file mode 100644 index 0000000..c795b05 --- /dev/null +++ b/eventgrid/.gitignore @@ -0,0 +1 @@ +build \ No newline at end of file diff --git a/eventgrid/templates/eventgrid.bicep b/eventgrid/templates/eventgrid.bicep index 14f1378..033ec7f 100644 --- a/eventgrid/templates/eventgrid.bicep +++ b/eventgrid/templates/eventgrid.bicep @@ -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 = [ { @@ -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' diff --git a/eventgrid/templates/eventhubintegration.bicep b/eventgrid/templates/eventhubintegration.bicep new file mode 100644 index 0000000..668d278 --- /dev/null +++ b/eventgrid/templates/eventhubintegration.bicep @@ -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 + ] +} diff --git a/eventgrid/templates/eventhubs.bicep b/eventgrid/templates/eventhubs.bicep index bfc15c9..623c2fe 100644 --- a/eventgrid/templates/eventhubs.bicep +++ b/eventgrid/templates/eventhubs.bicep @@ -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 @@ -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 diff --git a/eventgrid/templates/future/eventhubintegration.bicep b/eventgrid/templates/future/eventhubintegration.bicep deleted file mode 100644 index 7dd0b53..0000000 --- a/eventgrid/templates/future/eventhubintegration.bicep +++ /dev/null @@ -1,73 +0,0 @@ - -resource namespaces_name_test_ehsub2 'Microsoft.EventGrid/namespaces/topics/eventSubscriptions@2023-12-15-preview' = { - name: '${namespaces_name}/test/ehsub2' - properties: { - deliveryConfiguration: { - deliveryMode: 'Push' - push: { - maxDeliveryCount: 10 - eventTimeToLive: 'P7D' - deliveryWithResourceIdentity: { - identity: { - type: 'SystemAssigned' - } - destination: { - properties: { - resourceId: evengridsink.id - deliveryAttributeMappings: [] - } - endpointType: 'EventHub' - } - } - } - } - eventDeliverySchema: 'CloudEventSchemaV1_0' - filtersConfiguration: { - includedEventTypes: [] - filters: [ - { - values: [ - 'data/' - ] - operatorType: 'StringBeginsWith' - key: 'subject' - } - ] - } - } - dependsOn: [ - namespaces_name_test - namespace_resource - ] -} - -resource namespaces_name_test_grafana 'Microsoft.EventGrid/namespaces/topics/eventSubscriptions@2023-12-15-preview' = { - name: '${namespaces_name}/test/grafana' - properties: { - deliveryConfiguration: { - deliveryMode: 'Queue' - queue: { - receiveLockDurationInSeconds: 60 - maxDeliveryCount: 10 - eventTimeToLive: 'P7D' - } - } - eventDeliverySchema: 'CloudEventSchemaV1_0' - filtersConfiguration: { - includedEventTypes: [] - filters: [ - { - values: [ - 'data/' - ] - operatorType: 'StringBeginsWith' - key: 'subject' - } - ] - } - } - dependsOn: [ - namespaces_name_test - namespace_resource - ] -} diff --git a/eventgrid/templates/template.bicep b/eventgrid/templates/template.bicep index 5549553..eb05ec0 100644 --- a/eventgrid/templates/template.bicep +++ b/eventgrid/templates/template.bicep @@ -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 } } @@ -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