-
-
Save denishpatel/8d401ce3a507d59f32c86368fe6ee66d to your computer and use it in GitHub Desktop.
Deployment script for Azure PostgreSQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#These are the settings for deployment. The only thing you need to be sure you change is | |
#the resource group, as that will be the name you will use to destroy things later | |
USER=admin_$RANDOM #set this to whatever you like but it's not something that should be easy | |
PASS=$(uuidgen) #Again - whatever you like but keep it safe! Better to make it random | |
LOCATION=westus | |
SERVERNAME=northwind-$RANDOM #this has to be unique across azure | |
#resource group | |
echo "Specify a Resource Group:" | |
read RG | |
echo "Guessing your external IP address from ipinfo.io" | |
IP=$(curl -s ipinfo.io/ip) | |
echo "Your IP is $IP" | |
#The sku-name parameter value follows the convention {pricing tier}_{compute generation}_{vCores} as in the examples below: | |
# --sku-name B_Gen4_2 maps to Basic, Gen 4, and 2 vCores. | |
# --sku-name GP_Gen5_32 maps to General Purpose, Gen 5, and 32 vCores. | |
# --sku-name MO_Gen5_2 maps to Memory Optimized, Gen 5, and 2 vCores. | |
SKU=B_Gen4_1 #this is the cheapest one | |
# Create a resource group if you need it. | |
az group create --location $LOCATION --name $RG | |
echo "Spinning up PostgreSQL $SERVERNAME in group $RG Admin is $USER" | |
# Create the PostgreSQL service | |
az postgres server create --resource-group $RG \ | |
--name $SERVERNAME --location $LOCATION --admin-user $USER \ | |
--admin-password $PASS --sku-name $SKU --version 10.0 | |
# Open up the firewall so we can access | |
echo "Popping a hole in firewall for IP address $IP (that's you)" | |
az postgres server firewall-rule create --resource-group $RG \ | |
--server $SERVERNAME --name AllowMyIP \ | |
--start-ip-address $IP --end-ip-address $IP | |
echo "Your connection string is postgres://$USER@$SERVERNAME:$PASS@$SERVERNAME.postgres.database.azure.com/postgres" | |
echo "Creating the Northwind database..." | |
psql "postgres://$USER%40$SERVERNAME:$PASS@$SERVERNAME.postgres.database.azure.com/postgres" -c "CREATE DATABASE northwind;" | |
echo "Connecting... and loading up Northwind..." | |
psql "postgres://$USER%40$SERVERNAME:$PASS@$SERVERNAME.postgres.database.azure.com/northwind" -f northwind.sql | |
echo "....." | |
echo "You can now connect to the server by entering this command: " | |
echo "psql postgres://$USER%40$SERVERNAME:$PASS@$SERVERNAME.postgres.database.azure.com/northwind" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment