Azure CLI Basics
Authenticating
Before executing scripts, you must be authenticated. In a script this can be done by using:
az login
This will open the browser where you can authenticate. After authantication this line is not needed for the time the session is valid.
Setting subscriptionID
To have the correct resources provisionied, you must define the subscriptionID to the session. It will take the default if not provided.
az account set --subscription "[subscriptionID]"
Resources
Resourcegroup
Each resource in Azure requires a resourcegroup. A resourcegroup is a container that contains resources. Creating a resourcegroup requires:
- Location
- Name
$location = "westeurope"
$resourceGroup = "tst-azure-web-apps"
az group create -l $location -n $resourceGroup
Webapps
Webapps are the most commonly used resources in Azure. It's the buildingblock to run webapps. To create a webapp , you'll need:
- Serviceplan
- Resourcegroup
- Name
Because you'll need a serviceplan to create a webapp, you must create a serviceplan first.
A serviceplan requires:
- Location
- Name
- Tier/SKU
Creating a serviceplan and webapp can be combined to minimize the amount of required code:
$appName = "calculator"
$location = "westeurope"
$resourceGroup = "tst-azure-web-apps"
$webapp = "{0}-{1}" -f $resourceGroup, $appName
$servicePlan = "{0}-plan" -f $webapp
$sku = "S1"
az appservice plan create -g $resourceGroup -n $servicePlan --location $location --sku $sku
az webapp create -g $resourceGroup -p $servicePlan -n $webapp
Additional configurations
When creating a webapp, it's important to configure the webapp as clean and secure as possible:
- Disable FTP access
- HTTPS only
- Disable Session affinity cookie
az webapp update -g $resourceGroup -n $webapp --https-only true --client-affinity-enabled false
az webapp config set --ftps-state Disabled -g $resourceGroup -n $webapp