Skip to content

Instantly share code, notes, and snippets.

@ArcherN9
Created July 17, 2019 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ArcherN9/60b2dd5f2edfac593c262e7b38710beb to your computer and use it in GitHub Desktop.
Save ArcherN9/60b2dd5f2edfac593c262e7b38710beb to your computer and use it in GitHub Desktop.
# This script file handles the creation and deployment of a new Azure App Service web app.
echo "" # Blank space for formatting
echo "This script will attempt to create a new Azure App Service WebApp and return the configuration created"
echo "" # Blank space for formatting
echo "Please enter the name of the Web Application (name entered will form a unique FQDN ex: mysampleapp.azurewebsites.net): "
# Accept an application name. Prompt if not entered correctly.
while [ ${#applicationName} -eq 0 ]
do
read applicationName
# Perform a basic check - if user did not enter any input, ask again.
if [ ${#applicationName} -eq 0 ]; then
echo "Did not receive a valid input. Please try again."
fi
done
echo "" # Blank space for formatting
echo "Please wait. Fetching available App Service plans for your subscription."
echo "" # Blank space for formatting
# Declare an array to store the App Service plan names
declare -a appServicePlanNames
# This service is executed to be displayed to the user
az appservice plan list --query "[].{planName:name,tier:sku.tier, size:sku.size, location:location, status:status}" -o table
# This service is executed to store data directly to an Array. This is done so that a user can select an index number to select a plan on the succeeding prompt
appServicePlanNames=(`az appservice plan list --query "[].{planName:name}" -o tsv`)
echo "" # Blank space for formatting
# Ask the user to enter an index number to select a plan from the list | No checks here, entries should be correct.
echo "Please enter an index number to select a plan. (Starts with 0):"
read planIndexNumber
# Go ahead and create the WebApp
echo "Creating a WebApp. Please wait."
az webapp create \
--name ${applicationName} \
--plan ${appServicePlanNames[planIndexNumber]} \
# Ensure Resource group are stored as environment variable on the system. I do this because I always deploy my resources within the same resource group
--resource $AZURE_GROUP \
# I've added a couple of users and their email IDs as environment variables since I use them frequently.
--tags CreatedBy="${AZURE_ME}" Project=${AZURE_PROJECT} StartDate="`date`" ProductlineLeader="${AZURE_USER_VENKAT}" \
-o jsonc
echo "" # Blank space for formatting
echo "" # Blank space for formatting
echo "A web app has been created successfully. Creation response is above."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment