I am trying to fetch the Event hub compatible connection string in ARM template and then pass it on to my HDInsight Cluster for further processing.
I am trying to create the event hub connectiong string of my choice, But the event hub name generated is not the same and consists of a guid whose source I am unable to track.
I need the to list and pass the event hub connection string to HDInsight script action within the template.
The endpoint part in the iothub resource is where I customize the event hub compatible connection string.
"resources": [
{
"type": "Microsoft.Devices/IotHubs",
"sku": {
"name": "S1",
"tier": "Standard",
"capacity": 1
},
"name": "[variables('IotHub')]",
"apiVersion": "2016-02-03",
"location": "southeastasia",
"tags": {},
"properties": {
"ipFilterRules": [],
"eventHubEndpoints": {
"events": {
"retentionTimeInDays": 4,
"partitionCount": 4,
"partitionIds": [
"0",
"1",
"2",
"3"
],
"path": "[variables('IotHub')]",
"endpoint": "[concat('sb://', variables('IotHub'),'.servicebus.windows.net/')]"
}
},
"storageEndpoints": {
"$default": {
"sasTtlAsIso8601": "PT1H",
"connectionString": "",
"containerName": ""
}
},
"enableFileUploadNotifications": false,
"cloudToDevice": {
"maxDeliveryCount": 10,
"defaultTtlAsIso8601": "PT1H",
"feedback": {
"lockDurationAsIso8601": "PT1M",
"ttlAsIso8601": "PT1H",
"maxDeliveryCount": 10
}
},
"operationsMonitoringProperties": {
"events": {
"None": "None",
"Connections": "None",
"DeviceTelemetry": "None",
"C2DCommands": "None",
"DeviceIdentityOperations": "None",
"FileUploadOperations": "None"
}
},
"features": "None"
},
"resources": [],
"dependsOn": []
}
],
You can't set the values for the Event Hub-compatible name or Event Hub-compatible endpoint for an IoT Hub, these values are generated when the hub is created. However, you can access these values in an ARM template. The following snippet from the "outputs" section of a template that creates an IoT hub illustrates the syntax to use:
"outputs": {
"eventHubCompatibleEndpoint": {
"type": "string",
"value": "[reference(resourceId('Microsoft.Devices/IoTHubs',parameters('hubName'))).eventHubEndpoints.events.endpoint]"
},
"eventHubCompatibleName": {
"type": "string",
"value": "[reference(resourceId('Microsoft.Devices/IoTHubs',parameters('hubName'))).eventHubEndpoints.events.path]"
}
}
Related
I want to use the arm template to create the Event Subscription for the Event Grid Domain Topic. It's ok when I create Event Grid Domain and Event Grid Domain Topic but when I try to create the Event Subscription to listen to messages from Event Grid Domain Topic. It always fails. I think I defined the wrong "scrope" or "dependsOn".
Actually, I can't find the document or tutorial to create the Event Subscription for Event Grid Domain Topic. Almost document guide the way to create the Event Subscription for Event Grid Topic.
Thanks for support
This is my arm template
{
"type": "Microsoft.EventGrid/eventSubscriptions",
"apiVersion": "2021-06-01-preview",
"name": "[parameters('eventSubscription')]",
"scope": "[format('Microsoft.EventGrid/domains/topics/{0}', concat(variables('eventGridDomainName'), '/',parameters('topic')))]",
"properties": {
"deadletterdestination": {
"endpointType": "StorageBlob",
"properties": {
"blobContainerName": "parameters('containerName')",
"resourceId": "/subscriptions/{subscriptions}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{containerName}"
}
},
"destination": {
"endpointType": "WebHook",
"properties": {
"endpointUrl": "string"
}
},
"eventDeliverySchema": "EventGridSchema",
"filter": {
"advancedFilters": [],
"enableAdvancedFilteringOnArrays": true
},
"labels": []
},
"dependsOn": [
"[resourceId('Microsoft.EventGrid/domains/topics',variables('eventGridDomainName'),parameters('topic')]"
]
}
I had to modify the scope a bit to get it working, take a look at the snippet below.
"scope": "[concat('Microsoft.EventGrid/domains', '/', parameters('domains_azdomaineg_name'), '/', 'topics', '/', parameters('topicName'))]"
/
{
"type": "Microsoft.EventGrid/eventSubscriptions",
"apiVersion": "2020-06-01",
"name": "[concat(parameters('domains_azdomaineg_name'), 'topic-dommain-subscription')]",
"dependsOn": [
"[resourceId('Microsoft.EventGrid/domains', parameters('domains_azdomaineg_name'))]",
"[resourceId('Microsoft.EventHub/namespaces/eventHubs', parameters('eventHubNamespace'), parameters('eventHubName'))]"
],
"properties": {
"destination": {
"endpointType": "EventHub",
"properties": {
"resourceId": "[resourceId('Microsoft.EventHub/namespaces/eventhubs', parameters('eventHubNamespace'), parameters('eventHubName'))]"
}
},
"filter": {
"includedEventTypes": [
"first, last"
],
"advancedFilters": [
{
"key": "dataversion",
"operatorType": "StringIn",
"values": [
"test"
]
}
]
}
},
"scope": "[concat('Microsoft.EventGrid/domains', '/', parameters('domains_azdomaineg_name'), '/', 'topics', '/', parameters('topicName'))]"
}
]
}
I'm looking for a way to create access policy in Azure IoT hub but I'd like to supply my own keys.
I can see there is a command in Azure CLI:
az iot hub policy create --hub-name
--name
--permissions
[--resource-group]
[--subscription]
but it does not allow to provide my own keys.
I couldn't find anything interesting on PowerShell as well - seems like there is no command for creating shared access policy at all using PowerShell.
There is a way to use ARM template (seems like it is possible to provide primary and secondary key (https://learn.microsoft.com/en-us/azure/templates/microsoft.devices/iothubs?tabs=json#iothubproperties):
...
"properties": {
"allowedFqdnList": [ "string" ],
"authorizationPolicies": [
{
"keyName": "string",
"primaryKey": "string",
"rights": "string",
"secondaryKey": "string"
}
],
...
but it brings some hassle in terms how to provide the keys and I'm looking for something simple and preety much one-timer.
You can use the below sample arm template which create a basic iot hub & a shared access policy with our own keys. You need to create two files parameters.json & template.json.
template.json file contains the code which resources are going to deploy.
parameters.json file contains the value of those parameters that you have used in the template.json.
Template.json file:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"IotHubs_IotHub_connectionString": {
"type": "SecureString"
},
"IotHubs_IotHub_containerName": {
"type": "SecureString"
},
"IotHubs_IotHub_name": {
"defaultValue": "vedodIotHub",
"type": "String"
},
"IotHubs_Key_Name" : {
"defaultValue" : "newkeyname",
"type": "string"
},
"IotHubs_Key_Primary_value" : {
"type": "string"
},
"IotHubs_Key_Secondary_value":{
"type": "string"
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.Devices/IotHubs",
"apiVersion": "2021-07-02",
"name": "[parameters('IotHubs_IotHub_name')]",
"location": "eastus",
"sku": {
"name": "S1",
"tier": "Standard",
"capacity": 2
},
"identity": {
"type": "None"
},
"properties": {
"ipFilterRules": [],
"authorizationPolicies": [
{
"keyName": "[parameters('IotHubs_Key_Name')]",
"primaryKey": "[parameters('IotHubs_Key_Primary_value')]",
"secondaryKey" : "[parameters('IotHubs_Key_Secondary_value')]",
"rights": "RegistryRead, RegistryWrite, DeviceConnect"
}
],
"eventHubEndpoints": {
"events": {
"retentionTimeInDays": 1,
"partitionCount": 4
}
},
"routing": {
"endpoints": {
"serviceBusQueues": [],
"serviceBusTopics": [],
"eventHubs": [],
"storageContainers": []
},
"routes": [],
"fallbackRoute": {
"name": "$fallback",
"source": "DeviceMessages",
"condition": "true",
"endpointNames": [
"events"
],
"isEnabled": true
}
},
"storageEndpoints": {
"$default": {
"sasTtlAsIso8601": "PT1H",
"connectionString": "[parameters('IotHubs_IotHub_connectionString')]",
"containerName": "[parameters('IotHubs_IotHub_containerName')]"
}
},
"messagingEndpoints": {
"fileNotifications": {
"lockDurationAsIso8601": "PT1M",
"ttlAsIso8601": "PT1H",
"maxDeliveryCount": 10
}
},
"enableFileUploadNotifications": false,
"cloudToDevice": {
"maxDeliveryCount": 10,
"defaultTtlAsIso8601": "PT1H",
"feedback": {
"lockDurationAsIso8601": "PT1M",
"ttlAsIso8601": "PT1H",
"maxDeliveryCount": 10
}
},
"features": "None"
}
}
]
}
parameters.json file :
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"IotHubs_IotHub_connectionString": {
"value": ""
},
"IotHubs_IotHub_containerName": {
"value": ""
},
"IotHubs_IotHub_name": {
"value": "<IotHubName>"
},
"IotHubs_Key_Name":{
"value" : "<sharedaccesspolicyKeyName>"
},
"IotHubs_Key_Primary_value": {
"value" : "<accesspolicyPrimaryKeyValue>"
},
"IotHubs_Key_Secondary_value":{
"value" : "<accesspolicySecondaryKeyValue>"
}
}
}
Using the below Powershell cmdlets to deploy the create a Iot hub & passing the above template.json & parameters.json file as parameters :
New-AzResourceGroupDeployment -ResourceGroupName <resourcegroupName> -TemplateFile '<pathfortemplate.jsonfile>' -TemplateParameterFile '<Pathforparameters.jsonfile>'
Here is the sample output screenshot for reference:
I'm deploying an application gateway with ARM Template and wants to loop through the creation of listeners.
This is how far I got:
"copy": [
{
"name": "httpListeners",
"count": "[length(parameters('APPLICATIONS'))]",
"input": {
"name": "[concat(parameters('APPLICATIONS')[copyIndex('httpListeners')].site,'-',parameters('APPLICATIONS')[copyIndex('httpListeners')].protocol,'listener')]",
"properties": {
"FrontendIPConfiguration": {
"Id": "[concat(variables('applicationGatewayID'), '/frontendIPConfigurations/', variables('frontendIpConfigName'))]"
},
"FrontendPort": {
"Id": "[concat(variables('applicationGatewayID'), '/frontendPorts/', variables('frontendPortName443'))]"
},
"Protocol": "[parameters('APPLICATIONS')[copyIndex('httpListeners')].protocol]",
"SslCertificate": {
"Id": "[parameters('APPLICATIONS')[copyIndex('httpListeners')].cert]"
},
"HostName": "[parameters('APPLICATIONS')[copyIndex('httpListeners')].site]",
"RequireServerNameIndication": "[if(equals(parameters('APPLICATIONS')[copyIndex('httpListeners')].protocol, 'HTTPS'), json('true'), json('false'))]"
}
}
}
]
It works well as long as I only create HTTPS listeners, but when I create a HTTP listener I want to get rid of this part:
"SslCertificate": {
"Id": "[parameters('APPLICATIONS')[copyIndex('httpListeners')].cert]"
}
Just setting the parameter parameters('APPLICATIONS')[copyIndex('httpListeners')].cert to null doesn't help.
Any suggestions?
I am able to create the "message route" in azure portal and able to route messages to servicebusqueue if the query matching, I want to create the message route using the restapi instead of using azure portal, I have seen many documents but unable to find the proper one. Whether creating the message route using restapi is possible or not? if yes,How can I achieve this and please provide the respective links to refer?
I haven't tried this through REST API, but as Roman suggested,
You can check the IotHubResource_CreateOrUpdate which will help you understand how to Create or update the metadata of an Iot hub. The usual pattern to modify a property is to retrieve the IoT hub metadata and security metadata, and then combine them with the modified values in a new body to update the IoT hub.
Sample Request:
PUT https://management.azure.com/subscriptions/91d12660-3dec-467a-be2a-213b5544ddc0/resourceGroups/myResourceGroup/providers/Microsoft.Devices/IotHubs/testHub?api-version=2018-04-01
Request Body:
{
"name": "iot-dps-cit-hub-1",
"type": "Microsoft.Devices/IotHubs",
"location": "centraluseuap",
"tags": {},
"etag": "AAAAAAFD6M4=",
"properties": {
"operationsMonitoringProperties": {
"events": {
"None": "None",
"Connections": "None",
"DeviceTelemetry": "None",
"C2DCommands": "None",
"DeviceIdentityOperations": "None",
"FileUploadOperations": "None",
"Routes": "None"
}
},
"state": "Active",
"provisioningState": "Succeeded",
"ipFilterRules": [],
"hostName": "iot-dps-cit-hub-1.azure-devices.net",
"eventHubEndpoints": {
"events": {
"retentionTimeInDays": 1,
"partitionCount": 2,
"partitionIds": [
"0",
"1"
],
"path": "iot-dps-cit-hub-1",
"endpoint": "sb://iothub-ns-iot-dps-ci-245306-76aca8e13b.servicebus.windows.net/"
},
"operationsMonitoringEvents": {
"retentionTimeInDays": 1,
"partitionCount": 2,
"partitionIds": [
"0",
"1"
],
"path": "iot-dps-cit-hub-1-operationmonitoring",
"endpoint": "sb://iothub-ns-iot-dps-ci-245306-76aca8e13b.servicebus.windows.net/"
}
},
"routing": {
"endpoints": {
"serviceBusQueues": [],
"serviceBusTopics": [],
"eventHubs": [],
"storageContainers": []
},
"routes": [],
"fallbackRoute": {
"name": "$fallback",
"source": "DeviceMessages",
"condition": "true",
"endpointNames": [
"events"
],
"isEnabled": true
}
},
"storageEndpoints": {
"$default": {
"sasTtlAsIso8601": "PT1H",
"connectionString": "",
"containerName": ""
}
},
"messagingEndpoints": {
"fileNotifications": {
"lockDurationAsIso8601": "PT1M",
"ttlAsIso8601": "PT1H",
"maxDeliveryCount": 10
}
},
"enableFileUploadNotifications": false,
"cloudToDevice": {
"maxDeliveryCount": 10,
"defaultTtlAsIso8601": "PT1H",
"feedback": {
"lockDurationAsIso8601": "PT1M",
"ttlAsIso8601": "PT1H",
"maxDeliveryCount": 10
}
},
"features": "None"
},
"sku": {
"name": "S1",
"tier": "Standard",
"capacity": 1
}
}
I'm using Azure RM Template deployments with a Visual Studio 2017 Resource Group project to deploy IoTHub instance with diagnostics settings in Log Analytics.
Deploying IoTHub alone is successful, the problem is with deployment of the Diagnostics Settings template.
I'm following the instructions for deploying Diagnostics Settings as Non-Compute resource template
The strange error that I receive is the following:
Error: Code=InvalidTemplate; Message=Deployment template validation
failed: 'The template resource 'Microsoft.Insights/BasicDiagnostics'
for type 'providers/diagnosticSettings' at line '69' and column '9'
has incorrect segment lengths. A nested resource type must have
identical number of segments as its resource name. A root resource
type must have segment length one greater than its resource name.
Why does it fail like this, even though I follow the documentation with the provided example?
Here are my template definitions:
"resources": [
{
"type": "Microsoft.Devices/IotHubs",
"sku": {
"name": "[parameters('sku.name')]",
"capacity": "[parameters('sku.units')]"
},
"name": "[parameters('iothubname')]",
"apiVersion": "2018-04-01",
"location": "[resourceGroup().location]",
"properties": {
"eventHubEndpoints": {
"events": {
"retentionTimeInDays": "[parameters('endpoints.events.retention')]",
"partitionCount": "[parameters('endpoints.events.partitions')]"
},
"operationsMonitoringEvents": {
"retentionTimeInDays": "[parameters('endpoints.operationsMonitoringEvents.retention')]",
"partitionCount": "[parameters('endpoints.operationsMonitoringEvents.partitions')]"
}
},
"features": "[parameters('features')]"
}
},
{
"type": "providers/diagnosticSettings",
"name": "[concat('Microsoft.Insights/', parameters('iotHub.diagnostics.settingName'))]",
"dependsOn": [
"[resourceId('Microsoft.Devices/IoTHubs', parameters('iothubname'))]"
],
"apiVersion": "2017-05-01-preview",
"properties": {
"name": "[parameters('iotHub.diagnostics.settingName')]",
"workspaceId": "[parameters('iotHub.diagnostics.workspaceId')]",
"logs": [
{
"category": "Connections",
"enabled": true,
"retentionPolicy": {
"days": 0,
"enabled": false
}
},
{
"category": "Configurations",
"enabled": true,
"retentionPolicy": {
"days": 0,
"enabled": false
}
},
{
"category": "D2CTwinOperations",
"enabled": true,
"retentionPolicy": {
"days": 0,
"enabled": false
}
},
{
"category": "C2DTwinOperations",
"enabled": true,
"retentionPolicy": {
"days": 0,
"enabled": false
}
}
],
"metrics": [
{
"category": "AllMetrics",
"enabled": true,
"retentionPolicy": {
"days": 0,
"enabled": false
}
}
]
}
}
]
Any help much appreciated!
this needs to be a sub resource of the IOT hub, not a separate resource.
{
"type": "Microsoft.Devices/IotHubs",
"sku": {
"name": "[parameters('sku.name')]",
"capacity": "[parameters('sku.units')]"
},
"name": "[parameters('iothubname')]",
"apiVersion": "2018-04-01",
"location": "[resourceGroup().location]",
"properties": {
xxx
},
"features": "[parameters('features')]",
"resources": [
{
"type": "providers/diagnosticsSettings",
xxx
}
]
}
},