Azure

Deployment

The usual deployment in Microsoft Azure follows the procedure:

  1. Create resource group
  2. Create hosts.

Even when creating the hosts in parallel, the whole procedure takes a couple of minutes. Testing under those circumstances is faster than creating virtual machines in VMware, but not fast enough.

Consider creating a predefined environment from a template instead. This is significantly faster then creating all resources individually and deleting and re-creating them when needed.

The Azure CLI can do this as well. Given an already defined and configured environment, this can be exported and reimported to re-created the whole resource-group without deleting the resource-group itself.

# Define the export template file.
$ template_file=~/$(date +%Y%m%d%H%M%S)-azure-tmpl-testenvironment.json

# Export an existing resource group into the template file.
$ az group export \
    --name <resource-group> \
    --include-comments \
    --include-parameter-default-value > ${template_file}

# Import the template file and overwrite and existing group
$ az group deployment create \
    --template-file ${template_file} \
    -g <resource-group> \
    --mode complete

In comparison the deployment procedure of the same five notes using the az vm create ... commands (in a wrapper):

$ az group delete -n test-rg-ansible && i=1; for os in sles sles11 cos ubuntu oracle; do i
    wrapper-script azure create \
      --hostname c0${i} \
      -g test-rg-ansible \
      -o ${os} \
      --owner custom_tag \
      --auth ~/.ssh/keys/id_rsa.azure \
      --admin-username azure;
  $((i=i+1));
done

Note:: The wrapper-script is a custom script that just make the usage of the Azure CLI easier and more intuitive in daily use. Essentially the commands used for deployment are the same.

While the deployment using the json template file takes up to 90 seconds (300 seconds on initial creation), the deployment creating indiviual resources with five nodes takes in this example about 22 minutes until completion.

Invalid Parameter: osDisk.managedDisk.ID

Source

While playing with the template deployment I quickly ran into the error blow:

$ az group deployment create --template-file tmpl.json -g me-rg-test
Deployment failed. Correlation ID: 99ae8f5c-1f18-4e8a-aad7-c61a0dc23989. {
  "error": {
    "code": "InvalidParameter",
    "target": "osDisk.managedDisk.id",
    "message": "Parameter 'osDisk.managedDisk.id' is not allowed."
  }
}

The solution is to remove the uniq ID within the json template file:

"managedDisk": {
+ "storageAccountType": "Standard_LRS"
- "storageAccountType": "Premium_LRS",
- "id": "[parameters('virtualMachines_HCM200_id')]"
},

Search all VM images

Source

az vm image list --all -f Centos

Calling REST API via CURL

Source

# Create Service principal AZ CLI
az ad sp create-for-rbac --name [APP_NAME] --password [CLIENT_SECRET]

# Request access token
# Required:
# - APP ID
# - PASSWORD
# - TENANT ID
curl \
  -X POST \
  -d 'grant_type=client_credentials&client_id=[APP_ID]&client_secret=[PASSWORD]&resource=https%3A%2F%2Fmanagement.azure.com%2F' \
  https://login.microsoftonline.com/[TENANT_ID]/oauth2/token

# Call Azure REST API
curl \
  -X GET \
  -H "Authorization: Bearer [TOKEN]" \
  -H "Content-Type: application/json" \
  https://management.azure.com/subscriptions/[SUBSCRIPTION_ID]/providers/Microsoft.Web/sites?api-version=2016-08-01

List machine sizes per region

Source

az vm list-skus [--output yaml] --location westeurope