hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.5k stars 4.59k forks source link

Support for IoT Hub device creation #12604

Closed EliiseS closed 2 weeks ago

EliiseS commented 3 years ago

Community Note

Description

Add support for creating a IoT Hub device like in the Azure CLI:

az iot hub device-identity create --device-id myDeviceId --hub-name {Your IoT Hub name}

New or Affected Resource(s)

Potential Terraform Configuration

resource "azurerm_iothub_device" "example" {
  name            = "device_name"
  iothub_name     = azurerm_iothub.example.name
}

References

Work around with the shell_script provider

main.tf
terraform {
  required_providers {
    shell = {
      source  = "scottwinkler/shell"
      version = "1.7.7"
    }
  }
}

provider "shell" {}

resource "shell_script" "register_iot_edge_device" {
  lifecycle_commands {
    create = "$script create"
    read   = "$script read"
    delete = "$script delete"
  }

  environment = {
    iot_hub_name         = var.iot_hub_name
    iot_edge_device_name = "${var.resource_prefix}-edge-device"
    script               = "../../scripts/terraform/register_iot_edge_device.sh"
  }
}
register_iot_edge_device.sh
#!/bin/bash

set -e

create() {
    az iot hub device-identity create --device-id "$IOT_EDGE_DEVICE_NAME" --edge-enabled --hub-name "$IOT_HUB_NAME" --output none
    # shellcheck disable=SC2162
    read
}

read() {
    az iot hub device-identity connection-string show --device-id "$IOT_EDGE_DEVICE_NAME" --hub-name "$IOT_HUB_NAME"
}

delete() {
    az iot hub device-identity delete --device-id "$IOT_EDGE_DEVICE_NAME" --hub-name "$IOT_HUB_NAME"
}

# Check if the function exists (bash specific)
if declare -f "$1" >/dev/null; then
    # call arguments verbatim
    "$@"
else
    # Show a helpful error
    echo "'$1' is not a known function name" >&2
    exit 1
fi
EliiseS commented 3 years ago

This issue is blocked by the https://github.com/Azure/azure-sdk-for-go/issues/8399. The Azure SDK for go does not support IoT devices at this moment.

psmgeelen commented 2 years ago

Any news on this?

MirnaAlaisami commented 1 year ago

Any updates here?

EliiseS commented 1 year ago

@MirnaAlaisami it's still blocked by the https://github.com/Azure/azure-sdk-for-go/issues/8399 issue. So any updates need to come on that ticket before hand.

CornerstoneII commented 11 months ago

It appears it is the same for terraform

sjaatos commented 2 weeks ago

Any news?

EliiseS commented 2 weeks ago

Unfortunately as the the other issue has been closed, we're also unable to implement this.