Azure Classroomnotes 26/Sep/2023

Azure CLI

Activity1: Create an Azure SQL Database

  • Steps:
    • Create a resource group
    • Create a server
    • Create a database
RG_NAME='activity1'
RG_LOCATION='eastus'
SRV_NAME='qtactivity1'

# add information about what is happening to the user

# Create resource group if it does not exist
az group create --location "$RG_LOCATION" --name "$RG_NAME"

# Create azure sql server if it does not exist
az sql server create \
    --name "$SRV_NAME" \
    --resource-group "$RG_NAME" \
    --location "$RG_LOCATION" \
    --enable-public-network \
    --identity-type 'UserAssigned' \
    --admin-user 'qtdevops' \
    --admin-password 'qtazuredevops@123'


# Create azure sql database if it doesnot exist
az sql db create \
    --resource-group "$RG_NAME" \
    --server "$SRV_NAME" \
    --name 'employees' \
    --capacity '5' \
    --edition 'Basic' \
    --sample-name 'AdventureWorksLT' \
    --tags "env=dev" \
    --yes

  • To convert the activity into reusable script lets learn bash basics and its usage with azure Refer Here and Refer Here for the generic bash cheatsheet
  • Exercise: Try completing the script
#!/bin/bash

# create_resource_group(name, location)
# This function creates a resource group if it doesnot exist
function create_resource_group()
{
    name=$1
    location=$2
    if [ $(az group exists --name $name) = true ]; then 
        echo "resource group $name already exists"
    else
        az group create --name $name --location $location
    fi
}

function create_sql_server()
{
    name=$1
    rg_name=$2
    location=$3
    username=$4
    password=$5

}

function create_sql_database()
{

}

RG_NAME='activity1'
RG_LOCATION='eastus'
create_resource_group "$RG_NAME" "$RG_LOCATION"
create_sql_server . . . . .
create_sql_datbase ...
Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a ReplyCancel reply

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

Please turn AdBlock off
Animated Social Media Icons by Acurax Responsive Web Designing Company

Discover more from Direct DevOps from Quality Thought

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

Continue reading

Exit mobile version
%%footer%%