Azure Classroomnotes 18/May/2023

Optimizing the shell script to create database

  • Script which we have so far
#!/bin/bash
LOCATION='eastus'
RESOURCE_GROUP='fromcli'
SERVER_NAME='qtactivityscriptsrv'
DB_NAME='erpdb'
COMPUTE_MODEL='Provisioned'
EDITION='Basic'
START_IP='0.0.0.0'
END_IP='255.255.255.255'


echo "Creating a azure sql database with following details"
echo "LOCATION ==> ${LOCATION}"
echo "Resource Group  ==> ${RESOURCE_GROUP}"
echo "Server Name ==> ${SERVER_NAME}"
echo "Database Name ==> ${DB_NAME}"

# Create a resource group

az group create --name ${RESOURCE_GROUP} --location ${LOCATION}
echo "Resource group ${RESOURCE_GROUP} created"
# Create a server
az sql server create \
    --name  ${SERVER_NAME} \
    --location ${LOCATION} \
    --resource-group ${RESOURCE_GROUP} \
    --admin-user 'qtdevops' \
    --admin-password 'motherindia@123' \
    --enable-public-network true --identity-type UserAssigned


# Create a firewall rule (openall)
az sql server firewall-rule create \
    --name 'openall' \
    --resource-group ${RESOURCE_GROUP} \
    --server ${SERVER_NAME} \
    --start-ip-address ${START_IP} \
    --end-ip-address ${END_IP}

az sql db create \
    --name ${DB_NAME} \
    --resource-group ${RESOURCE_GROUP} \
    --server ${SERVER_NAME} \
    --compute-model ${COMPUTE_MODEL} \
    --edition ${EDITION} \
    --sample-name 'AdventureWorksLT'
  • Bash cheat sheet Refer Here
  • Refer Here for the changes done to the script to allow arguments and default values if arguments are not passed
  • Lets not create resources if they exist for that we need to deal with conditions and to parse the json results we need to use jmes path Refer Here
  • Refer Here for the changes done to create resource group and server when they do not exist, try applying same changes for firewall and database

Exercises

  1. Create a free tier eligible mysql flexible server from cli
  2. Create a dynamo db with mongo db api using cli

Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Social Network Widget by Acurax Small Business Website Designers

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube