0

I'm trying to create a postgresql database on azure with azure-cli. I set my default location with az configure --defaults location=WestEurope, then I created a resourcegroup, a vnet and a subnet. Now I want to create a flexible server for postgresql with

az postgres flexible-server create --name $SERVERNAME --vnet $VNET --subnet $DBSUBNET
--admin-user $DB_USER --admin-password $DB_PASSWORD --sku-name Standard_B1ms --tier Burstable --storage-size 1024  --tags "Billing=test" --version 13 --database-name $DB_NAME

but I get this error and the server is not created: The location of Vnet should be same as the location of the server.

My Vnet is obviously located in WestEurope, given my default location set before, and I can't understand how the location of any resource I create could be different from my default location. I even tried to add --location WestEurope to the command, but it produced the same result.

Thom A
  • 88,727
  • 11
  • 45
  • 75
J.M. Kenny
  • 384
  • 4
  • 11

1 Answers1

0

I tried to set the default location as West Europe through AZ CLI in Azure Cloud Shell:

az configure --defaults location=westeurope

To create the PostgreSQL Server and database in the specified default location:

    az postgres flexible-server create --resource-group HariTestRG \
      --name demoserver1205 --admin-user <username> --admin-password <your-password>  \
      --sku-name Standard_B1ms --tier Burstable --storage-size 1024 \
      --tags "Billing=test" --version 13 \
      --vnet myVnet --subnet mySubnet --database-name demopsqldb01 \

Result:

reproazdefaultlocnrescreation

defaultlocationresourcescreation

Private DNS Zone is created at the global level automatically by Azure while creating the Postgres SQL Server and the Virtual Network.

Note:

  • After executing the default location command, you need to execute the remaining CLI commands without any error.
  • If you got the error in between the execution of any other commands, then execute the default location config command again.
  • Without interactive activity, cloud shell time out after 20 minutes and it runs on a temporary host provided on a per-session basis.

Updated Answer:

Here I created the VNet and Subnet in the resource group. Created the PostgreSQL Server and database with the existing VNet and Subnet through AZ CLI (using the above CLI Cmdlets - worked successfully):

Result:

deploypostgresqlserverexistingvnetsubnet

  • Thanks for your answer. As I mentionned in my question, I created the virtual network prior to creating the flexible server. When I do it as you did, passing a non existing vnet name, it works and create an new vnet and subnet. But I should be able to use an existing vnet as long as the subnet provided is dedicated to the flexible server. – J.M. Kenny Mar 25 '22 at 16:43