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

az keyvault network-rule add --subnet {subnet id here} ..{additional params}... not working

Open jklaus opened this issue 2 years ago • 4 comments

Describe the bug

When I try to pass the subnet ID in for the --subnet param it is throwing indicating that it doesn't see it as valid input. Perhaps there is a max length I am exceeding?

subnetId=$(az network vnet subnet show --resource-group $vnetResoureGroup --vnet-name $vnet --name $subnet --query "id" -o tsv); az keyvault network-rule add --name $keyvault --resource-group $kvResourceGroup --subnet $subnetId Output: incorrect usage: [--subnet ID | --subnet NAME --vnet-name NAME]

Note: I have tried various output forms and even just manually executed the same command withe the subnet ID surrounded by quotes and without, with the initial '/' and without.

The same approach works fine in powershell: $vnet = Get-AzVirtualNetwork -Name $VnetName -ResourceGroupName $VnetResourceGroup $subnet = Get-AzVirtualNetworkSubnetConfig -Name $subnetName -VirtualNetwork $vnet Add-AzKeyVaultNetworkRule -SubscriptionId $Subscription -ResourceGroupName $KvResourceGroup -VaultName $KeyVault -VirtualNetworkResourceId $subnet.Id -PassThru

Related command

subnetId=$(az network vnet subnet show --resource-group $vnetResoureGroup --vnet-name $vnet --name $subnet --query "id" -o tsv); az keyvault network-rule add --name $keyvault --resource-group $kvResourceGroup --subnet $subnetId

Errors

incorrect usage: [--subnet ID | --subnet NAME --vnet-name NAME]

Issue script & Debug output

az_command_data_logger: command args: keyvault network-rule add --debug --name {} --resource-group {} --subnet {} cli.knack.cli: Event: CommandInvoker.OnPreArgumentLoad [<function register_global_subscription_argument..add_subscription_parameter at 0x000002127250F600>] cli.knack.cli: Event: CommandInvoker.OnPostArgumentLoad [] cli.knack.cli: Event: CommandInvoker.OnPostCommandTableCreate [<function register_ids_argument..add_ids_arguments at 0x000002127254D4E0>, <function register_cache_arguments..add_cache_arguments at 0x000002127254D620>] cli.knack.cli: Event: CommandInvoker.OnCommandTableLoaded [] cli.knack.cli: Event: CommandInvoker.OnPreParseArgs [] cli.knack.cli: Event: CommandInvoker.OnPostParseArgs [<function OutputProducer.handle_output_argument at 0x0000021270AB6200>, <function CLIQuery.handle_query_parameter at 0x0000021270AE3D80>, <function register_ids_argument..parse_ids_arguments at 0x000002127254D580>] cli.azure.cli.core.azclierror: Traceback (most recent call last): File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 233, in invoke File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/init.py", line 652, in execute File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/invocation.py", line 113, in _validation File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/init.py", line 894, in _validate_arg_level File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/keyvault/_validators.py", line 543, in validate_subnet knack.util.CLIError: incorrect usage: [--subnet ID | --subnet NAME --vnet-name NAME]

cli.azure.cli.core.azclierror: incorrect usage: [--subnet ID | --subnet NAME --vnet-name NAME] az_command_data_logger: incorrect usage: [--subnet ID | --subnet NAME --vnet-name NAME] cli.knack.cli: Event: Cli.PostExecute [<function AzCliLogging.deinit_cmd_metadata_logging at 0x0000021272503240>]

Expected behavior

Expected --subnet to recognize the subnet ID as a subnet ID and function as expected

Environment Summary

$ az --version azure-cli 2.59.0 *

core 2.59.0 * telemetry 1.1.0

Dependencies: msal 1.27.0 azure-mgmt-resource 23.1.0b2

Python location 'C:\Program Files\Microsoft SDKs\Azure\CLI2\python.exe' Extensions directory 'C:\Users\a525949.azure\cliextensions'

Python (Windows) 3.11.8 (tags/v3.11.8:db85d51, Feb 6 2024, 22:03:32) [MSC v.1937 64 bit (AMD64)]

Legal docs and information: aka.ms/AzureCliLegal

Additional context

No response

jklaus avatar Jun 07 '24 20:06 jklaus

Hi @jklaus,

2.59.0 is not the latest Azure CLI(2.61.0).

If you haven't already attempted to do so, please upgrade to the latest Azure CLI version by following https://learn.microsoft.com/en-us/cli/azure/update-azure-cli.

Thank you for opening this issue, we will look into it.

yonzhan avatar Jun 07 '24 20:06 yonzhan

Hi @jklaus,

2.59.0 is not the latest Azure CLI(2.61.0).

If you haven't already attempted to do so, please upgrade to the latest Azure CLI version by following https://learn.microsoft.com/en-us/cli/azure/update-azure-cli.

I was seeing the same on our build agents which have the latest. I also just upgraded my local and I am still seeing the same outcome.

$ az --version azure-cli 2.61.0

core 2.61.0 telemetry 1.1.0

Dependencies: msal 1.28.0 azure-mgmt-resource 23.1.1

Python location 'C:\Program Files\Microsoft SDKs\Azure\CLI2\python.exe' Extensions directory 'C:\Users\a525949.azure\cliextensions'

Python (Windows) 3.11.8 (tags/v3.11.8:db85d51, Feb 6 2024, 22:03:32) [MSC v.1937 64 bit (AMD64)]

Legal docs and information: aka.ms/AzureCliLegal

Your CLI is up-to-date.

jklaus avatar Jun 07 '24 20:06 jklaus

I modified the query for the subnet ID, using jq to handle the parsing now, and it seems to be working fine. Looking at the output the subnet IDs look the same and I'm still running the same az version. I am a bit perplexed as to why this is working, perhaps something changed on the backend?

jklaus avatar Jun 11 '24 12:06 jklaus