Redaguoti

Bendrinti naudojant


Add a custom image to an Azure scale set template

Note

This document covers Virtual Machine Scale Sets running in Uniform Orchestration mode. We recommend using Flexible Orchestration for new workloads. For more information, see Orchesration modes for Virtual Machine Scale Sets in Azure.

This article shows how to modify the basic scale set template to deploy from custom image.

Change the template definition

In a previous article we had created a basic scale set template. We will now use that earlier template and modify it to create a template that deploys a scale set from a custom image.

Creating a managed disk image

If you already have a custom managed disk image (a resource of type Microsoft.Compute/images), then you can skip this section.

First, add a sourceImageVhdUri parameter, which is the URI to the generalized blob in Azure Storage that contains the custom image to deploy from.

     },
     "adminPassword": {
       "type": "securestring"
+    },
+    "sourceImageVhdUri": {
+      "type": "string",
+      "metadata": {
+        "description": "The source of the generalized blob containing the custom image"
+      }
     }
   },
   "variables": {},

Next, add a resource of type Microsoft.Compute/images, which is the managed disk image based on the generalized blob located at URI sourceImageVhdUri. This image must be in the same region as the scale set that uses it. In the properties of the image, specify the OS type, the location of the blob (from the sourceImageVhdUri parameter), and the storage account type:

   "resources": [
     {
+      "type": "Microsoft.Compute/images",
+      "apiVersion": "2019-03-01",
+      "name": "myCustomImage",
+      "location": "[resourceGroup().location]",
+      "properties": {
+        "storageProfile": {
+          "osDisk": {
+            "osType": "Linux",
+            "osState": "Generalized",
+            "blobUri": "[parameters('sourceImageVhdUri')]",
+            "storageAccountType": "Standard_LRS"
+          }
+        }
+      }
+    },
+    {
       "type": "Microsoft.Network/virtualNetworks",
       "name": "myVnet",
       "location": "[resourceGroup().location]",

In the scale set resource, add a dependsOn clause referring to the custom image to make sure the image gets created before the scale set tries to deploy from that image:

       "location": "[resourceGroup().location]",
       "apiVersion": "2019-03-01-preview",
       "dependsOn": [
-        "Microsoft.Network/virtualNetworks/myVnet"
+        "Microsoft.Network/virtualNetworks/myVnet",
+        "Microsoft.Compute/images/myCustomImage"
       ],
       "sku": {
         "name": "Standard_A1",

Changing scale set properties to use the managed disk image

In the imageReference of the scale set storageProfile, instead of specifying the publisher, offer, sku, and version of a platform image, specify the id of the Microsoft.Compute/images resource:

  "virtualMachineProfile": {
    "storageProfile": {
      "imageReference": {
        "id": "[resourceId('Microsoft.Compute/images', omImage')]"
      }
    },
    "osProfile": {
      ...
    }
  }

In this example, use the resourceId function to get the resource ID of the image created in the same template. If you have created the managed disk image beforehand, you should provide the ID of that image instead. This ID must be of the form: /subscriptions/<subscription-id>resourceGroups/<resource-group-name>/providers/Microsoft.Compute/images/<image-name>.

Next Steps

You can deploy the preceding template by following the Azure Resource Manager documentation.

You can start this tutorial series from the basic scale set template article.

You can see how to modify the basic scale set template to deploy the scale set into an existing virtual network.

You can see how to modify the basic scale set template to deploy the scale set with a custom image.

You can see how to modify the basic scale set template to deploy a Linux scale set with guest-based autoscale.

For more information about scale sets, refer to the scale set overview page.