Azure / Azure/azure-cli

Add "exists" subcommand

Open
#23,451 3 comments 0 reactions 0 assignees View on GitHub
act-codegen-extensibility-squad Auto-Assign customer-reported feature-request Service Attention Synapse
Dominant language
Python
Stars
4.6k
Forks
3.5k
Avg merge
3d 2h
Merged PRs (30d)
60

Description

**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.

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.