An Azure IoT Hub Resource Manager Template

Posted on Saturday, December 12, 2015

For a recent project I needed to recreate an Azure IoT Hub automatically.
An Azure Resource Manager Template is perfect for this but I couldn't find any online.
So after some trial and error I figured out how the template should look like. Below is the result of that effort.

The Template

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "iotHubName": {
            "type": "string",
            "metadata": {
                "description": "The Iot Hub name."
            }
        },
        "skuName": {
            "type": "string",
            "defaultValue": "S1",
            "allowedValues": [
                "Free",
                "S1",
                "S2"
            ],
            "metadata": {
                "description": "The Sku."
            }
        },
        "skuCapacity": {
            "type": "int",
            "defaultValue": "1",
            "metadata": {
                "description": "The Sku capacity."
            }
        },
        "partitionCount": {
            "type": "int",
            "defaultValue": "1",
            "metadata": {
                "description": "The partition count."
            }
        }
    },
    "resources": [
        {
            "apiVersion": "2015-08-15-preview",
            "type": "Microsoft.Devices/IotHubs",
            "name": "[parameters('iotHubName')]",
            "location": "[resourceGroup().location]",
            "sku": {
                "name": "[parameters('skuName')]",
                "capacity": 1
            },
            "properties": {
                "eventHubEndpoints": {
                    "events": {
                        "retentionTimeInDays": 1,
                        "partitionCount": "[parameters('partitionCount')]"
                    }
                },
                "cloudToDevice": {
                    "maxDeliveryCount": 10,
                    "defaultTtlAsIso8601": "PT1H",
                    "feedback": {
                        "maxDeliveryCount": 10,
                        "ttlAsIso8601": "PT1H"
                    }
                }
            }
        }
    ]
}

The Parameters

{
    "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "iotHubName": {
            "value": "IoTHubName"
        },
        "skuName": {
            "value": "S1"
        },
        "skuCapacity": {
            "value": 1
        },
        "partitionCount": {
            "value": 32
        }
    }
}

Disclaimer: Any views or opinions expressed on this blog are my own personal ones and do not represent my employer in any way.