azure-cli icon indicating copy to clipboard operation
azure-cli copied to clipboard

Add "exists" subcommand

Open chlsmith opened this issue 4 years ago • 3 comments

Related command az list/show

Is your feature request related to a problem? Please describe. It's easy to get back information about most Azure resources using list or show, but when those resource don't exist, you get back an error. This breaks automation scripts.

Describe the solution you'd like Along with list/show, add a subcommand for "exists" that will return either a 0 or 1 based upon if the resource exists.

Describe alternatives you've considered I have used things like:

exists=$(az synapse workspace list --resource-group $rg -o tsv --query "[?name=='$workspacename'] | length(@)")

Additional context I realize that the Azure CLI commands are supposed to always be idempotent, so I should be able to just do a "create" on anything and it won't break existing resources. The problem is that most of the time Azure CLI will return an error saying something like "resource already exists". This breaks automation scripts all the time. The cleanest solution, to me, would be to just give us an option for "exists" to get 0/1.

Az Pwsh already kinda does this, as it will return an empty object when you do the Get. This is totally workable, too, if Azure CLI just returned nothing.

chlsmith avatar Aug 05 '22 14:08 chlsmith

route to CXP team

yonzhan avatar Aug 06 '22 00:08 yonzhan

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @wonner, @zesluo.

Issue Details

Related command az list/show

Is your feature request related to a problem? Please describe. It's easy to get back information about most Azure resources using list or show, but when those resource don't exist, you get back an error. This breaks automation scripts.

Describe the solution you'd like Along with list/show, add a subcommand for "exists" that will return either a 0 or 1 based upon if the resource exists.

Describe alternatives you've considered I have used things like:

exists=$(az synapse workspace list --resource-group $rg -o tsv --query "[?name=='$workspacename'] | length(@)")

Additional context I realize that the Azure CLI commands are supposed to always be idempotent, so I should be able to just do a "create" on anything and it won't break existing resources. The problem is that most of the time Azure CLI will return an error saying something like "resource already exists". This breaks automation scripts all the time. The cleanest solution, to me, would be to just give us an option for "exists" to get 0/1.

Az Pwsh already kinda does this, as it will return an empty object when you do the Get. This is totally workable, too, if Azure CLI just returned nothing.

Author: chlsmith
Assignees: -
Labels:

Service Attention, customer-reported, Synapse, feature-request, Auto-Assign

Milestone: -

ghost avatar Aug 06 '22 15:08 ghost

Hi @chlsmith, Thanks for the suggest. I think you can use az synapse workspace check-name instead of exists.

wonner avatar Aug 08 '22 03:08 wonner