Skip to content

azurermIothubRoute

Manages an IotHub Route

\~> NOTE: Routes can be defined either directly on the azurermIothub resource, or using the azurermIothubRoute resource - but the two cannot be used together. If both are used against the same IoTHub, spurious changes will occur.

Example Usage

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as azurerm from "./.gen/providers/azurerm";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: azurerm.
For a more precise conversion please use the --provider flag in convert.*/
const azurermResourceGroupExample = new azurerm.resourceGroup.ResourceGroup(
  this,
  "example",
  {
    location: "West Europe",
    name: "example-resources",
  }
);
const azurermStorageAccountExample = new azurerm.storageAccount.StorageAccount(
  this,
  "example_1",
  {
    account_replication_type: "LRS",
    account_tier: "Standard",
    location: azurermResourceGroupExample.location,
    name: "examplestorageaccount",
    resource_group_name: azurermResourceGroupExample.name,
  }
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermStorageAccountExample.overrideLogicalId("example");
const azurermStorageContainerExample =
  new azurerm.storageContainer.StorageContainer(this, "example_2", {
    container_access_type: "private",
    name: "example",
    storage_account_name: azurermStorageAccountExample.name,
  });
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermStorageContainerExample.overrideLogicalId("example");
const azurermIothubExample = new azurerm.iothub.Iothub(this, "example_3", {
  location: azurermResourceGroupExample.location,
  name: "exampleIothub",
  resource_group_name: azurermResourceGroupExample.name,
  sku: [
    {
      capacity: "1",
      name: "S1",
    },
  ],
  tags: {
    purpose: "testing",
  },
});
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermIothubExample.overrideLogicalId("example");
const azurermIothubEndpointStorageContainerExample =
  new azurerm.iothubEndpointStorageContainer.IothubEndpointStorageContainer(
    this,
    "example_4",
    {
      batch_frequency_in_seconds: 60,
      connection_string:
        azurermStorageAccountExample.primaryBlobConnectionString,
      container_name: azurermStorageContainerExample.name,
      encoding: "Avro",
      file_name_format: "{iothub}/{partition}_{YYYY}_{MM}_{DD}_{HH}_{mm}",
      iothub_id: azurermIothubExample.id,
      max_chunk_size_in_bytes: 10485760,
      name: "example",
      resource_group_name: azurermResourceGroupExample.name,
    }
  );
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermIothubEndpointStorageContainerExample.overrideLogicalId("example");
const azurermIothubRouteExample = new azurerm.iothubRoute.IothubRoute(
  this,
  "example_5",
  {
    condition: "true",
    enabled: true,
    endpoint_names: [azurermIothubEndpointStorageContainerExample.name],
    iothub_name: azurermIothubExample.name,
    name: "example",
    resource_group_name: azurermResourceGroupExample.name,
    source: "DeviceMessages",
  }
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermIothubRouteExample.overrideLogicalId("example");

Argument Reference

The following arguments are supported:

  • name - (Required) The name of the route. Changing this forces a new resource to be created.

  • resourceGroupName - (Required) The name of the resource group under which the IotHub Route resource has to be created. Changing this forces a new resource to be created.

  • iothubName - (Required) The name of the IoTHub to which this Route belongs. Changing this forces a new resource to be created.

  • source - (Required) The source that the routing rule is to be applied to. Possible values include: deviceConnectionStateEvents, deviceJobLifecycleEvents, deviceLifecycleEvents, deviceMessages, digitalTwinChangeEvents, invalid, twinChangeEvents.

  • condition - (Optional) The 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.

  • endpointNames - (Required) The list of endpoints to which messages that satisfy the condition are routed. Currently only one endpoint is allowed.

  • enabled - (Required) Specifies whether a route is enabled.

Attributes Reference

The following attributes are exported:

  • id - The ID of the IoTHub Route.

Timeouts

The timeouts block allows you to specify timeouts for certain actions:

  • create - (Defaults to 30 minutes) Used when creating the IotHub Route.
  • update - (Defaults to 30 minutes) Used when updating the IotHub Route.
  • read - (Defaults to 5 minutes) Used when retrieving the IotHub Route.
  • delete - (Defaults to 30 minutes) Used when deleting the IotHub Route.

Import

IoTHub Route can be imported using the resourceId, e.g.

terraform import azurerm_iothub_route.route1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Devices/iotHubs/hub1/routes/route1