Azure IoT Hub Iothub
This page shows how to write Terraform and Azure Resource Manager for IoT Hub Iothub and write them securely.
azurerm_iothub (Terraform)
The Iothub in IoT Hub can be configured in Terraform with the resource name azurerm_iothub. The following sections describe 10 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "azurerm_iothub" "plant_iot" {
name = var.iot_hub_name
location = var.location
resource_group_name = var.resource_group_name
sku {
resource "azurerm_iothub" "iot" {
location = azurerm_resource_group.rg.location
name = "iot-lc"
resource_group_name = azurerm_resource_group.rg.name
sku {
name = "F1"
resource "azurerm_iothub" "iothub" {
name = var.iot_hub_name
resource_group_name = azurerm_resource_group.rg.name
location = var.location
sku {
resource "azurerm_iothub" "b59iothub" {
name = "b59iothub"
resource_group_name = azurerm_resource_group.b59.name
location = azurerm_resource_group.b59.location
sku {
resource "azurerm_iothub" "iothub" {
name = var.iot_hub_name
resource_group_name = azurerm_resource_group.rg.name
location = var.location
sku {
resource "azurerm_iothub" "this" {
name = var.iothub_name
resource_group_name = data.azurerm_resource_group.this.name
location = data.azurerm_resource_group.this.location
sku {
resource "azurerm_iothub" "myitohub" {
name = "__var.resourceiothubname__"
resource_group_name = data.azurerm_resource_group.resourcegropuiothub.name
location = data.azurerm_resource_group.resourcegropuiothub.location
sku {
resource "azurerm_iothub" "iothub" {
name = var.iot_hub_name
resource_group_name = azurerm_resource_group.rg.name
location = var.location
sku {
resource "azurerm_iothub" "iot" {
name = var.name-iot
resource_group_name = azurerm_resource_group.rg.name
location = var.location
sku {
resource "azurerm_iothub" "ioth" {
name = var.iothub_name
resource_group_name = var.resource_group_name
location = var.resource_group_location
sku {
name = var.iothub_sku_name
Parameters
-
endpointoptional computed - list of object-
batch_frequency_in_seconds- number -
connection_string- string -
container_name- string -
encoding- string -
file_name_format- string -
max_chunk_size_in_bytes- number -
name- string -
resource_group_name- string -
type- string
-
-
enrichmentoptional computed - list of object-
endpoint_names- list of string -
key- string -
value- string
-
-
event_hub_events_endpointoptional computed - string -
event_hub_events_pathoptional computed - string -
event_hub_operations_endpointoptional computed - string -
event_hub_operations_pathoptional computed - string -
event_hub_partition_countoptional computed - number -
event_hub_retention_in_daysoptional computed - number -
hostnameoptional computed - string -
idoptional computed - string -
locationrequired - string -
min_tls_versionoptional - string -
namerequired - string -
public_network_access_enabledoptional - bool -
resource_group_namerequired - string -
routeoptional computed - list of object-
condition- string -
enabled- bool -
endpoint_names- list of string -
name- string -
source- string
-
-
shared_access_policyoptional computed - list of object-
key_name- string -
permissions- string -
primary_key- string -
secondary_key- string
-
-
tagsoptional - map from string to string -
typeoptional computed - string -
fallback_routelist block-
conditionoptional - string -
enabledoptional computed - bool -
endpoint_namesoptional computed - list of string -
sourceoptional - string
-
-
file_uploadlist block-
connection_stringrequired - string -
container_namerequired - string -
default_ttloptional computed - string -
lock_durationoptional computed - string -
max_delivery_countoptional - number -
notificationsoptional - bool -
sas_ttloptional computed - string
-
-
ip_filter_ruleset block -
skulist block -
timeoutssingle block
Explanation in Terraform Registry
Manages an IotHub
NOTE: Endpoints can be defined either directly on the
azurerm_iothubresource, or using theazurerm_iothub_endpoint_*resources - but the two ways of defining the endpoints cannot be used together. If both are used against the same IoTHub, spurious changes will occur. Also, defining aazurerm_iothub_endpoint_*resource and another endpoint of a different type directly on theazurerm_iothubresource is not supported.NOTE: Routes can be defined either directly on the
azurerm_iothubresource, or using theazurerm_iothub_routeresource - but the two cannot be used together. If both are used against the same IoTHub, spurious changes will occur.NOTE: Enrichments can be defined either directly on the
azurerm_iothubresource, or using theazurerm_iothub_enrichmentresource - but the two cannot be used together. If both are used against the same IoTHub, spurious changes will occur.NOTE: Fallback route can be defined either directly on the
azurerm_iothubresource, or using theazurerm_iothub_fallback_routeresource - but the two cannot be used together. If both are used against the same IoTHub, spurious changes will occur.
Microsoft.Devices/IotHubs (Azure Resource Manager)
The IotHubs in Microsoft.Devices can be configured in Azure Resource Manager with the resource name Microsoft.Devices/IotHubs. The following sections describe how to use the resource and its parameters.
Example Usage from GitHub
"type": "Microsoft.Devices/IotHubs",
"apiVersion": "2020-03-01",
"name": "[variables('CameraIotHubName')]",
"location": "[parameters('Region')]",
"sku": {
"name": "S1",
"type": "Microsoft.Devices/IotHubs",
"name": "[parameters('hubName')]",
"location": "North Europe",
"sku": {
"name": "S1",
"tier": "Standard",
"type": "Microsoft.Devices/IotHubs",
"apiVersion": "2020-03-01",
"name": "[variables('CameraIotHubName')]",
"location": "[parameters('Region')]",
"sku": {
"name": "S1",
"type": "Microsoft.Devices/IotHubs",
"name": "[parameters('iotHubName')]",
"location": "[parameters('azureLocation')]",
"sku": {
"name": "S1",
"tier": "Standard",
"type": "Microsoft.Devices/IotHubs",
"apiVersion": "2018-04-01",
"name": "[parameters('iotHubName')]",
"location": "[parameters('location')]",
"properties": {
"eventHubEndpoints": {
"type": "Microsoft.Devices/IotHubs",
"name": "[parameters('resourceName')]",
"location": "[resourceGroup().location]",
"properties": {
"eventHubEndpoints": {
"events": {
"type": "Microsoft.Devices/IotHubs",
"apiVersion": "2018-04-01",
"name": "[parameters('iotHubName')]",
"location": "[parameters('location')]",
"properties": {
"eventHubEndpoints": {
"type": "Microsoft.Devices/IotHubs",
"name": "[variables('hubName')]",
"location": "[variables('location')]",
"sku": {
"name": "S1",
"tier": "Standard",
"type": "Microsoft.Devices/IotHubs",
"apiVersion": "2018-04-01",
"name": "[parameters('iotHubName')]",
"location": "[parameters('location')]",
"properties": {
"eventHubEndpoints": {
"type": "Microsoft.Devices/IotHubs",
"apiVersion": "2018-04-01",
"name": "[parameters('iotHubName')]",
"location": "[parameters('location')]",
"properties": {
"eventHubEndpoints": {
Parameters
apiVersionrequired - stringetagoptional - stringThe Etag field is not required. If it is provided in the response body, it must also be provided as a header per the normal ETag convention.
identityoptionaltypeoptional - stringThe type of identity used for the resource. The type 'SystemAssigned, UserAssigned' includes both an implicitly created identity and a set of user assigned identities. The type 'None' will remove any identities from the service.
userAssignedIdentitiesoptional - undefined
locationrequired - stringThe resource location.
namerequired - stringThe name of the IoT hub.
propertiesrequiredallowedFqdnListoptional - arrayList of allowed FQDNs(Fully Qualified Domain Name) for egress from Iot Hub.
authorizationPoliciesoptional arraykeyNamerequired - stringThe name of the shared access policy.
primaryKeyoptional - stringThe primary key.
rightsrequired - stringThe permissions assigned to the shared access policy.
secondaryKeyoptional - stringThe secondary key.
cloudToDeviceoptionaldefaultTtlAsIso8601optional - stringThe default time to live for cloud-to-device messages in the device queue. See: https://docs.microsoft.com/azure/iot-hub/iot-hub-devguide-messaging#cloud-to-device-messages.
feedbackoptionallockDurationAsIso8601optional - stringThe lock duration for the feedback queue. See: https://docs.microsoft.com/azure/iot-hub/iot-hub-devguide-messaging#cloud-to-device-messages.
maxDeliveryCountoptional - integerThe number of times the IoT hub attempts to deliver a message on the feedback queue. See: https://docs.microsoft.com/azure/iot-hub/iot-hub-devguide-messaging#cloud-to-device-messages.
ttlAsIso8601optional - stringThe period of time for which a message is available to consume before it is expired by the IoT hub. See: https://docs.microsoft.com/azure/iot-hub/iot-hub-devguide-messaging#cloud-to-device-messages.
maxDeliveryCountoptional - integerThe max delivery count for cloud-to-device messages in the device queue. See: https://docs.microsoft.com/azure/iot-hub/iot-hub-devguide-messaging#cloud-to-device-messages.
commentsoptional - stringIoT hub comments.
disableDeviceSASoptional - booleanIf true, all device(including Edge devices but excluding modules) scoped SAS keys cannot be used for authentication.
disableLocalAuthoptional - booleanIf true, SAS tokens with Iot hub scoped SAS keys cannot be used for authentication.
disableModuleSASoptional - booleanIf true, all module scoped SAS keys cannot be used for authentication.
enableDataResidencyoptional - booleanThis property when set to true, will enable data residency, thus, disabling disaster recovery.
enableFileUploadNotificationsoptional - booleanIf True, file upload notifications are enabled.
eventHubEndpointsoptional - undefinedThe Event Hub-compatible endpoint properties. The only possible keys to this dictionary is events. This key has to be present in the dictionary while making create or update calls for the IoT hub.
featuresoptional - stringThe capabilities and features enabled for the IoT hub.
ipFilterRulesoptional arrayactionrequired - stringThe desired action for requests captured by this rule.
filterNamerequired - stringThe name of the IP filter rule.
ipMaskrequired - stringA string that contains the IP address range in CIDR notation for the rule.
messagingEndpointsoptional - undefinedThe messaging endpoint properties for the file upload notification queue.
minTlsVersionoptional - stringSpecifies the minimum TLS version to support for this hub. Can be set to "1.2" to have clients that use a TLS version below 1.2 to be rejected.
networkRuleSetsoptionalapplyToBuiltInEventHubEndpointrequired - booleanIf True, then Network Rule Set is also applied to BuiltIn EventHub EndPoint of IotHub
defaultActionoptional - stringDefault Action for Network Rule Set.
ipRulesrequired arrayactionoptional - stringIP Filter Action.
filterNamerequired - stringName of the IP filter rule.
ipMaskrequired - stringA string that contains the IP address range in CIDR notation for the rule.
privateEndpointConnectionsoptional arraypropertiesrequiredprivateEndpointoptionalprivateLinkServiceConnectionStaterequiredactionsRequiredoptional - stringActions required for a private endpoint connection
descriptionrequired - stringThe description for the current state of a private endpoint connection
statusrequired - stringThe status of a private endpoint connection.
publicNetworkAccessoptional - stringWhether requests from Public Network are allowed.
restrictOutboundNetworkAccessoptional - booleanIf true, egress from IotHub will be restricted to only the allowed FQDNs that are configured via allowedFqdnList.
routingoptionalendpointsoptionaleventHubsoptional arrayauthenticationTypeoptional - stringMethod used to authenticate against the event hub endpoint.
connectionStringoptional - stringThe connection string of the event hub endpoint.
endpointUrioptional - stringThe url of the event hub endpoint. It must include the protocol sb://
entityPathoptional - stringEvent hub name on the event hub namespace
idoptional - stringId of the event hub endpoint
identityoptionaluserAssignedIdentityoptional - stringThe user assigned identity.
namerequired - stringThe name that identifies this endpoint. The name can only include alphanumeric characters, periods, underscores, hyphens and has a maximum length of 64 characters. The following names are reserved: events, fileNotifications, $default. Endpoint names must be unique across endpoint types.
resourceGroupoptional - stringThe name of the resource group of the event hub endpoint.
subscriptionIdoptional - stringThe subscription identifier of the event hub endpoint.
serviceBusQueuesoptional arrayauthenticationTypeoptional - stringMethod used to authenticate against the service bus queue endpoint.
connectionStringoptional - stringThe connection string of the service bus queue endpoint.
endpointUrioptional - stringThe url of the service bus queue endpoint. It must include the protocol sb://
entityPathoptional - stringQueue name on the service bus namespace
idoptional - stringId of the service bus queue endpoint
identityoptionaluserAssignedIdentityoptional - stringThe user assigned identity.
namerequired - stringThe name that identifies this endpoint. The name can only include alphanumeric characters, periods, underscores, hyphens and has a maximum length of 64 characters. The following names are reserved: events, fileNotifications, $default. Endpoint names must be unique across endpoint types. The name need not be the same as the actual queue name.
resourceGroupoptional - stringThe name of the resource group of the service bus queue endpoint.
subscriptionIdoptional - stringThe subscription identifier of the service bus queue endpoint.
serviceBusTopicsoptional arrayauthenticationTypeoptional - stringMethod used to authenticate against the service bus topic endpoint.
connectionStringoptional - stringThe connection string of the service bus topic endpoint.
endpointUrioptional - stringThe url of the service bus topic endpoint. It must include the protocol sb://
entityPathoptional - stringQueue name on the service bus topic
idoptional - stringId of the service bus topic endpoint
identityoptionaluserAssignedIdentityoptional - stringThe user assigned identity.
namerequired - stringThe name that identifies this endpoint. The name can only include alphanumeric characters, periods, underscores, hyphens and has a maximum length of 64 characters. The following names are reserved: events, fileNotifications, $default. Endpoint names must be unique across endpoint types. The name need not be the same as the actual topic name.
resourceGroupoptional - stringThe name of the resource group of the service bus topic endpoint.
subscriptionIdoptional - stringThe subscription identifier of the service bus topic endpoint.
storageContainersoptional arrayauthenticationTypeoptional - stringMethod used to authenticate against the storage endpoint.
batchFrequencyInSecondsoptional - integerTime interval at which blobs are written to storage. Value should be between 60 and 720 seconds. Default value is 300 seconds.
connectionStringoptional - stringThe connection string of the storage account.
containerNamerequired - stringThe name of storage container in the storage account.
encodingoptional - stringEncoding that is used to serialize messages to blobs. Supported values are 'avro', 'avrodeflate', and 'JSON'. Default value is 'avro'.
endpointUrioptional - stringThe url of the storage endpoint. It must include the protocol https://
fileNameFormatoptional - stringFile name format for the blob. Default format is {iothub}/{partition}/{YYYY}/{MM}/{DD}/{HH}/{mm}. All parameters are mandatory but can be reordered.
idoptional - stringId of the storage container endpoint
identityoptionaluserAssignedIdentityoptional - stringThe user assigned identity.
maxChunkSizeInBytesoptional - integerMaximum number of bytes for each blob written to storage. Value should be between 10485760(10MB) and 524288000(500MB). Default value is 314572800(300MB).
namerequired - stringThe name that identifies this endpoint. The name can only include alphanumeric characters, periods, underscores, hyphens and has a maximum length of 64 characters. The following names are reserved: events, fileNotifications, $default. Endpoint names must be unique across endpoint types.
resourceGroupoptional - stringThe name of the resource group of the storage account.
subscriptionIdoptional - stringThe subscription identifier of the storage account.
enrichmentsoptional arrayendpointNamesrequired - arrayThe list of endpoints for which the enrichment is applied to the message.
keyrequired - stringThe key or name for the enrichment property.
valuerequired - stringThe value for the enrichment property.
fallbackRouteoptionalconditionoptional - stringThe condition which is evaluated in order to apply the fallback route. If the condition is not provided it will evaluate to true by default. For grammar, See: https://docs.microsoft.com/azure/iot-hub/iot-hub-devguide-query-language
endpointNamesrequired - arrayThe list of endpoints to which the messages that satisfy the condition are routed to. Currently only 1 endpoint is allowed.
isEnabledrequired - booleanUsed to specify whether the fallback route is enabled.
nameoptional - stringThe name of the route. The name can only include alphanumeric characters, periods, underscores, hyphens, has a maximum length of 64 characters, and must be unique.
sourcerequired - stringThe source to which the routing rule is to be applied to. For example, DeviceMessages.
routesoptional arrayconditionoptional - stringThe condition that is evaluated to apply the routing rule. If no condition is provided, it evaluates to true by default. For grammar, see: https://docs.microsoft.com/azure/iot-hub/iot-hub-devguide-query-language
endpointNamesrequired - arrayThe list of endpoints to which messages that satisfy the condition are routed. Currently only one endpoint is allowed.
isEnabledrequired - booleanUsed to specify whether a route is enabled.
namerequired - stringThe name of the route. The name can only include alphanumeric characters, periods, underscores, hyphens, has a maximum length of 64 characters, and must be unique.
sourcerequired - stringThe source that the routing rule is to be applied to, such as DeviceMessages.
storageEndpointsoptional - undefinedThe list of Azure Storage endpoints where you can upload files. Currently you can configure only one Azure Storage account and that MUST have its key as $default. Specifying more than one storage account causes an error to be thrown. Not specifying a value for this property when the enableFileUploadNotifications property is set to True, causes an error to be thrown.
skurequiredcapacityoptional - integerThe number of provisioned IoT Hub units. See: https://docs.microsoft.com/azure/azure-subscription-service-limits#iot-hub-limits.
namerequired - stringThe name of the SKU.
tagsoptional - stringThe resource tags.
typerequired - string
Frequently asked questions
What is Azure IoT Hub Iothub?
Azure IoT Hub Iothub is a resource for IoT Hub of Microsoft Azure. Settings can be wrote in Terraform.
Where can I find the example code for the Azure IoT Hub Iothub?
For Terraform, the prashant101386/devops, finn-wa-log-cabin/lc-devops-terraform and Manuss20/trackmverse source code examples are useful. See the Terraform Example section for further details.
For Azure Resource Manager, the solliancenet/azure-synapse-in-a-day-demos, niallermoran/SmartHVACDemo and Moisesjoel/Primer-proyecto source code examples are useful. See the Azure Resource Manager Example section for further details.