Building the Apache and MySQL images using Packer and Ansible provisioners
We will now use Packer to create the Apache and MySQL images. Before defining the Packer configuration, we have a few prerequisites to allow Packer to build custom images.
Prerequisites
We would need to create a service principal for Packer to interact with Azure and build the image.
First, log in using the Azure CLI to your Azure account using the following command:
$ az login
Now, set the subscription to the subscription id we got in response to az login
using the following command:
$ az account set --subscription="<SUBSCRIPTION_ID>"
Then create the service principal with contributor access using the following command:
$ az ad sp create-for-rbac --role="Contributor" \ --scopes="/subscriptions/<SUBSCRIPTION_ID>"Creating ‘Contributor' role assignment under scope ‘/subscriptions/<SUBSCRIPTION_ID>'  Retrying...