skip to Main Content

I am trying to automate setting up of IoT Hub. But I am not able to find any code related to creating a device in the IoT Hub. I found the below command:

resource “azurerm_iothub_device” “example” {
    name = “device_name” iothub_name = azurerm_iothub.iothub12.name
}

But it does not seem to be valid.
I have installed the extensions azure IoT Hub and IoT Device Workbench.

How can I do it?

2

Answers


  1. According to EliiseS, as of now, support for IoT Hub device creation using Terraform is not available.

    Login or Signup to reply.
  2. A workaround I use is to use a local provisioner. I use it in my iothub resource for creation. The downside is that it only works on resource creation (or deletion) – so if devices need to be updated at a later stage without recreating the IoT hub you would need to create a new resource with said provisioner.
    My provisioner:

    provisioner "local-exec" {
          command = "${path.module}/create-iot-device.sh ${azurerm_iothub.<your-resource-name>.name}" 
    }
    

    And the create-iot-device.sh

    #!/bin/bash
    az iot hub device-identity create --device-id dev-1 --hub-name $1
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search