I am trying to create multiple event hubs in a single namespace but I am not able to do so.
I have tried a single event hub which I am able to create.
When I am trying to create multiple event hubs passing all the event hub names in the variable and passing the same in the resource section is not able to create the consumer group
Here is the snippet for creating single event-hub
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.19.5.34762",
"templateHash": "1037450281519309886"
}
},
"parameters": {
"namespaceName": {
"type": "string",
"defaultValue": "arm-deployed-event-hub-namespace",
"metadata": {
"description": "Name of EventHub namespace"
}
},
"eventhubSku": {
"type": "string",
"defaultValue": "Standard",
"allowedValues": [
"Basic",
"Standard"
],
"metadata": {
"description": "The messaging tier for service Bus namespace"
}
},
"skuCapacity": {
"type": "int",
"defaultValue": 1,
"allowedValues": [
1,
2,
4
],
"metadata": {
"description": "MessagingUnits for premium namespace"
}
},
"eventHubName": {
"type": "string",
"defaultValue": "arm-deployed_4g_att_cu_om",
"metadata": {
"description": "Name of Event Hub"
}
},
"consumerGroupName": {
"type": "string",
"defaultValue": "arm-deployed-event-hub-consumer-group",
"metadata": {
"description": "Name of Consumer Group"
}
}
},
"variables": {
},
"resources": [
{
"type": "Microsoft.EventHub/namespaces",
"apiVersion": "2022-10-01-preview",
"name": "[parameters('namespaceName')]",
"location": "[parameters('location')]",
"sku": {
"name": "[parameters('eventhubSku')]",
"tier": "[parameters('eventhubSku')]",
"capacity": "[parameters('skuCapacity')]"
},
"tags": {
"tag1": "value1",
"tag2": "value2"
},
"properties": {}
},
{
"type": "Microsoft.EventHub/namespaces/eventhubs",
"apiVersion": "2022-10-01-preview",
"name": "[format('{0}/{1}', parameters('namespaceName'), parameters('eventHubName'))]",
"properties": {},
"dependsOn": [
"[resourceId('Microsoft.EventHub/namespaces', parameters('namespaceName'))]"
]
},
{
"type": "Microsoft.EventHub/namespaces/eventhubs/consumergroups",
"apiVersion": "2022-10-01-preview",
"name": "[format('{0}/{1}/{2}', parameters('namespaceName'), parameters('eventHubName'), parameters('consumerGroupName'))]",
"properties": {
"userMetadata": "User Metadata goes here"
},
"dependsOn": [
"[resourceId('Microsoft.EventHub/namespaces/eventhubs', parameters('namespaceName'), parameters('eventHubName'))]"
]
}
]}
The above code is working properly and I am able to create the resource.
Snippet for creating multiple event-hub in a single space.
``` {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {
"eventHubNames": [
"myeventhub1",
"myeventhub2"
// Add more names as needed
],
"namespaceName": "myeventhubnamespace"
},
"resources": [
{
"type": "Microsoft.EventHub/namespaces/eventhubs",
"apiVersion": "2021-06-01-preview",
"name": "[format('{0}/{1}', variables('namespaceName'), variables('eventHubNames')[copyIndex()])]",
"copy": {
"name": "eventHubLoop",
"count": "[length(variables('eventHubNames'))]"
},
"location": "[resourceGroup().location]",
"properties": {
"messageRetentionInDays": 1,
"partitionCount": 4
}
}
],
"outputs": {
"eventHubNames": {
"type": "array",
"value": "[variables('eventHubNames')]"
}
}
}
I have tried different approaches as well but I am getting stuck at the consumer group resource block and without the consumer block I am not able to create the resource.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.15.31.15270",
"templateHash": "12923377345559355625"
}
},
"parameters": {
"namespaceName": {
"type": "string",
"defaultValue": "chronos-event-hub-namespace",
"metadata": {
"description": "Name of EventHub namespace"
}
},
"eventhubSku": {
"type": "string",
"defaultValue": "Standard",
"allowedValues": [
"Basic",
"Standard"
],
"metadata": {
"description": "The messaging tier for service Bus namespace"
}
},
"skuCapacity": {
"type": "int",
"defaultValue": 1,
"allowedValues": [
1,
2,
4
],
"metadata": {
"description": "MessagingUnits for premium namespace"
}
},
// "eventHubName": {
// "type": "string",
// "defaultValue": "chronos_4g_event_hub_name",
// "metadata": {
// "description": "Name of Event Hub"
// }
// },
"consumerGroupName": {
"type": "string",
"defaultValue": "chronos-event-hub-consumer-group",
"metadata": {
"description": "Name of Consumer Group"
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for all resources."
}
}
},
"variables": {
"namespaceName": "chronos-event-hub-namespace",
"eventHubs": [
{
"name": "myeventhub1",
"consumerGroups": [
"group1",
"group2"
]
},
{
"name": "myeventhub2",
"consumerGroups": [
"group3",
"group4"
]
}
// Add more Event Hubs with consumer groups as needed
]
},
"resources": [
{
"type": "Microsoft.EventHub/namespaces",
"apiVersion": "2017-04-01",
"name": "[variables('eventHubNamespaceName')]",
"location": "[resourceGroup().location]",
"sku": {
"name": "Standard",
"tier": "Standard"
}
},
{
"type": "Microsoft.EventHub/namespaces/eventhubs",
"apiVersion": "2018-01-01-preview",
"name": "[format('{0}/{1}', variables('eventHubNamespaceName'), variables('eventHubs')[copyIndex()].name)]",
"copy": {
"name": "eventHubLoop",
"count": "[length(variables('eventHubs'))]"
},
"dependsOn": [
"[resourceId('Microsoft.EventHub/namespaces', variables('eventHubNamespaceName'))]"
],
"properties": {
"messageRetentionInDays": 1,
"partitionCount": 4
}
},
{
"type": "Microsoft.EventHub/namespaces/eventhubs/consumergroups",
"apiVersion": "2017-04-01",
"name": "[format('{0}/{1}/{2}', variables('eventHubNamespaceName'), variables('eventHubs')[copyIndex()].name, variables('eventHubs')[copyIndex()].consumerGroups[innerCopyIndex()])]",
"copy": {
"name": "consumerGroupLoop",
"count": "[length(variables('eventHubs')[copyIndex()].consumerGroups)]",
"mode": "inner"
},
"dependsOn": [
"[resourceId('Microsoft.EventHub/namespaces/eventhubs', variables('eventHubNamespaceName'), variables('eventHubs')[copyIndex()].name)]"
]
}
],
"outputs": {
"eventHubName": {
"type": "array",
"value": "[variables('eventHubs')]"
}
}
}
I am not sure how to define the consumer group resource section so that I can create multiple event-hub in a single namespace.