Skip to content

Commit 6608633

Browse files
committed
add event grid mqtt resource
1 parent 6d18cc2 commit 6608633

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed

infra/main.bicep

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ param storageAccountName string = '${prefix}sa'
2929
@description('Specifies the name of the Azure Event Grid resource.')
3030
param eventGridName string = '${prefix}eg'
3131

32+
@description('Specifies the name of the Azure Event Grid MQTT resource.')
33+
param eventGridMqttName string = '${prefix}egmqtt'
34+
35+
@description('Specifies the name of the encoded certificate.')
36+
param eventGridMqttEncodedCertificate string
37+
3238
@description('Specifies the name of the Azure Cosmos DB resource.')
3339
param cosmosDbName string = '${prefix}cosmosdb'
3440

@@ -87,6 +93,16 @@ module eventGrid './modules/eventGrid.bicep' = {
8793
}
8894
}
8995

96+
module eventGridMqtt './modules/eventGridMqtt.bicep' = {
97+
name: 'eventGridMqtt'
98+
params: {
99+
name: eventGridMqttName
100+
location: location
101+
tags: tags
102+
encodedCertificate: eventGridMqttEncodedCertificate
103+
}
104+
}
105+
90106
module cosmosDb './modules/cosmosDb.bicep' = {
91107
name: 'cosmosDb'
92108
params: {

infra/main.parameters.bicepparam

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ param openAiDeployments = [
1818
}
1919
]
2020

21+
// To create certificate, overwrite the default value of the parameter by the output from the following command:
22+
// $ cat ~/.step/certs/intermediate_ca.crt | tr -d "\n"
23+
// ref. https://github.com/ks6088ts-labs/azure-iot-scenarios/tree/main/scenarios/3_event-grid-mqtt-messaging
24+
param eventGridMqttEncodedCertificate = ''
25+
2126
param tags = {
2227
environment: 'dev'
2328
}

infra/modules/eventGridMqtt.bicep

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// Parameters
2+
@description('Specifies the name prefix.')
3+
param prefix string = uniqueString(resourceGroup().id)
4+
5+
@description('Specifies the primary location of Azure resources.')
6+
param location string = resourceGroup().location
7+
8+
@description('Specifies the resource tags.')
9+
param tags object = {}
10+
11+
@description('Specifies the name of the Event Grid Namespace.')
12+
param name string = '${prefix}egn'
13+
14+
@description('Specifies the name of the Event Grid Namespace Topic Space.')
15+
param eventGridNamesapceTopicSpaceName string = 'samples'
16+
17+
@description('Specifies the name of the encoded certificate.')
18+
param encodedCertificate string
19+
20+
resource eventGridNamesapce 'Microsoft.EventGrid/namespaces@2024-06-01-preview' = {
21+
name: name
22+
location: location
23+
tags: tags
24+
sku: {
25+
name: 'Standard'
26+
capacity: 1
27+
}
28+
identity: {
29+
type: 'SystemAssigned'
30+
}
31+
properties: {
32+
isZoneRedundant: true
33+
topicsConfiguration: {}
34+
topicSpacesConfiguration: {
35+
state: 'Enabled'
36+
}
37+
}
38+
}
39+
40+
resource eventGridCaCertificate 'Microsoft.EventGrid/namespaces/caCertificates@2024-06-01-preview' = if (encodedCertificate != '') {
41+
parent: eventGridNamesapce
42+
name: 'Intermediate01'
43+
properties: {
44+
encodedCertificate: encodedCertificate
45+
}
46+
}
47+
48+
resource eventGridClient 'Microsoft.EventGrid/namespaces/clients@2024-06-01-preview' = {
49+
parent: eventGridNamesapce
50+
name: 'sample_client'
51+
properties: {
52+
authenticationName: 'sample_client'
53+
state: 'Enabled'
54+
clientCertificateAuthentication: {
55+
validationScheme: 'SubjectMatchesAuthenticationName'
56+
}
57+
attributes: {
58+
room: '345'
59+
floor: 12
60+
deviceTypes: [
61+
'Fan'
62+
'Light'
63+
]
64+
}
65+
description: 'This is a sample client'
66+
}
67+
}
68+
69+
resource eventGridNamesapceTopicSpace 'Microsoft.EventGrid/namespaces/topicSpaces@2024-06-01-preview' = {
70+
parent: eventGridNamesapce
71+
name: eventGridNamesapceTopicSpaceName
72+
properties: {
73+
description: 'This is a sample topic-space for Event Grid namespace'
74+
topicTemplates: [
75+
'sample/#'
76+
]
77+
}
78+
}
79+
80+
resource permissionBindingForPublisher 'Microsoft.EventGrid/namespaces/permissionBindings@2024-06-01-preview' = {
81+
name: 'samplesPub'
82+
parent: eventGridNamesapce
83+
properties: {
84+
clientGroupName: '$all'
85+
description: 'A publisher permission binding for the namespace'
86+
permission: 'Publisher'
87+
topicSpaceName: eventGridNamesapceTopicSpace.name
88+
}
89+
}
90+
91+
resource permissionBindingForSubscriber 'Microsoft.EventGrid/namespaces/permissionBindings@2024-06-01-preview' = {
92+
name: 'samplesSub'
93+
parent: eventGridNamesapce
94+
properties: {
95+
clientGroupName: '$all'
96+
description: 'A subscriber permission binding for the namespace'
97+
permission: 'Subscriber'
98+
topicSpaceName: eventGridNamesapceTopicSpace.name
99+
}
100+
}

0 commit comments

Comments
 (0)