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
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 exampleResourceGroup = new ResourceGroup("exampleResourceGroup", ResourceGroupArgs.builder()
.location("West Europe")
.build());
var exampleAccount = new Account("exampleAccount", AccountArgs.builder()
.resourceGroupName(exampleResourceGroup.name())
.location(exampleResourceGroup.location())
.accountTier("Standard")
.accountReplicationType("LRS")
.build());
var exampleContainer = new Container("exampleContainer", ContainerArgs.builder()
.storageAccountName(exampleAccount.name())
.containerAccessType("private")
.build());
var exampleEventHubNamespace = new EventHubNamespace("exampleEventHubNamespace", EventHubNamespaceArgs.builder()
.resourceGroupName(exampleResourceGroup.name())
.location(exampleResourceGroup.location())
.sku("Basic")
.build());
var exampleEventHub = new EventHub("exampleEventHub", EventHubArgs.builder()
.resourceGroupName(exampleResourceGroup.name())
.namespaceName(exampleEventHubNamespace.name())
.partitionCount(2)
.messageRetention(1)
.build());
var exampleAuthorizationRule = new AuthorizationRule("exampleAuthorizationRule", AuthorizationRuleArgs.builder()
.resourceGroupName(exampleResourceGroup.name())
.namespaceName(exampleEventHubNamespace.name())
.eventhubName(exampleEventHub.name())
.send(true)
.build());
var exampleIoTHub = new IoTHub("exampleIoTHub", IoTHubArgs.builder()
.resourceGroupName(exampleResourceGroup.name())
.location(exampleResourceGroup.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());
}
}
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