az configure doesn't check the validity of the arguments/values before configuring
az feedbackauto-generates most of the information requested below, as of CLI version 2.0.62
Describe the bug CLI tells me rg isn't avail after I'd already explicitly configured it

To Reproduce
-
used az configure to set global rg

-
created appservice plan but ended up failing because rg isn't actually avail

Expected behavior If the rg to be set at az configure isn't actually a valid rg, the tool should not plainly accept the value. It should first check the validity of the resource and return an error if it's not a valid rg. Else it would give a false impression that the configure has been successful and that the defaulted values are readily avail for use -- which is not in this case
Environment summary CLI 2.10.1 on windows
Additional context
Another follow up Q... Is there a way for folks to clear/delete any defaulted values in the CLI without going to the file and edit it? I must be missing something but can't seem to find it either in doc or via intool help

add to S175
Hi @chenlomis, for the original post, this behavior is expected. Imagine these scenarios:
# The user sets the default resource group first
> az configure --default group=rg1
# Create the resource group
> az group create -l westus -n rg1
# Use the configured default resource group
> az vm list
If we enforce the validation in az configure, this scenario will fail at az configure because of the non-existing resource group.
Or
# The user sets the default resource group first
> az configure --default group=rg1
# Switch the active subscription
> az account set --subscription <subscription_id>
# Use the configured default resource group
> az vm list
There are 2 cases:
- The old subscription has the resource group, but the new subscription doesn't. In this case, after switching the subscription, the configured default resource group becomes invalid (no way for CLI to detect that).
- The old subscription doesn't have the resource group, but the new subscription does. The
az configurecommand will fail at the beginning.
That's why the validation logic is not included in az configure, but is deferred to when an ARM command is actually executed.
For the second question, moving to a separate issue https://github.com/Azure/azure-cli/issues/14853.
@jiasli Thanks! I presumed that we'd be checking for validity based on the existing env/context. So not sure I entirely understand your 2nd examples
- The rg does become invalid if the new sub doesn't have that rg, but that is a logic that comes later(?) If anything, there should be an error thrown when the user tries to execute az vm list that'd default to rg1 because it's no longer valid
The error could be something like "can't list vm in rg1 because you changed subscription"
So I don't see any fault here if we were to validate the validity of rg1 during az config. It's just that once the condition changes, we will then notify people?
- This make sense and should be expected no?
The error could be something like "can't list vm in rg1 because you changed subscription".
This is difficult to achieve because the configuration is not bound to a subscription. In other words, all configurations apply to all subscriptions. So, it is difficult for Azure CLI to detect if the default resource group becomes invalid due to
- subscription change, or
- that the resource group is simply deleted by the user.
We can of course implement this but it requires big development efforts. The current config file is in ini format thus it is difficult to set complex properties:
[defaults]
group = rg1
If we switch to JSON, we can make the default resource group bound to a certain subscription, like
{
"subscriptions": {
"0b1f6471-1bf0-4dda-aec3-cb9272f09590": {
"defaults": {
"group": "rg1",
"location": "westus"
}
},
"bf664f93-b001-4dc8-a597-148bbc173cfd": {
"defaults": {
"group": "network-infra",
"location": "eastus"
}
}
}
}