Skip to content

az <resource> show has inconsistent exit status #5006

@damienpontifex

Description

@damienpontifex

Following template scripts generated from the Portal's Automation Script section, the CLI script uses checks for existing resources such as

az group show $resourceGroupName 1> /dev/null

if [ $? != 0 ]; then
	echo "Resource group with name" $resourceGroupName "could not be found. Creating new resource group.."
	set -e
	(
		set -x
		az group create --name $resourceGroupName --location $resourceGroupLocation 1> /dev/null
	)
	else
	echo "Using existing resource group..."
fi

az group show and az storage account show both return non-zero when the resource is missing and so the above pattern works. If being consistent across resources throughout my scripts, examples such as az storage share show and az vm show return zero regardless of the resource existing or not. Thus cannot be used to determine missing resources.

The issue is that the 'show' action doesn't always return a non-zero code for missing resources when used on other resource types. For consistency and approachability to new commands, I would thing these would behave the same across resources?

Environment summary

az --version 2.0.21
Python (Darwin) 3.6.3
Installed via homebrew

Metadata

Metadata

Assignees

Labels

ARMaz resource/group/lock/tag/deployment/policy/managementapp/account management-groupResource ManagerquestionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions