azure-cli: Resource IDs containing spaces can't be consumed by other az commands

I’ve been trying to use a command to list all the Logic App IDs which have an Alert set up for them. To do this, I’m running 2 commands; az resource list, and az resource show. However, since az resource list returns IDs that contain spaces, az resource show will then fail.

Command Name az resource show --ids $(az resource list --resource-type Microsoft.Insights/metricAlerts --query [].id --output tsv) --query properties.scopes

Errors: az resource: error: argument --ids: invalid ResourceId value: 'failed'

To Reproduce:

Create an alert against any Logic App… make sure the Alert Name has a space in it, like ‘logic-app-test-la failed’.

Run the command above.

Expected Behavior

It should really be able to handle the encoding of the spaces so that az resource show can ingest the result of az resource list without having to resort to a Bash script to work round the problem.

Environment Summary

Linux-4.15.0-1075-azure-x86_64-with-debian-stretch-sid
Python 3.6.5

azure-cli 2.2.0 *

Extensions:
interactive 0.4.4

Additional Context

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 1
  • Comments: 23 (8 by maintainers)

Most upvoted comments

How many Azure resources allow a space in the ID, I wonder? Alerts are the only one I’ve come across so far. Feels like they should maybe restrict this to stop the user entering spaces & potentially running across this issue.

This requires the service team to see why the resource id allows spaces in some resources.

If the az resource list XXX command encoded any IDs that contained spaces with a %20 (maybe?) wouldn’t this fix the problem & not break any existing Bash/Powershell scripts?

Yes, this is a solution, and the service team needs to evaluate whether it is breaking change and whether it can be modified~ By the way, if this problem is not easy to solve at the rest API, CLI can consider adding a parameter for customers to encode the space.