Scripted Deployments with Azure CLI and Bash

Length: 00:08:45

Lesson Summary:

Continuing on from our Getting Started lesson, we now take a look at a real-world scenario and script.

In this lesson, we step through an example scenario for deploying infrastructure in Azure, breaking down a script into steps, and looking at a complete script.

This lesson demonstrates how we combine various concepts from this course into a fully functional script.

All commands used if you wish to follow along:

vi scriptDeploy.sh
chmod +x scriptDeploy.sh
./scriptDeploy.sh

scriptDeploy.sh

#!/bin/bash

declare -A project

# Ask for the name of the book
echo -n "Enter the name of the book, and press [ENTER]: "
read projectName

# Create all the resource names based on the book name
project[name]=$projectName
project[rgName]="${projectName}-rg"
project[vnetName]="${projectName}-vnet"

# Storage Accounts cannot be uppercase (or greater than 24 characters)
randString=$(date +%s | sha256sum | base64 | head -c 6)
saTempName="${projectName}store1${randString}"
project[saName]=$(echo $saTempName | awk '{print tolower($0)}')

# Let's display the information we've generated so far
echo "--------------"
echo "We are going to setup some infrastructure using the following values"
echo "Project Name: ${project[name]}"
echo "> RG Name: ${project[rgName]}"
echo "> VNet Name: ${project[vnetName]}"
echo "> Storage Account Name: ${project[saName]}"
echo ""
echo ""

# Let's get started creating the resources
echo "Creating the Resource Group"
az group create -n ${project[rgName]} -l "Australia Southeast"

echo "Creating the Virtual Network"
az network vnet create -n ${project[vnetName]} -g ${project[rgName]}

echo "Creating the Storage Account"
az storage account create -n ${project[saName]} -g ${project[rgName]}


This lesson is only available to Linux Academy members.

Sign Up To View This Lesson
Or Log In

Looking For Team Training?

Learn More