Skip to content

azurermIothubSharedAccessPolicy

Manages an IotHub Shared Access Policy

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 azurermIothubExample = new azurerm.iothub.Iothub(this, "example_1", {
  location: azurermResourceGroupExample.location,
  name: "example",
  resource_group_name: azurermResourceGroupExample.name,
  sku: [
    {
      capacity: "1",
      name: "S1",
    },
  ],
});
/*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 azurermIothubSharedAccessPolicyExample =
  new azurerm.iothubSharedAccessPolicy.IothubSharedAccessPolicy(
    this,
    "example_2",
    {
      iothub_name: azurermIothubExample.name,
      name: "example",
      registry_read: true,
      registry_write: true,
      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.*/
azurermIothubSharedAccessPolicyExample.overrideLogicalId("example");

Argument Reference

The following arguments are supported:

  • name - (Required) Specifies the name of the IotHub Shared Access Policy resource. Changing this forces a new resource to be created.

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

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

  • registryRead - (Optional) Adds registryRead permission to this Shared Access Account. It allows read access to the identity registry.

  • registryWrite - (Optional) Adds registryWrite permission to this Shared Access Account. It allows write access to the identity registry.

-> NOTE When registryWrite is set to true, registryRead must also be set to true. This is a limitation of the Azure REST API

  • serviceConnect - (Optional) Adds serviceConnect permission to this Shared Access Account. It allows sending and receiving on the cloud-side endpoints.

  • deviceConnect - (Optional) Adds deviceConnect permission to this Shared Access Account. It allows sending and receiving on the device-side endpoints.

-> NOTE At least one of registryRead, registryWrite, serviceConnect, deviceConnect permissions must be set to true.

Attributes Reference

The following attributes are exported:

  • id - The ID of the IoTHub Shared Access Policy.

  • primaryKey - The primary key used to create the authentication token.

  • primaryConnectionString - The primary connection string of the Shared Access Policy.

  • secondaryKey - The secondary key used to create the authentication token.

  • secondaryConnectionString - The secondary connection string of the Shared Access Policy.

Timeouts

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

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

Import

IoTHub Shared Access Policies can be imported using the resourceId, e.g.

terraform import azurerm_iothub_shared_access_policy.shared_access_policy1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Devices/iotHubs/hub1/iotHubKeys/shared_access_policy1