Skip to content

Instantly share code, notes, and snippets.

@liliankasem
Created April 3, 2021 16:34
Show Gist options
  • Select an option

  • Save liliankasem/3de8bd257a92ceffee468374c30d4e44 to your computer and use it in GitHub Desktop.

Select an option

Save liliankasem/3de8bd257a92ceffee468374c30d4e44 to your computer and use it in GitHub Desktop.
IoT Hub Conditional Routes
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string",
"metadata": {
"description": "The datacenter to use for the deployment."
}
},
"iotHubName": {
"type": "String"
},
"skuName": {
"type": "string",
"defaultValue": "S1",
"metadata": {
"description": "The SKU to use for the IoT Hub."
}
},
"skuUnits": {
"type": "string",
"defaultValue": "1",
"metadata": {
"description": "The number of IoT Hub units."
}
},
"environmentName": {
"type": "string"
},
"projectName": {
"type": "string"
},
"hubEndptRetentionTime": {
"type": "string",
"defaultValue": "1"
},
"hubEndptPartitionCount": {
"type": "string",
"defaultValue": "4"
},
"feature": {
"type": "string",
"defaultValue": "None"
}
},
"variables": {
"defaultTags": {
"iotHubExists": false
},
"updatedTags": {
"iotHubExists": true
},
"existingTags": "[if(contains(resourceGroup(), 'tags'), resourceGroup().tags, json('{}'))]",
"iotHubExists": "[bool(union(variables('defaultTags'), variables('existingTags'))['iotHubExists'])]"
},
"resources": [
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2019-10-01",
"name": "getIoTHubRoutes",
"tags": {
"Environment": "[parameters('environmentName')]",
"Project": "[parameters('projectName')]"
},
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
],
"outputs": {
"iotHubRoutes": {
"type": "array",
"value": "[if(variables('iotHubExists'), reference(resourceId('Microsoft.Devices/IotHubs', parameters('iotHubName')), '2020-03-01').routing.routes , json('[]'))]"
}
}
}
}
},
{
"dependsOn": [
"[resourceId('Microsoft.Resources/deployments', 'getIoTHubRoutes')]"
],
"type": "Microsoft.Resources/deployments",
"apiVersion": "2019-10-01",
"name": "iothub-deploy",
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "Microsoft.Devices/IotHubs",
"apiVersion": "2020-03-01",
"name": "[parameters('iotHubName')]",
"location": "[parameters('location')]",
"tags": {
"Environment": "[parameters('environmentName')]",
"Project": "[parameters('projectName')]"
},
"sku": {
"name": "[parameters('skuName')]",
"capacity": "[parameters('skuUnits')]"
},
"identity": {
"type": "None"
},
"properties": {
"eventHubEndpoints": {
"events": {
"retentionTimeInDays": "[parameters('hubEndptRetentionTime')]",
"partitionCount": "[parameters('hubEndptPartitionCount')]"
}
},
"routing": {
"routes": "[reference(resourceId('Microsoft.Resources/deployments', 'getIoTHubRoutes')).outputs.iotHubRoutes.value]",
"fallbackRoute": {
"name": "$fallback",
"source": "DeviceMessages",
"condition": "true",
"endpointNames": [
"events"
],
"isEnabled": true
}
},
"messagingEndpoints": {
"fileNotifications": {
"lockDurationAsIso8601": "PT1M",
"ttlAsIso8601": "PT1H",
"maxDeliveryCount": 10
}
},
"enableFileUploadNotifications": false,
"cloudToDevice": {
"maxDeliveryCount": 10,
"defaultTtlAsIso8601": "PT1H",
"feedback": {
"lockDurationAsIso8601": "PT1M",
"ttlAsIso8601": "PT1H",
"maxDeliveryCount": 10
}
},
"features": "[parameters('feature')]"
}
},
{
"dependsOn": [
"[resourceId('Microsoft.Devices/IotHubs', parameters('iotHubName'))]"
],
"type": "Microsoft.Resources/tags",
"apiVersion": "2019-10-01",
"name": "default",
"properties": {
"tags": "[union(variables('existingTags'), variables('updatedTags'))]"
}
}
]
}
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment