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 ...
Like this:
Like Loading...