Io THub
Manages an IotHub
Note: Endpoints can be defined either directly on the
azure.iot.IoTHub
resource, 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 theazure.iot.IoTHub
resource is not supported. Note: Routes can be defined either directly on theazure.iot.IoTHub
resource, or using theazure.iot.Route
resource - 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 theazure.iot.IoTHub
resource, or using theazure.iot.Enrichment
resource - 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 theazure.iot.IoTHub
resource, or using theazure.iot.FallbackRoute
resource - but the two cannot be used together. If both are used against the same IoTHub, spurious changes will occur. Note: File upload can be defined either directly on theazure.iot.IoTHub
resource, or using theazure.iot.FileUpload
resource - but the two cannot be used together. If both are used against the same IoTHub, spurious changes will occur.
Example Usage
import * as pulumi from "@pulumi/pulumi";
import * as azure from "@pulumi/azure";
const example = new azure.core.ResourceGroup("example", {
name: "example-resources",
location: "West Europe",
});
const exampleAccount = new azure.storage.Account("example", {
name: "examplestorage",
resourceGroupName: example.name,
location: example.location,
accountTier: "Standard",
accountReplicationType: "LRS",
});
const exampleContainer = new azure.storage.Container("example", {
name: "examplecontainer",
storageAccountName: exampleAccount.name,
containerAccessType: "private",
});
const exampleEventHubNamespace = new azure.eventhub.EventHubNamespace("example", {
name: "example-namespace",
resourceGroupName: example.name,
location: example.location,
sku: "Basic",
});
const exampleEventHub = new azure.eventhub.EventHub("example", {
name: "example-eventhub",
resourceGroupName: example.name,
namespaceName: exampleEventHubNamespace.name,
partitionCount: 2,
messageRetention: 1,
});
const exampleAuthorizationRule = new azure.eventhub.AuthorizationRule("example", {
resourceGroupName: example.name,
namespaceName: exampleEventHubNamespace.name,
eventhubName: exampleEventHub.name,
name: "acctest",
send: true,
});
const exampleIoTHub = new azure.iot.IoTHub("example", {
name: "Example-IoTHub",
resourceGroupName: example.name,
location: example.location,
localAuthenticationEnabled: false,
sku: {
name: "S1",
capacity: 1,
},
endpoints: [
{
type: "AzureIotHub.StorageContainer",
connectionString: exampleAccount.primaryBlobConnectionString,
name: "export",
batchFrequencyInSeconds: 60,
maxChunkSizeInBytes: 10485760,
containerName: exampleContainer.name,
encoding: "Avro",
fileNameFormat: "{iothub}/{partition}_{YYYY}_{MM}_{DD}_{HH}_{mm}",
},
{
type: "AzureIotHub.EventHub",
connectionString: exampleAuthorizationRule.primaryConnectionString,
name: "export2",
},
],
routes: [
{
name: "export",
source: "DeviceMessages",
condition: "true",
endpointNames: ["export"],
enabled: true,
},
{
name: "export2",
source: "DeviceMessages",
condition: "true",
endpointNames: ["export2"],
enabled: true,
},
],
enrichments: [{
key: "tenant",
value: "$twin.tags.Tenant",
endpointNames: [
"export",
"export2",
],
}],
cloudToDevice: {
maxDeliveryCount: 30,
defaultTtl: "PT1H",
feedbacks: [{
timeToLive: "PT1H10M",
maxDeliveryCount: 15,
lockDuration: "PT30S",
}],
},
tags: {
purpose: "testing",
},
});
import pulumi
import pulumi_azure as azure
example = azure.core.ResourceGroup("example",
name="example-resources",
location="West Europe")
example_account = azure.storage.Account("example",
name="examplestorage",
resource_group_name=example.name,
location=example.location,
account_tier="Standard",
account_replication_type="LRS")
example_container = azure.storage.Container("example",
name="examplecontainer",
storage_account_name=example_account.name,
container_access_type="private")
example_event_hub_namespace = azure.eventhub.EventHubNamespace("example",
name="example-namespace",
resource_group_name=example.name,
location=example.location,
sku="Basic")
example_event_hub = azure.eventhub.EventHub("example",
name="example-eventhub",
resource_group_name=example.name,
namespace_name=example_event_hub_namespace.name,
partition_count=2,
message_retention=1)
example_authorization_rule = azure.eventhub.AuthorizationRule("example",
resource_group_name=example.name,
namespace_name=example_event_hub_namespace.name,
eventhub_name=example_event_hub.name,
name="acctest",
send=True)
example_io_t_hub = azure.iot.IoTHub("example",
name="Example-IoTHub",
resource_group_name=example.name,
location=example.location,
local_authentication_enabled=False,
sku={
"name": "S1",
"capacity": 1,
},
endpoints=[
{
"type": "AzureIotHub.StorageContainer",
"connection_string": example_account.primary_blob_connection_string,
"name": "export",
"batch_frequency_in_seconds": 60,
"max_chunk_size_in_bytes": 10485760,
"container_name": example_container.name,
"encoding": "Avro",
"file_name_format": "{iothub}/{partition}_{YYYY}_{MM}_{DD}_{HH}_{mm}",
},
{
"type": "AzureIotHub.EventHub",
"connection_string": example_authorization_rule.primary_connection_string,
"name": "export2",
},
],
routes=[
{
"name": "export",
"source": "DeviceMessages",
"condition": "true",
"endpoint_names": ["export"],
"enabled": True,
},
{
"name": "export2",
"source": "DeviceMessages",
"condition": "true",
"endpoint_names": ["export2"],
"enabled": True,
},
],
enrichments=[{
"key": "tenant",
"value": "$twin.tags.Tenant",
"endpoint_names": [
"export",
"export2",
],
}],
cloud_to_device={
"max_delivery_count": 30,
"default_ttl": "PT1H",
"feedbacks": [{
"time_to_live": "PT1H10M",
"max_delivery_count": 15,
"lock_duration": "PT30S",
}],
},
tags={
"purpose": "testing",
})
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Azure = Pulumi.Azure;
return await Deployment.RunAsync(() =>
{
var example = new Azure.Core.ResourceGroup("example", new()
{
Name = "example-resources",
Location = "West Europe",
});
var exampleAccount = new Azure.Storage.Account("example", new()
{
Name = "examplestorage",
ResourceGroupName = example.Name,
Location = example.Location,
AccountTier = "Standard",
AccountReplicationType = "LRS",
});
var exampleContainer = new Azure.Storage.Container("example", new()
{
Name = "examplecontainer",
StorageAccountName = exampleAccount.Name,
ContainerAccessType = "private",
});
var exampleEventHubNamespace = new Azure.EventHub.EventHubNamespace("example", new()
{
Name = "example-namespace",
ResourceGroupName = example.Name,
Location = example.Location,
Sku = "Basic",
});
var exampleEventHub = new Azure.EventHub.EventHub("example", new()
{
Name = "example-eventhub",
ResourceGroupName = example.Name,
NamespaceName = exampleEventHubNamespace.Name,
PartitionCount = 2,
MessageRetention = 1,
});
var exampleAuthorizationRule = new Azure.EventHub.AuthorizationRule("example", new()
{
ResourceGroupName = example.Name,
NamespaceName = exampleEventHubNamespace.Name,
EventhubName = exampleEventHub.Name,
Name = "acctest",
Send = true,
});
var exampleIoTHub = new Azure.Iot.IoTHub("example", new()
{
Name = "Example-IoTHub",
ResourceGroupName = example.Name,
Location = example.Location,
LocalAuthenticationEnabled = false,
Sku = new Azure.Iot.Inputs.IoTHubSkuArgs
{
Name = "S1",
Capacity = 1,
},
Endpoints = new[]
{
new Azure.Iot.Inputs.IoTHubEndpointArgs
{
Type = "AzureIotHub.StorageContainer",
ConnectionString = exampleAccount.PrimaryBlobConnectionString,
Name = "export",
BatchFrequencyInSeconds = 60,
MaxChunkSizeInBytes = 10485760,
ContainerName = exampleContainer.Name,
Encoding = "Avro",
FileNameFormat = "{iothub}/{partition}_{YYYY}_{MM}_{DD}_{HH}_{mm}",
},
new Azure.Iot.Inputs.IoTHubEndpointArgs
{
Type = "AzureIotHub.EventHub",
ConnectionString = exampleAuthorizationRule.PrimaryConnectionString,
Name = "export2",
},
},
Routes = new[]
{
new Azure.Iot.Inputs.IoTHubRouteArgs
{
Name = "export",
Source = "DeviceMessages",
Condition = "true",
EndpointNames = new[]
{
"export",
},
Enabled = true,
},
new Azure.Iot.Inputs.IoTHubRouteArgs
{
Name = "export2",
Source = "DeviceMessages",
Condition = "true",
EndpointNames = new[]
{
"export2",
},
Enabled = true,
},
},
Enrichments = new[]
{
new Azure.Iot.Inputs.IoTHubEnrichmentArgs
{
Key = "tenant",
Value = "$twin.tags.Tenant",
EndpointNames = new[]
{
"export",
"export2",
},
},
},
CloudToDevice = new Azure.Iot.Inputs.IoTHubCloudToDeviceArgs
{
MaxDeliveryCount = 30,
DefaultTtl = "PT1H",
Feedbacks = new[]
{
new Azure.Iot.Inputs.IoTHubCloudToDeviceFeedbackArgs
{
TimeToLive = "PT1H10M",
MaxDeliveryCount = 15,
LockDuration = "PT30S",
},
},
},
Tags =
{
{ "purpose", "testing" },
},
});
});
package main
import (
"github.com/pulumi/pulumi-azure/sdk/v6/go/azure/core"
"github.com/pulumi/pulumi-azure/sdk/v6/go/azure/eventhub"
"github.com/pulumi/pulumi-azure/sdk/v6/go/azure/iot"
"github.com/pulumi/pulumi-azure/sdk/v6/go/azure/storage"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
example, err := core.NewResourceGroup(ctx, "example", &core.ResourceGroupArgs{
Name: pulumi.String("example-resources"),
Location: pulumi.String("West Europe"),
})
if err != nil {
return err
}
exampleAccount, err := storage.NewAccount(ctx, "example", &storage.AccountArgs{
Name: pulumi.String("examplestorage"),
ResourceGroupName: example.Name,
Location: example.Location,
AccountTier: pulumi.String("Standard"),
AccountReplicationType: pulumi.String("LRS"),
})
if err != nil {
return err
}
exampleContainer, err := storage.NewContainer(ctx, "example", &storage.ContainerArgs{
Name: pulumi.String("examplecontainer"),
StorageAccountName: exampleAccount.Name,
ContainerAccessType: pulumi.String("private"),
})
if err != nil {
return err
}
exampleEventHubNamespace, err := eventhub.NewEventHubNamespace(ctx, "example", &eventhub.EventHubNamespaceArgs{
Name: pulumi.String("example-namespace"),
ResourceGroupName: example.Name,
Location: example.Location,
Sku: pulumi.String("Basic"),
})
if err != nil {
return err
}
exampleEventHub, err := eventhub.NewEventHub(ctx, "example", &eventhub.EventHubArgs{
Name: pulumi.String("example-eventhub"),
ResourceGroupName: example.Name,
NamespaceName: exampleEventHubNamespace.Name,
PartitionCount: pulumi.Int(2),
MessageRetention: pulumi.Int(1),
})
if err != nil {
return err
}
exampleAuthorizationRule, err := eventhub.NewAuthorizationRule(ctx, "example", &eventhub.AuthorizationRuleArgs{
ResourceGroupName: example.Name,
NamespaceName: exampleEventHubNamespace.Name,
EventhubName: exampleEventHub.Name,
Name: pulumi.String("acctest"),
Send: pulumi.Bool(true),
})
if err != nil {
return err
}
_, err = iot.NewIoTHub(ctx, "example", &iot.IoTHubArgs{
Name: pulumi.String("Example-IoTHub"),
ResourceGroupName: example.Name,
Location: example.Location,
LocalAuthenticationEnabled: pulumi.Bool(false),
Sku: &iot.IoTHubSkuArgs{
Name: pulumi.String("S1"),
Capacity: pulumi.Int(1),
},
Endpoints: iot.IoTHubEndpointArray{
&iot.IoTHubEndpointArgs{
Type: pulumi.String("AzureIotHub.StorageContainer"),
ConnectionString: exampleAccount.PrimaryBlobConnectionString,
Name: pulumi.String("export"),
BatchFrequencyInSeconds: pulumi.Int(60),
MaxChunkSizeInBytes: pulumi.Int(10485760),
ContainerName: exampleContainer.Name,
Encoding: pulumi.String("Avro"),
FileNameFormat: pulumi.String("{iothub}/{partition}_{YYYY}_{MM}_{DD}_{HH}_{mm}"),
},
&iot.IoTHubEndpointArgs{
Type: pulumi.String("AzureIotHub.EventHub"),
ConnectionString: exampleAuthorizationRule.PrimaryConnectionString,
Name: pulumi.String("export2"),
},
},
Routes: iot.IoTHubRouteArray{
&iot.IoTHubRouteArgs{
Name: pulumi.String("export"),
Source: pulumi.String("DeviceMessages"),
Condition: pulumi.String("true"),
EndpointNames: pulumi.StringArray{
pulumi.String("export"),
},
Enabled: pulumi.Bool(true),
},
&iot.IoTHubRouteArgs{
Name: pulumi.String("export2"),
Source: pulumi.String("DeviceMessages"),
Condition: pulumi.String("true"),
EndpointNames: pulumi.StringArray{
pulumi.String("export2"),
},
Enabled: pulumi.Bool(true),
},
},
Enrichments: iot.IoTHubEnrichmentArray{
&iot.IoTHubEnrichmentArgs{
Key: pulumi.String("tenant"),
Value: pulumi.String("$twin.tags.Tenant"),
EndpointNames: pulumi.StringArray{
pulumi.String("export"),
pulumi.String("export2"),
},
},
},
CloudToDevice: &iot.IoTHubCloudToDeviceArgs{
MaxDeliveryCount: pulumi.Int(30),
DefaultTtl: pulumi.String("PT1H"),
Feedbacks: iot.IoTHubCloudToDeviceFeedbackArray{
&iot.IoTHubCloudToDeviceFeedbackArgs{
TimeToLive: pulumi.String("PT1H10M"),
MaxDeliveryCount: pulumi.Int(15),
LockDuration: pulumi.String("PT30S"),
},
},
},
Tags: pulumi.StringMap{
"purpose": pulumi.String("testing"),
},
})
if err != nil {
return err
}
return nil
})
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.azure.core.ResourceGroup;
import com.pulumi.azure.core.ResourceGroupArgs;
import com.pulumi.azure.storage.Account;
import com.pulumi.azure.storage.AccountArgs;
import com.pulumi.azure.storage.Container;
import com.pulumi.azure.storage.ContainerArgs;
import com.pulumi.azure.eventhub.EventHubNamespace;
import com.pulumi.azure.eventhub.EventHubNamespaceArgs;
import com.pulumi.azure.eventhub.EventHub;
import com.pulumi.azure.eventhub.EventHubArgs;
import com.pulumi.azure.eventhub.AuthorizationRule;
import com.pulumi.azure.eventhub.AuthorizationRuleArgs;
import com.pulumi.azure.iot.IoTHub;
import com.pulumi.azure.iot.IoTHubArgs;
import com.pulumi.azure.iot.inputs.IoTHubSkuArgs;
import com.pulumi.azure.iot.inputs.IoTHubEndpointArgs;
import com.pulumi.azure.iot.inputs.IoTHubRouteArgs;
import com.pulumi.azure.iot.inputs.IoTHubEnrichmentArgs;
import com.pulumi.azure.iot.inputs.IoTHubCloudToDeviceArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var example = new ResourceGroup("example", ResourceGroupArgs.builder()
.name("example-resources")
.location("West Europe")
.build());
var exampleAccount = new Account("exampleAccount", AccountArgs.builder()
.name("examplestorage")
.resourceGroupName(example.name())
.location(example.location())
.accountTier("Standard")
.accountReplicationType("LRS")
.build());
var exampleContainer = new Container("exampleContainer", ContainerArgs.builder()
.name("examplecontainer")
.storageAccountName(exampleAccount.name())
.containerAccessType("private")
.build());
var exampleEventHubNamespace = new EventHubNamespace("exampleEventHubNamespace", EventHubNamespaceArgs.builder()
.name("example-namespace")
.resourceGroupName(example.name())
.location(example.location())
.sku("Basic")
.build());
var exampleEventHub = new EventHub("exampleEventHub", EventHubArgs.builder()
.name("example-eventhub")
.resourceGroupName(example.name())
.namespaceName(exampleEventHubNamespace.name())
.partitionCount(2)
.messageRetention(1)
.build());
var exampleAuthorizationRule = new AuthorizationRule("exampleAuthorizationRule", AuthorizationRuleArgs.builder()
.resourceGroupName(example.name())
.namespaceName(exampleEventHubNamespace.name())
.eventhubName(exampleEventHub.name())
.name("acctest")
.send(true)
.build());
var exampleIoTHub = new IoTHub("exampleIoTHub", IoTHubArgs.builder()
.name("Example-IoTHub")
.resourceGroupName(example.name())
.location(example.location())
.localAuthenticationEnabled(false)
.sku(IoTHubSkuArgs.builder()
.name("S1")
.capacity(1)
.build())
.endpoints(
IoTHubEndpointArgs.builder()
.type("AzureIotHub.StorageContainer")
.connectionString(exampleAccount.primaryBlobConnectionString())
.name("export")
.batchFrequencyInSeconds(60)
.maxChunkSizeInBytes(10485760)
.containerName(exampleContainer.name())
.encoding("Avro")
.fileNameFormat("{iothub}/{partition}_{YYYY}_{MM}_{DD}_{HH}_{mm}")
.build(),
IoTHubEndpointArgs.builder()
.type("AzureIotHub.EventHub")
.connectionString(exampleAuthorizationRule.primaryConnectionString())
.name("export2")
.build())
.routes(
IoTHubRouteArgs.builder()
.name("export")
.source("DeviceMessages")
.condition("true")
.endpointNames("export")
.enabled(true)
.build(),
IoTHubRouteArgs.builder()
.name("export2")
.source("DeviceMessages")
.condition("true")
.endpointNames("export2")
.enabled(true)
.build())
.enrichments(IoTHubEnrichmentArgs.builder()
.key("tenant")
.value("$twin.tags.Tenant")
.endpointNames(
"export",
"export2")
.build())
.cloudToDevice(IoTHubCloudToDeviceArgs.builder()
.maxDeliveryCount(30)
.defaultTtl("PT1H")
.feedbacks(IoTHubCloudToDeviceFeedbackArgs.builder()
.timeToLive("PT1H10M")
.maxDeliveryCount(15)
.lockDuration("PT30S")
.build())
.build())
.tags(Map.of("purpose", "testing"))
.build());
}
}
resources:
example:
type: azure:core:ResourceGroup
properties:
name: example-resources
location: West Europe
exampleAccount:
type: azure:storage:Account
name: example
properties:
name: examplestorage
resourceGroupName: ${example.name}
location: ${example.location}
accountTier: Standard
accountReplicationType: LRS
exampleContainer:
type: azure:storage:Container
name: example
properties:
name: examplecontainer
storageAccountName: ${exampleAccount.name}
containerAccessType: private
exampleEventHubNamespace:
type: azure:eventhub:EventHubNamespace
name: example
properties:
name: example-namespace
resourceGroupName: ${example.name}
location: ${example.location}
sku: Basic
exampleEventHub:
type: azure:eventhub:EventHub
name: example
properties:
name: example-eventhub
resourceGroupName: ${example.name}
namespaceName: ${exampleEventHubNamespace.name}
partitionCount: 2
messageRetention: 1
exampleAuthorizationRule:
type: azure:eventhub:AuthorizationRule
name: example
properties:
resourceGroupName: ${example.name}
namespaceName: ${exampleEventHubNamespace.name}
eventhubName: ${exampleEventHub.name}
name: acctest
send: true
exampleIoTHub:
type: azure:iot:IoTHub
name: example
properties:
name: Example-IoTHub
resourceGroupName: ${example.name}
location: ${example.location}
localAuthenticationEnabled: false
sku:
name: S1
capacity: '1'
endpoints:
- type: AzureIotHub.StorageContainer
connectionString: ${exampleAccount.primaryBlobConnectionString}
name: export
batchFrequencyInSeconds: 60
maxChunkSizeInBytes: 1.048576e+07
containerName: ${exampleContainer.name}
encoding: Avro
fileNameFormat: '{iothub}/{partition}_{YYYY}_{MM}_{DD}_{HH}_{mm}'
- type: AzureIotHub.EventHub
connectionString: ${exampleAuthorizationRule.primaryConnectionString}
name: export2
routes:
- name: export
source: DeviceMessages
condition: 'true'
endpointNames:
- export
enabled: true
- name: export2
source: DeviceMessages
condition: 'true'
endpointNames:
- export2
enabled: true
enrichments:
- key: tenant
value: $twin.tags.Tenant
endpointNames:
- export
- export2
cloudToDevice:
maxDeliveryCount: 30
defaultTtl: PT1H
feedbacks:
- timeToLive: PT1H10M
maxDeliveryCount: 15
lockDuration: PT30S
tags:
purpose: testing
Import
IoTHubs can be imported using the resource id
, e.g.
$ pulumi import azure:iot/ioTHub:IoTHub hub1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Devices/iotHubs/hub1
Properties
An endpoint
block as defined below.
The EventHub compatible endpoint for events data
The EventHub namespace for events data
The EventHub compatible path for events data
The EventHub compatible endpoint for operational data
The EventHub compatible path for operational data
The number of device-to-cloud partitions used by backing event hubs. Must be between 2
and 128
. Defaults to 4
.
The event hub retention to use in days. Must be between 1
and 7
. Defaults to 1
.
A fallback_route
block as defined below. If the fallback route is enabled, messages that don't match any of the supplied routes are automatically sent to this route. Defaults to messages/events.
A file_upload
block as defined below.
An identity
block as defined below.
If false, SAS tokens with Iot hub scoped SAS keys cannot be used for authentication. Defaults to true
.
A network_rule_set
block as defined below.
The name of the resource group under which the IotHub resource has to be created. Changing this forces a new resource to be created.
One or more shared_access_policy
blocks as defined below.