"az network vnet peering create" results in "BadRequestError: Cannot parse the request."

684 views Asked by At

I am trying to peer two Azure vnets with CLI, therefor I followed the tutorial Connect virtual networks with virtual network peering using the Azure CLI. But the result is always "BadRequestError: Cannot parse the request"

# Get the id for myVirtualNetwork1.
vNet1Id=$(az network vnet show \
   --resource-group myResourceGroup \
   --name myVirtualNetwork1 \
   --query id --out tsv)

# Get the id for myVirtualNetwork2.
vNet2Id=$(az network vnet show \
   --resource-group myResourceGroup \
   --name myVirtualNetwork2 \
   --query id \
   --out tsv)

az network vnet peering create \
   --name myVirtualNetwork1-myVirtualNetwork2 \
   --resource-group myResourceGroup \
   --vnet-name myVirtualNetwork1 \
   --remote-vnet $vNet2Id \
   --allow-vnet-access

--> BadRequestError: Cannot parse the request.

Anyone any idea?

2

There are 2 answers

0
Nancy On

The CLI commands work well on my side. I can reproduce the same error, please check if you have copied the sample exactly on your side.

For example, If you lack the --out tsv in the command, you will get the error.

enter image description here

Update

It is something wrong or bug in the Azure CLI version azure-CLI 2.16.0 because I can reproduce it with cloud shell or upgrade my local CLI version to 2.16.0 but the same commands work well on my local PowerShell or Bash with Azure CLI 2.11.1.

enter image description here

On PowerShell

enter image description here

On WSL

enter image description here

In this case, you could Install the specific version Azure CLI locally. Or you could have a look at the CLI bug report here.

0
user14839708 On

Here is the script I used in Azure CLI:

az group create --name myResourceGroup --location eastus
az network vnet create \
  --name myVirtualNetwork1 \
  --resource-group myResourceGroup \
  --address-prefixes 10.0.0.0/16 \
  --subnet-name Subnet1 \
  --subnet-prefix 10.0.0.0/24
az network vnet create \
  --name myVirtualNetwork2 \
  --resource-group myResourceGroup \
  --address-prefixes 10.1.0.0/16 \
  --subnet-name Subnet1 \
  --subnet-prefix 10.1.0.0/24
# Get the id for myVirtualNetwork1.
vNet1Id=$(az network vnet show \
  --resource-group myResourceGroup \
  --name myVirtualNetwork1 \
  --query id --out tsv)

# Get the id for myVirtualNetwork2.
vNet2Id=$(az network vnet show \
  --resource-group myResourceGroup \
  --name myVirtualNetwork2 \
  --query id \
  --out tsv)
az network vnet peering create \
  --name myVirtualNetwork1-myVirtualNetwork2 \
  --resource-group myResourceGroup \
  --vnet-name myVirtualNetwork1 \
  --remote-vnet $vNet2Id \
  --allow-vnet-access \
  --out tsv

enter image description here