Tutorial: Deploy virtual machine extensions with ARM templates
Article
Learn how to use Azure virtual machine extensions to perform post-deployment configuration and automation tasks on Azure VMs. Many different VM extensions are available for use with Azure VMs. In this tutorial, you deploy a Custom Script extension from an Azure Resource Manager template (ARM template) to run a PowerShell script on a Windows VM. The script installs Web Server on the VM.
To increase security, use a generated password for the virtual machine administrator account. You can use Azure Cloud Shell to run the following command in PowerShell or Bash:
openssl rand -base64 32
To learn more, run man openssl rand to open the manual page.
You can use an inline PowerShell script or a script file. This tutorial shows how to use a script file. A PowerShell script with the following content is shared from GitHub:
If you choose to publish the file to your own location, update the fileUri element in the template later in the tutorial.
Open a quickstart template
Azure Quickstart Templates is a repository for ARM templates. Instead of creating a template from scratch, you can find a sample template and customize it. The template used in this tutorial is called Deploy a simple Windows VM.
For more information about this resource definition, see the extension reference. The following are some important elements:
name: Because the extension resource is a child resource of the virtual machine object, the name must have the virtual machine name prefix. See Set name and type for child resources.
dependsOn: Create the extension resource after you've created the virtual machine.
fileUris: The locations where the script files are stored. If you choose not to use the provided location, you need to update the values.
commandToExecute: This command invokes the script.
To use an inline script, remove fileUris, and update commandToExecute to:
Paste the IP address into a Web browser. The default Internet Information Services (IIS) welcome page opens:
Clean up resources
When you no longer need the Azure resources you deployed, clean them up by deleting the resource group.
In the Azure portal, in the left pane, select Resource group.
In the Filter by name box, enter the resource group name.
Select the resource group name.
Six resources are displayed in the resource group.
In the top menu, select Delete resource group.
Next steps
In this tutorial, you deployed a virtual machine and a virtual machine extension. The extension installed the IIS web server on the virtual machine. To learn how to use the Azure SQL Database extension to import a BACPAC file, see: