Azure / azure-cli

Azure Command-Line Interface
MIT License
3.99k stars 2.96k forks source link

Azure CLI Enrollment Group Update unlinks all IoT Hubs #29002

Closed cboschert1 closed 2 months ago

cboschert1 commented 4 months ago

Describe the bug

When I update the allocation policy using the update enrollment-group command, it unlinks all IoT Hubs from the enrollment group.

Related command

az iot dps enrollment-group update -n -g --enrollment-id --allocation-policy custom --webhook-url --api-version 2021-10-01

Errors

Command succeeds and updates the allocation policy.

Issue script & Debug output

Please message if needed, don't want to have to go through the output and block sensitive info.

Expected behavior

I expect all other settings to stay the same on the enrollment group, and all of the selected linked hubs to remain unchanged. Before the command: image After the command: image

Environment Summary

{ "azure-cli": "2.52.0", "azure-cli-core": "2.52.0", "azure-cli-telemetry": "1.1.0", "extensions": { "azure-devops": "0.26.0", "azure-iot": "0.23.1" } }

Additional context

Am I misunderstanding the update command. I expect an update command to only update the parameters I pass in, leaving everything else unchanged.

azure-client-tools-bot-prd[bot] commented 4 months ago

Hi @cboschert1,

2.52.0 is not the latest Azure CLI(2.61.0).

If you haven't already attempted to do so, please upgrade to the latest Azure CLI version by following https://learn.microsoft.com/en-us/cli/azure/update-azure-cli.

yonzhan commented 4 months ago

Thank you for opening this issue, we will look into it.

microsoft-github-policy-service[bot] commented 4 months ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @Azure/azure-iot-cli-triage.

cboschert1 commented 4 months ago

Hi @cboschert1,

2.52.0 is not the latest Azure CLI(2.61.0).

If you haven't already attempted to do so, please upgrade to the latest Azure CLI version by following https://learn.microsoft.com/en-us/cli/azure/update-azure-cli.

Verified this happens with the latest azure CLI (2.61.0) as well.

vilit1 commented 4 months ago

Hi,

I managed to reproduce your issue and have looked into the code and documentation as to why this occurs. The initial goal was to have the customer re-enter the IoT Hubs they want to connect if they change the allocation policy. This is extremely important for allocation policies such as static, in which exactly one IoT Hub is allowed.

However, I can see this being a pain point, especially if there are multiple IoT Hubs present and the allocation policy is minimally changed (such as updating the webhook url). Thus, I will modify the enrollment update code so that the current IoT Hub list is kept unless a new one is specified via the command.

cboschert1 commented 4 months ago

Thank you for the quick response, I appreciate it and will follow this issue for updates.

In the meantime I did this as a workaround if someone else happens across this. There's probably a better way, but this works for now:

enrollmentGroupInfo=$(az iot dps enrollment-group show -g $RESOURCE_GROUP --dps-name $DPS_NAME --enrollment-id $group)
linkedHubs=$(echo $enrollmentGroupInfo | jq -r '.iotHubs[]' | xargs)
...
az iot dps enrollment-group update -g $RESOURCE_GROUP --dps-name $DPS_NAME --enrollment-id $group --iot-hubs "$linkedHubs" --allocation-policy custom --webhook-url $FUNCTION_URL --api-version 2021-10-01
vilit1 commented 2 months ago

Closing issue since the code has been merged in and released