Azure / Azure/iotedgedev

Add support for DPS

Open
#487 2 comments 0 reactions 3 assignees Claimed by @EliiseS View on GitHub
feature InBacklog one week hack priority:high
Dominant language
Python
Stars
166
Forks
76
PR merge metrics
No merged PRs in 30d

Description

In our project we're using [DPS](https://docs.microsoft.com/en-us/azure/iot-dps/?view=iotedge-2020-11) to provison our edge devices. Right now we have a mixed solution of using `iotedgedev build --push` and `az iot edge deployment create` for our deployments. This works when you don't set the `DEVICE_CONNECTION_STRING` in the `.env` file.

Would it be possible to add DPS support for `iotedge deploy` and do you have plans to support it?

**Example of a DPS provisioned device connection string:**
`HostName=soak-iot-hub.azure-devices.net;DeviceId=soak-edge-device;x509=true`
**Example of a regular device connection string:**
`HostName=iotedgedev-iothub-d278b7.azure-devices.net;DeviceId=iotedgedev-edgedevice;SharedAccessKey=NfS9UhVSljRM4=`

### Steps to reproduce issue:

1. Provision and set up IoTEdge with a Virtual Machine by following the QuickStart guide
2. In the generated `.env` replace `DEVICE_CONNECTION_STRING` value with `"HostName=soak-iot-hub.azure-devices.net;DeviceId=;x509=true"` where the `` is the same as the `DeviceId` from your original `DEVICE_CONNECTION_STRING`
3. Retry: `iotedgedev solution deploy`

### Current solution

The `DEVICE_CONNECTION_STRING` value is only required for extracting the `DeviceId` for all commands in the `iotedgedev` CLI, with the exception of the commands that use the simulator (`iotedgehubdev`).

The `.env` template also already contains `EDGE_DEVICE_ID` value, which id currently only used to retrieve the device connection string using `Azure CLI`:
![image](https://user-images.githubusercontent.com/12761692/167104230-4f693a4b-c42d-4d2f-bdc9-3e7f0d287fcd.png)
![image](https://user-images.githubusercontent.com/12761692/167104266-2244cbbe-6607-40a9-9557-1856578aa6a8.png)

There are a number of commands that check that the `DEVICE_CONNECTION_STRING` is set in commands that only use the `DeviceId`:
![image](https://user-images.githubusercontent.com/12761692/167104965-a30b9631-8ba1-4235-bd87-b315bf80053a.png)

When using a DPS device connection string, the device connection string is set to empty, failing the above validations:
![image](https://user-images.githubusercontent.com/12761692/167105188-7b791987-f497-461e-92d3-d1fd8a1d3514.png)

### Implementation suggestion

- Set the `DeviceId` from either `DEVICE_CONNECTION_STRING` or `EDGE_DEVICE_ID`, favoring one over the other when both are set or failing validation if both are set to a different `DeviceIds`
- Change validation for commands that only require `DeviceId` to only verify `DeviceId` is set
- Change `iotedgedev solution deploy` validation #576
- When the `DEVICE_CONNECTION_STRING` is a DPS connection string, still extract and set the `DeviceId` #576

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.