|
| 1 | +--- |
| 2 | +title: Quickstart - Create a Windows virtual machine scale set with Bicep |
| 3 | +description: Learn how to quickly create a Windows virtual machine scale with Bicep to deploy a sample app and configures autoscale rules |
| 4 | +author: schaffererin |
| 5 | +ms.author: v-eschaffer |
| 6 | +ms.topic: quickstart |
| 7 | +ms.service: virtual-machine-scale-sets |
| 8 | +ms.collection: windows |
| 9 | +ms.date: 06/28/2022 |
| 10 | +ms.custom: subject-armqs, devx-track-azurepowershell, mode-arm |
| 11 | +--- |
| 12 | + |
| 13 | +# Quickstart: Create a Windows virtual machine scale set with Bicep |
| 14 | + |
| 15 | +**Applies to:** :heavy_check_mark: Windows VMs :heavy_check_mark: Uniform scale sets |
| 16 | + |
| 17 | +A virtual machine scale set allows you to deploy and manage a set of auto-scaling virtual machines. You can scale the number of VMs in the virtual machine scale set manually, or define rules to autoscale based on resource usage like CPU, memory demand, or network traffic. An Azure load balancer then distributes traffic to the VM instances in the virtual machine scale set. In this quickstart, you create a virtual machine scale set and deploy a sample application with Bicep. |
| 18 | + |
| 19 | +[!INCLUDE [About Bicep](../../includes/resource-manager-quickstart-bicep-introduction.md)] |
| 20 | + |
| 21 | +## Prerequisites |
| 22 | + |
| 23 | +If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin. |
| 24 | + |
| 25 | +## Review the Bicep file |
| 26 | + |
| 27 | +The Bicep file used in this quickstart is from [Azure Quickstart Templates](https://azure.microsoft.com/resources/templates/vmss-windows-webapp-dsc-autoscale/). |
| 28 | + |
| 29 | +:::code language="bicep" source="~/quickstart-templates/demos/vmss-windows-webapp-dsc-autoscale/main.bicep"::: |
| 30 | + |
| 31 | +The following resources are defined in the Bicep file: |
| 32 | + |
| 33 | +- [**Microsoft.Network/virtualNetworks**](/azure/templates/microsoft.network/virtualnetworks) |
| 34 | +- [**Microsoft.Network/publicIPAddresses**](/azure/templates/microsoft.network/publicipaddresses) |
| 35 | +- [**Microsoft.Network/loadBalancers**](/azure/templates/microsoft.network/loadbalancers) |
| 36 | +- [**Microsoft.Compute/virtualMachineScaleSets**](/azure/templates/microsoft.compute/virtualmachinescalesets) |
| 37 | +- [**Microsoft.Insights/autoscaleSettings**](/azure/templates/microsoft.insights/autoscalesettings) |
| 38 | + |
| 39 | +### Define a scale set |
| 40 | + |
| 41 | +To create a virtual machine scale set with a Bicep file, you define the appropriate resources. The core parts of the virtual machine scale set resource type are: |
| 42 | + |
| 43 | +| Property | Description of property | Example template value | |
| 44 | +|------------------------------|----------------------------------------------------------|-------------------------------------------| |
| 45 | +| type | Azure resource type to create | Microsoft.Compute/virtualMachineScaleSets | |
| 46 | +| name | The scale set name | myScaleSet | |
| 47 | +| location | The location to create the scale set | East US | |
| 48 | +| sku.name | The VM size for each scale set instance | Standard_A1 | |
| 49 | +| sku.capacity | The number of VM instances to initially create | 2 | |
| 50 | +| upgradePolicy.mode | VM instance upgrade mode when changes occur | Automatic | |
| 51 | +| imageReference | The platform or custom image to use for the VM instances | Microsoft Windows Server 2016 Datacenter | |
| 52 | +| osProfile.computerNamePrefix | The name prefix for each VM instance | myvmss | |
| 53 | +| osProfile.adminUsername | The username for each VM instance | azureuser | |
| 54 | +| osProfile.adminPassword | The password for each VM instance | P@ssw0rd! | |
| 55 | + |
| 56 | +To customize a virtual machine scale set Bicep file, you can change the VM size or initial capacity. Another option is to use a different platform or a custom image. |
| 57 | + |
| 58 | +### Add a sample application |
| 59 | + |
| 60 | +To test your virtual machine scale set, install a basic web application. When you deploy a virtual machine scale set, VM extensions can provide post-deployment configuration and automation tasks, such as installing an app. Scripts can be downloaded from [GitHub](https://azure.microsoft.com/resources/templates/vmss-windows-webapp-dsc-autoscale/) or provided to the Azure portal at extension run-time. To apply an extension to your virtual machine scale set, add the `extensionProfile` section to the resource example above. The extension profile typically defines the following properties: |
| 61 | + |
| 62 | +- Extension type |
| 63 | +- Extension publisher |
| 64 | +- Extension version |
| 65 | +- Location of configuration or install scripts |
| 66 | +- Commands to execute on the VM instances |
| 67 | + |
| 68 | +The Bicep file uses the PowerShell DSC extension to install an ASP.NET MVC app that runs in IIS. |
| 69 | + |
| 70 | +An install script is downloaded from GitHub, as defined in `url`. The extension then runs `InstallIIS` from the `IISInstall.ps1` script, as defined in `function` and `Script`. The ASP.NET app itself is provided as a Web Deploy package, which is also downloaded from GitHub, as defined in `WebDeployPackagePath`: |
| 71 | + |
| 72 | +## Deploy the Bicep file |
| 73 | + |
| 74 | +1. Save the Bicep file as `main.bicep` to your local computer. |
| 75 | +1. Deploy the Bicep file using either Azure CLI or Azure PowerShell. |
| 76 | + |
| 77 | + # [CLI](#tab/CLI) |
| 78 | + |
| 79 | + ```azurecli |
| 80 | + az group create --name exampleRG --location eastus |
| 81 | + az deployment group create --resource-group exampleRG --template-file main.bicep --parameters vmssName=<vmss-name> |
| 82 | + ``` |
| 83 | +
|
| 84 | + # [PowerShell](#tab/PowerShell) |
| 85 | +
|
| 86 | + ```azurepowershell |
| 87 | + New-AzResourceGroup -Name exampleRG -Location eastus |
| 88 | + New-AzResourceGroupDeployment -ResourceGroupName exampleRG -TemplateFile ./main.bicep -vmssName "<vmss-name>" |
| 89 | + ``` |
| 90 | +
|
| 91 | + --- |
| 92 | +
|
| 93 | + Replace *\<vmss-name\>* with the name of the virtual machine scale set. It must be 3-61 characters in length and globally unique across Azure. You'll be prompted to enter `adminPassword`. |
| 94 | +
|
| 95 | + > [!NOTE] |
| 96 | + > When the deployment finishes, you should see a message indicating the deployment succeeded. It can take 10-15 minutes for the virtual machine scale set to be created and apply the extension to configure the app. |
| 97 | +
|
| 98 | +## Validate the deployment |
| 99 | +
|
| 100 | +To see your virtual machine scale set in action, access the sample web application in a web browser. Obtain the public IP address of your load balancer using Azure CLI or Azure PowerShell. |
| 101 | +
|
| 102 | +# [CLI](#tab/CLI) |
| 103 | +
|
| 104 | +```azurecli-interactive |
| 105 | +az network public-ip show --resource-group exampleRG |
| 106 | +``` |
| 107 | + |
| 108 | +# [PowerShell](#tab/PowerShell) |
| 109 | + |
| 110 | +```azurepowershell-interactive |
| 111 | +Get-AzPublicIpAddress -ResourceGroupName exampleRG | Select IpAddress |
| 112 | +``` |
| 113 | + |
| 114 | +--- |
| 115 | + |
| 116 | +Enter the public IP address of the load balancer in to a web browser in the format *http:\//publicIpAddress/MyApp*. The load balancer distributes traffic to one of your VM instances, as shown in the following example: |
| 117 | + |
| 118 | + |
| 119 | + |
| 120 | +## Clean up resources |
| 121 | + |
| 122 | +When no longer needed, use the Azure portal, Azure CLI, or Azure PowerShell to remove the resource group and its resources. |
| 123 | + |
| 124 | +# [CLI](#tab/CLI) |
| 125 | + |
| 126 | +```azurecli-interactive |
| 127 | +az group delete --name exampleRG |
| 128 | +``` |
| 129 | + |
| 130 | +# [PowerShell](#tab/PowerShell) |
| 131 | + |
| 132 | +```azurepowershell-interactive |
| 133 | +Remove-AzResourceGroup -Name exampleRG |
| 134 | +``` |
| 135 | + |
| 136 | +--- |
| 137 | + |
| 138 | +## Next steps |
| 139 | + |
| 140 | +In this quickstart, you created a Windows virtual machine scale set with a Bicep file and used the PowerShell DSC extension to install a basic ASP.NET app on the VM instances. To learn more, continue to the tutorial for how to create and manage Azure virtual machine scale sets. |
| 141 | + |
| 142 | +> [!div class="nextstepaction"] |
| 143 | +> [Create and manage Azure virtual machine scale sets](tutorial-create-and-manage-powershell.md) |
0 commit comments