Skip to content

Commit 7ab5fab

Browse files
authored
Merge pull request #122 from ks6088ts-labs/feature/issue-121_eventgrid-mqtt
add eventgrid mqtt
2 parents dbd3368 + 6608633 commit 7ab5fab

File tree

4 files changed

+140
-17
lines changed

4 files changed

+140
-17
lines changed

infra/main.bicep

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ param openAiDeployments array = []
1818
param openAiLocation string = 'eastus2'
1919

2020
@description('Specifies the name of the Azure Cognitive Services resource.')
21-
param cognitiveServicesName string = '${prefix}cognitiveServices'
21+
param cognitiveServicesName string = '${prefix}aiServices'
2222

2323
@description('Specifies the location of the Azure Cognitive Services resource.')
2424
param cognitiveServicesLocation string = 'eastus'
@@ -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+
}

infra/modules/openAi.bicep

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,26 @@ resource openAi 'Microsoft.CognitiveServices/accounts@2023-10-01-preview' = {
4646
}
4747

4848
@batchSize(1)
49-
resource model 'Microsoft.CognitiveServices/accounts/deployments@2023-10-01-preview' = [for deployment in deployments: {
50-
name: deployment.name
51-
parent: openAi
52-
properties: {
53-
model: {
54-
format: 'OpenAI'
55-
name: deployment.name
56-
version: deployment.version
49+
resource model 'Microsoft.CognitiveServices/accounts/deployments@2023-10-01-preview' = [
50+
for deployment in deployments: {
51+
name: deployment.name
52+
parent: openAi
53+
properties: {
54+
model: {
55+
format: 'OpenAI'
56+
name: deployment.name
57+
version: deployment.version
58+
}
59+
currentCapacity: deployment.capacity
60+
raiPolicyName: deployment.?raiPolicyName ?? null
61+
versionUpgradeOption: deployment.?versionUpgradeOption ?? 'OnceNewDefaultVersionAvailable'
62+
}
63+
sku: deployment.?sku ?? {
64+
name: 'Standard'
65+
capacity: deployment.capacity
5766
}
58-
currentCapacity: deployment.capacity
59-
raiPolicyName: contains(deployment, 'raiPolicyName') ? deployment.raiPolicyName : null
60-
versionUpgradeOption: contains(deployment, 'versionUpgradeOption') ? deployment.versionUpgradeOption : 'OnceNewDefaultVersionAvailable'
61-
}
62-
sku: contains(deployment, 'sku') ? deployment.sku : {
63-
name: 'Standard'
64-
capacity: deployment.capacity
6567
}
66-
}]
68+
]
6769

6870
// Outputs
6971
output id string = openAi.id

0 commit comments

Comments
 (0)