For the update scenario, a PUT or PATCH request can be submitted with a subset of the VM properties. Alternatively, the RESTful way is to do a GET, tweak the properties and submit a PUT request. For non-updateable properties, you can specify them in the update request but they must have the same values as returned by GET.
Request
For information about getting started with Azure REST operations including request authentication, see Azure REST API Reference.
| Method | Request URI |
|---|---|
| PUT | https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Compute/virtualMachines/{vm}&api-version={apiVersion} |
| Parameter | Description |
|---|---|
| subscriptionId | The identifier of your subscription. |
| resourceGroup | The resource group that will contain the virtual machine. |
| vm | The name of the virtual machine. |
| apiVersion | The version of the API to use. The current version is 2016-04-30-preview. |
The following example shows the request body for creating a virtual machine from a platform image. For examples of creating virtual machines in other ways, see the Examples section below.
{
"name": "myvm1",
"location": "westus",
"tags": {
"department": "finance"
},
"properties": {
"licenseType": "Windows_Server | Windows_Client",
"availabilitySet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myresourcegroup1/providers/Microsoft.Compute/availabilitySets/myav1"
},
"hardwareProfile": {
"vmSize": "Standard_A0"
},
"storageProfile": {
"imageReference": {
"publisher": "Publisher Name",
"offer": "Publisher Offer",
"sku": "Offer SKU",
"version": "Version for the image" // Can also specify "latest" to automatically get the latest image
},
"osDisk": {
"name": "myosdisk1",
"vhd": {
"uri": "http://mystorage1.blob.core.windows.net/vhds/myosdisk1.vhd"
},
"caching": "ReadOnly | ReadWrite", // Changing this value causes VM to reboot
"createOption": "fromImage | attach",
"encryptionSettings": {
"enabled": true,
"diskEncryptionKey": {
"sourceVault": {
"id": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.KeyVault/vaults/{vaultName}"
},
"secretUrl": "https://mykeyvault.vault.azure.net/secrets/{secret-name}/{secret-version}"
},
"keyEncryptionKey": {
"sourceVault": {
"id": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.KeyVault/vaults/{vaultName}"
},
"keyUrl": "https://mykeyvault.vault.azure.net/keys/{key-name}/{key-version}"
}
}
},
"dataDisks": [
// sample of creating empty data disk
{
"name": "mydatadisk1",
"diskSizeGB": "1",
"lun": 0,
"vhd": {
"uri": "http://mystorage.blob.core.windows.net/vhds/mydatadisk1.vhd"
},
"createOption": "empty"
},
// sample of attaching an existing VHD as a data disk
{
"name": "mydatadisk2",
"diskSizeGB": "1",
"lun": 1,
"vhd": {
"uri": "http://mystorage.blob.core.windows.net/vhds/mydatadisk2.vhd"
},
"createOption": "attach"
},
{
// sample of attaching a data disk from image
"name": "mydatadisk3",
"diskSizeGB": "1",
"lun": 2,
"image": { // specifies the location of the data disk vhd when creating the vm from user image
"uri": "http: //storagename.blob.core.windows.net/vhds/VMImageName-datadisk.vhd"
},
"vhd": {
"uri": "http://mystorage.blob.core.windows.net/vhds/mydatadisk3.vhd"
},
"createOption": "fromImage"
}
]
},
"osProfile": {
"computerName": "myvm1",
"adminUsername": "username",
"adminPassword": "password",
"customData": "",
"windowsConfiguration": {
"provisionVMAgent": true|false,
"winRM": {
"listeners": [
{
"protocol": "http"
},
{
"protocol": "https",
"certificateUrl": "url-to-key-vault-secret-that-has-the-certificate"
}
]
},
"additionalUnattendContent": {
"pass": "oobesystem",
"component": "Microsoft-Windows-Shell-Setup",
"settingName": "FirstLogonCommands|AutoLogon",
"content": "<XML unattend content>"
},
"enableAutomaticUpdates": true|false,
"timeZone": "Pacific Standard Time"
},
"linuxConfiguration": {
"disablePasswordAuthentication": true|false,
"ssh": {
"publicKeys": [
{
"path": "Path-Where-To-Place-Public-Key-On-VM",
"keyData": "PEM-Encoded-public-key-file"
}
]
}
},
"secrets": [
{
"sourceVault": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myresourcegroup1/providers/Microsoft.KeyVault/vaults/myvault1"
},
"vaultCertificates": [
{
"certificateUrl": "https://myvault1.vault.azure.net/secrets/{secretName}/{secretVersion}",
"certificateStore": "<certificateStoreName on Windows>" // Windows only property
}
]
}
]
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myresourceGroup1/providers /Microsoft.Network/networkInterfaces/mynic1",
"properties": {
"primary": true
}
},
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myresourceGroup1/providers /Microsoft.Network/networkInterfaces/mynic2",
"properties": {
"primary": false
}
}
]
},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": true|false,
"storageUri": " http://storageaccount.blob.core.windows.net/"
}
}
}
}
Top level elements
| Element name | Required | Type | Description |
|---|---|---|---|
| name | Yes | String | Specifies the name of the virtual machine. This name should be unique within the resource group. |
| location | Yes | String | Specifies the supported Azure location where the virtual machine should be created. This location can be different from the location of the resource group. For more information, see List all the available geo-locations. |
| tags | No | String | Specifies the tags that are assigned to the virtual machine. For more information about using tags, see Using tags to organize your Azure resources. |
| plan | No | Complex Type | Specifies information about the marketplace image used to create the virtual machine. This element is only used for marketplace images. Before you can use a marketplace image from an API, you must enable the image for programmatic use. In the Azure portal, find the marketplace image that you want to use and then click Want to deploy programmatically, Get Started ->. Enter any required information and then click Save. |
| properties | Yes | Complex Type | Specifies the properties of the virtual machine. |
plan
| Element name | Required | Type | Description |
|---|---|---|---|
| name | Yes | String | Specifies the name of the image from the marketplace. This is the same value that you use for Sku under the imageReference element. For more information about how to find image information, see Navigating and Selecting Azure Virtual Machine images with PowerShell and the Azure CLI |
| publisher | Yes | String | Specifies the publisher of the image. |
| product | Yes | String | Specifies the product of the image from the marketplace. This is the same value as Offer under the imageReference element. |
properties
| Element name | Required | Type | Description |
|---|---|---|---|
| licenseType | No | String | Specifies that the image or disk that is being used was licensed on-premises. This element is only used for images that contain the Windows Server operating system. Possible values are: Windows_Client Windows_Server If this element is included in a request for an update, the value must match the initial value. This value cannot be updated. For more information, see Azure Hybrid Use Benefit for Windows Server Minimum api-version: 2015-06-15 |
| availabilitySet | No | Complex Type | Specifies information about the availability set that the virtual machine should be assigned to. Virtual machines specified in the same availability set are allocated to different nodes to maximize availability. For more information about availability sets, see Manage the availability of virtual machines. For more information on Azure planned maintainance, see Planned maintenance for virtual machines in Azure Currently, a VM can only be added to availability set at creation time. An existing VM cannot be added to an availability set. |
| hardwareProfile | Yes | Complex Type | Specifies the hardware settings for the virtual machine. |
| storageProfile | Yes | Complex Type | Specifies the storage settings for the virtual machine disks. |
| osProfile | Yes | Complex Type | Specifies the operating system settings for the virtual machine. |
| networkProfile | Yes | Complex Type | Specifies the network interfaces of the virtual machine. |
| diagnosticsProfile | No | Complex Type | Specifies the boot diagnostic settings state. Minimum api-version: 2015-06-15 |
availabilitySet
| Element name | Required | Type | Description |
|---|---|---|---|
| id | Yes | String | Specifies the resource Id for the availability set to which the Virtual Machine is added. To get this, you need to first create the availability set and then get its resource Id. |
hardwareProfile
| Element name | Required | Type | Description |
|---|---|---|---|
| vmSize | Yes | String | Specifies the size of the virtual machine. For more information about virtual machine sizes, see Sizes for virtual machines. The available VM sizes depend on region and availability set. For a list of available sizes use these APIs: List all available virtual machine sizes in an availability set List all available virtual machine sizes in a region List all available virtual machine sizes for resizing |
storageProfile
| Element name | Required | Type | Description |
|---|---|---|---|
| imageReference | No | Complex Type | Specifies information about the image to use. You can specify information about platform images, marketplace images, or virtual machine images. This element is required when you want to use a platform image, marketplace image, or virtual machine image, but is not used in other creation operations. |
| osDisk | Yes | Complex Type | Specifies information about the operating system disk used by the virtual machine. For more information about disks, see About disks and VHDs for Azure virtual machines. |
| dataDisks | No | Complex Type | Specifies the parameters that are used to add a data disk to a virtual machine. For more information about disks, see About disks and VHDs for Azure virtual machines. |
imageReference
| Element name | Required | Type | Description |
|---|---|---|---|
| id | Yes, if using a virtual machine image. | String | Specifies the resource identifier of a virtual machine image in your subscription. This element is only used for virtual machine images, not platform images or marketplace images. Minimum api-version: 2016-04-30-preview |
| publisher | Yes | String | Specifies the publisher of the platform image or marketplace image used to create the virtual machine. For more information about how to find image information, see Navigating and Selecting Azure Virtual Machine images with PowerShell and the Azure CLI. |
| offer | Yes | String | Specifies the offer of the platform image or marketplace image used to create the virtual machine. |
| sku | Yes | String | Specifies the SKU of the platform image or marketplace image used to create the virtual machine. |
| version | Yes | String | Specifies the version of the platform image or marketplace image used to create the virtual machine. You can use the value of latest to use the latest version of an image. |
osDisk
| Element name | Required | Type | Description |
|---|---|---|---|
| name | Yes | String | Specifies the disk name. This element can be used to overwrite the name of the disk in a virtual machine image. |
| Uri | Yes | String | Specifies the vhd uri. |
| caching | No | String | Specifies the caching requirements. Note that the OS disk will always use read caching even if the setting is configured to None. Possible values are: None ReadOnly ReadWrite Default: ReadWrite |
| createOption | Yes | String | Specifies how the virtual machine should be created. Possible values are: Attach – This value is used when you are using a specialized disk to create the virtual machine. FromImage – This value is used when you are using an image to create the virtual machine. If you are using a platform image, you also use the imageReference element described above. If you are using a marketplace image, you also use the plan element previously described. |
| diskSizeGB | No | Int | Specifies the resized size of the OS Disk. Allows you to resize an existing OS disk size. This value cannot be larger than 1023 GB. This element is not returned in the GET VM call unless specified on the first resize disk operation. The partitions on the VMs will need to be adjusted for the new size from within the OS. Minimum api-version: 2015-06-15 |
| osType | Yes for user-image deployments Do not specify for platform/marketplace image deployments |
Int | This property allows you to specify the type of the OS that is included in the disk if creating a VM from user-image or a specialized VHD. Possible values are: Windows Linux |
| encryptionSettings | No | Complex Type | Specifies the encryption settings for the OS Disk. Minimum api-version: 2015-06-15 |
encryptionSettings
| Element name | Required | Type | Description |
|---|---|---|---|
| enabled | Yes | boolean | Specifies if the encryption is enabled Minimum api-version: 2016-03-30 |
| diskEncryptionKey | Yes | Complex Object | Specifies the location of the disk encryption key. |
| keyEncryptionKey | Yes | Complex Object | Specifies the location of the key encryption key. |
diskEncryptionKey
| Element name | Required | Type | Description |
|---|---|---|---|
| sourceVault.Id | Yes | String | Specifies the resource Id of the Key Vault to use. For more on Key Vault, see What is Azure Key Vault? Get started with Azure Key Vault |
| keyUrl | Yes | String | Specifies the location of the disk encryption key. |
keyEncryptionKey
| Element name | Required | Type | Description |
|---|---|---|---|
| sourceVault.Id | Yes | String | Specifies the resource Id of the Key Vault to use. For more on Key Vault, see What is Azure Key Vault? Get started with Azure Key Vault |
| keyUrl | Yes | String | Specifies the location of the key encryption key. |
dataDisks
| Element name | Required | Type | Description |
|---|---|---|---|
| name | Yes | String | Specifies the name of the data disk. This element can be used to overwrite the name of the disk in a virtual machine image. For using letter D: for a data disk, see Use the D drive as a data drive on a Windows VM. For adding a disk to your vm using CLI, see Add a disk to a Linux VM. For creating a RAID array on Linux, see Configure Software RAID on Linux. |
| diskSizeGB | Yes | String | Specifies the size of the data disk in gigabytes. This element can be used to overwrite the name of the disk in a virtual machine image. This value cannot be larger than 1023 GB |
| caching | No | String | Specifies the caching requirements. Possible values are: None ReadOnly ReadWrite Default: None for Standard storage. ReadOnly for Premium storage |
| lun | Yes | Int | Specifies the logical unit number of the data disk. |
| vhd | Yes | String | Specifies the uri of the location in storage where the VHD for the virtual machine should be placed. |
| managedDisk | Specified the identifier and optional storage account type for the disk. | ||
| creationOption | Yes | String | Specifies how the data disk should be created. Possible values are: Attach - This value is used when you are using a specialized disk/VHD to attach to the virtual machine. FromImage - This value is used when you are using an image to create the virtual machine. If you are using a platform image, you will also use the imageReference element described above. If you are using a marketplace image, you will also use the plan element described above. |
managedDisk
| Element name | Required | Type | Description |
|---|---|---|---|
| Id | Yes | String | Specifies the resource identifier of the managed disk. |
| storageAccountType | No | String | Specifies the storage account type for the managed disk. Possible values are: Standard_LRS or Premium_LRS. |
osProfile
| Element name | Required | Type | Description |
|---|---|---|---|
| computerName | No | String | Specifies the host OS name of the virtual machine. Max-length (Windows): 15 characters Max-length (Linux): 64 characters. For naming conventions and restrictions see Azure infrastructure services implementation guidelines. |
| adminUsername | Yes | String | Specifies the name of the administrator account. Windows-only restriction: Cannot end in "." Disallowed values: "administrator", "admin", "user", "user1", "test", "user2", "test1", "user3", "admin1", "1", "123", "a", "actuser", "adm", "admin2", "aspnet", "backup", "console", "david", "guest", "john", "owner", "root", "server", "sql", "support", "support_388945a0", "sys", "test2", "test3", "user4", "user5". Minimum-length (Linux): 1 character Max-length (Linux): 64 characters Max-length (Windows): 20 characters |
| adminPassword | Yes on Windows No on Linux |
Secure String | Specifies the password of the administrator account. Minimum-length (Windows): 8 characters Minimum-length (Linux): 6 characters Max-length (Windows): 123 characters Max-length (Linux): 72 characters Complexity requirements: 3 out of 4 conditions below need to be fulfilled Has lower characters Has upper characters Has a digit Has a special character (Regex match [\W_]) Disallowed values: "abc@123", "P@$$w0rd", "P@ssw0rd", "P@ssword123", "Pa$$word", "pass@word1", "Password!", "Password1", "Password22", "iloveyou!" For resetting the password, see How to reset the Remote Desktop service or its login password in a Windows VM For resetting root password, see Manage users, SSH, and check or repair disks on Azure Linux VMs using the VMAccess Extension |
| customData | No | String | Specifies a base-64 encoded string of custom data. The base-64 encoded string is decoded to a binary array that is saved as a file on the Virtual Machine. The maximum length of the binary array is 65535 bytes. For using cloud-init for your VM, see Using cloud-init to customize a Linux VM during creation |
| windowsConfiguration | Yes on Windows No on Linux |
Complex Type | Specifies Windows operating system settings on the virtual machine. |
| linuxConfiguration | No on Windows Yes on Linux |
Complex Type | Specifies the Linux operating system settings on the virtual machine. For a list of supported Linux distributions, see Linux on Azure-Endorsed Distributions For running non-endorsed distributions, see Information for Non-Endorsed Distributions. |
| secrets | No | Complex Type | Specifies set of certificates that should be installed onto the virtual machine. |
windowsConfiguration
| Element name | Required | Type | Description |
|---|---|---|---|
| provisionVMAgent | No | Boolean | Indicates whether virtual machine agent should be provisioned on the virtual machine. When this property is not specified in the request body, default behavior is to set it to true. This will ensure that VM Agent is installed on the VM so that extensions can be added to the VM later. |
| winRM | No | Collection | Specifies the Windows Remote Management listeners. This enables remote Windows PowerShell. |
| additionalUnattendContent | No | Complex Type | Specifies additional XML formatted information that can be included in the Unattend.xml file, which is used by Windows Setup. |
| enableAutomaticUpdates | No | Boolean | Indicates whether virtual machine is enabled for automatic updates. |
| timeZone | No | String | Specifies the time zone of the virtual machine. e.g. "Pacific Standard Time" |
linuxConfiguration
| Element name | Required | Type | Description |
|---|---|---|---|
| disablePasswordAuthentication | No | Boolean | Specifies whether password authentication should be disabled. |
| ssh.publicKeys | No if password specified Yes if password not specified |
Collection | Specifies a collection of keys to be placed on the virtual machine. When a SSH key is specified, "disablePasswordAuthentication" property is automatically set to "true". For creating ssh keys, see Create SSH keys on Linux and Mac for Linux VMs in Azure. |
publicKeys
| Element name | Required | Type | Description |
|---|---|---|---|
| path | Yes | String | Specifies the full path on the created VM where ssh public key is stored. If the file already exists, the specified key is appended to the file. Example: /home/user/.ssh/authorized_keys |
| keyData | Yes | String | SSH public key certificate used to authenticate with the VM through ssh. The key needs to be at least 2048-bit and in ssh-rsa format. For creating ssh keys, see Create SSH keys on Linux and Mac for Linux VMs in Azure. |
winRM
| Element name | Required | Type | Description |
|---|---|---|---|
| protocol | Yes | String | Specifies the protocol of listener. Possible values are: http https |
| certificateUrl | No | String | Specifies URL of the certificate with which new Virtual Machines is provisioned. This property is only needed when https is the specified protocol above. |
additionalUnattendContent
| Element name | Required | Type | Description |
|---|---|---|---|
| pass | Yes | String | Specifies the name of the pass that the content applies to. The only allowable value is oobeSystem. |
| component | Yes | String | Specifies the name of the component to configure with the added content. The only allowable value is Microsoft-Windows-Shell-Setup. |
| settingName | Yes | String | Specifies the name of the setting to which the content applies. Possible values are: FirstLogonCommands and AutoLogon. |
| content | Yes | String | Specifies the XML formatted content that is added to the unattend.xml file for the specified path and component. The XML must be less than 4KB and must include the root element for the setting or feature that is being inserted. |
secrets
| Element name | Required | Type | Description |
|---|---|---|---|
| sourceVault | Yes | Complex Type | Specifies the key vault to use. |
| vaultCertificates | Yes | Collection | Specifies additional certificate information. |
sourceVault
| Element name | Required | Type | Description |
|---|---|---|---|
| id | Yes | String | Specifies the uri of the Key Vault that contains all of the secrets. |
vaultCertificates
| Element name | Required | Type | Description |
|---|---|---|---|
| certificateUrl | Yes | String | This is the URL of a certificate that has been uploaded to Key Vault as a secret. For adding a secret to the Key Vault, see Add a key or secret to the key vault. In this case, your certificate needs to be It is the Base64 encoding of the following JSON Object which is encoded in UTF-8: { "data":" "dataType":"pfx", "password":" } |
| certificateStore | No | String | For Windows VMs, specifies the certificate store on the Virtual Machine to which the certificate should be added. The specified certificate store is implicitly in the LocalMachine account. For Linux VMs, the certificate file is placed under the /var/lib/waagent directory, with the file name |
networkProfile
| Element name | Required | Type | Description |
|---|---|---|---|
| networkInterfaces | Yes | Collection | Specifies the list of resource Ids for the network interfaces associated with the virtual machine. |
networkInterfaces
| Element name | Required | Type | Description |
|---|---|---|---|
| id | Yes | String | Specifies the resource Id of the network interface. |
| primary | No | boolean | Specifies the primary network interface in case the virtual machine has more than 1 network interface. |
diagnosticsProfile
| Element name | Required | Type | Description |
|---|---|---|---|
| bootDiagnostics | Yes | Collection | Boot Diagnostics is a debugging feature which allows you to view Console Output and Screenshot to diagnose VM status. For Linux Virtual Machines, you can easily view the output of your console log. For both Windows and Linux virtual machines, Azure also enables you to see a screenshot of the VM from the hypervisor. |
bootDiagnostics
| Element name | Required | Type | Description |
|---|---|---|---|
| enabled | Yes | String | Specifies if the bootDiagnostics is enabled. |
| storageUri | Yes | String | Uri of the storage account to use for placing the console output and screenshot. |
Response
Status code: 200 (OK). 404 (NotFound) if a resource does not exist.
The following example shows the response body for a virtual machine that was created from a platform image. Responses from other create operations will include the elements shown in the following Examples section.
{
"id":"/subscriptions/{subscription-id}/resourceGroups/myresourcegroup1/providers/Microsoft.Compute/virtualMachines/myvm1",
"name":"myvm1",
"type":"Microsoft.Compute/virtualMachines",
"location":"westus",
"tags": {
"department":"finance"
},
"properties": {
"availabilitySet": {
"id":"/subscriptions/{subscription-id}/resourceGroups/myresourcegroup1/providers/Microsoft.Compute/availabilitySets/myavset1"
},
"hardwareProfile": {
"vmSize":"Standard_A0"
},
"storageProfile": {
"imageReference": {
"publisher":"MicrosoftWindowsServerEssentials",
"offer":"WindowsServerEssentials",
"sku":"WindowsServerEssentials",
"version":"latest"
},
"osDisk": {
"name":"myosdisk1",
"vhd": {
"uri":"mystorage1.blob.core.windows.net/vhds/myosdisk1.vhd"
},
"caching":"ReadWrite",
"createOption":"FromImage"
},
"dataDisks":[ {
"name":"mydatadisk1",
"diskSizeGB":"1",
"lun": 0,
"vhd": {
"uri" : "http://mystorage1.blob.core.windows.net/vhds/mydatadisk1.vhd"
},
"createOption":"Empty"
} ]
},
"osProfile": {
"computerName":"myvm1",
"adminUsername":"username",
"customData":"",
"windowsConfiguration": {
"provisionVMAgent": true,
"winRM": {
"listeners": [ {
"protocol": "https",
"certificateUrl": "url-to-certificate"
} ]
},
"additionalUnattendContent": {
"pass":"oobesystem",
"component":"Microsoft-Windows-Shell-Setup",
"settingName":"FirstLogonCommands|AutoLogon",
"content":"<XML unattend content>"
}
"enableAutomaticUpdates":true
},
"secrets":[ {
"sourceVault": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myresourcegroup1/providers/Microsoft.KeyVault/vaults/myvault1"
},
"vaultCertificates": [ {
"certificateUrl": "https://myvault1.vault.azure.net/secrets/{secretName}/{secretVersion}"
"certificateStore": "{certificateStoreName}"
} ]
} ]
},
"networkProfile": {
"networkInterfaces": [ {
"id":"/subscriptions/{subscription-id}/resourceGroups/myresourcegroup1/providers/Microsoft.Network/networkInterfaces/mynic1"
} ]
},
"provisioningState":"succeeded"
}
}
The provisioningState element specifies the status of the virtual machine deployment. For descriptions of the other elements in the response, see the Request section.
Examples
Create a managed VM
"storageProfile": {
"imageReference": {
"publisher":"MicrosoftWindowsServerEssentials",
"offer":"WindowsServerEssentials",
"sku":"WindowsServerEssentials",
"version":"latest"
"id": "/subscriptions/{subscription-id}/providers/Microsoft.Compute/locations/westus/publishers/MicrosoftWindowsServerEssentials/ArtifactTypes/vmimage/offers/WindowsServerEssentials/skus/WindowsServerEssentials/versions/latest"
},
"osDisk": {
"name": "osdisk",
"osType": "<Windows or Linux>",
"createOption": "fromImage",
"diskSizeGB": "10"
}
}
Create a VM from a virtual machine image
This example shows how to create a VM from a virtual machine image. The key things to notice are the value fromImage for the createOption property and the imageReference.id property. The imageRefence.id value is the resource identifier of a virtual machine image in your subscription.
"storageProfile": {
"imageReference": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myresourcegroup1/providers/Microsoft.Compute/images/myImage"
},
"osDisk": {
"name": "osdisk",
"osType": "<Windows or Linux>",
"createOption": "fromImage"
}
}
Create a VM from a virtual machine image with an attached managed disk
{
"storageProfile": {
"imageReference": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myresourcegroup1/providers/Microsoft.Compute/images/myImage"
},
"osDisk": {
"name": "myosdisk", # override the os disk name in the VM image
"createOption": "fromImage"
},
"dataDisks": [
{
"name": "datadisk1", # override the data disk name in the VM image
"diskSizeGB": "64" # override the size of the existing data disk
},
{
"lun": "2", # add new managed datadisk
"name": "datadisk2",
"managedDisk": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myresourcegroup1/providers/Microsoft.Compute/disks/myDisk2",
"storageAccountType": "Standard_LRS"
},
"createOption": "attach"
}
]
}
}
Create a VM from a VHD in Azure storage
This example shows how to create a VM from a generalized/sysprepped VHD in Azure storage. The key things to notice are the value fromImage for the createOption property and image.uri and vhd.uri properties in the osDisk object. image.uri is the location of your image and vhd.uri is where the disk is copied to and the VM is booted from.
"osProfile": {
"computerName": "contosoVM",
"adminUsername": "contosouser",
"adminPassword": "Contoso!pas1"
},
"storageProfile": {
"osDisk": {
"name": "osdisk",
"osType": "<Windows or Linux>",
"caching": "ReadWrite",
"createOption": "FromImage",
"image": {
"uri": "http://storagename.blob.core.windows.net/vhds/VMImageName-osdisk.vhd"
},
"vhd": {
"uri": "http://storagename.blob.core.windows.net/vhds/osdisk.vhd"
}
}
},
"dataDisks": [
{
"name": "mydatadisk1",
"diskSizeGB": "1",
"lun": 0,
"image": {
"uri": "http://storagename.blob.core.windows.net/vhds/VMImageName-datadisk.vhd"
},
"vhd": {
"uri": "http://mystorage.blob.core.windows.net/vhds/mydatadisk3.vhd"
},
"createOption": "fromImage"
}
]
Creating a VM using an existing disk
This example shows how to create a VM from an existing disk. The key things to notice are the value attach for the createOption property and vhd.uri properties in the osDisk object. image.uri isn't needed in this case since you are just attaching the vhd.uri and the VM is booted from it.
In this case osProfile is not needed since all OS properties such as username/password as persisted in the VHD when it is not generalized.
"storageProfile": {
"osDisk": {
"name": "osdisk",
"osType": "<Windows or Linux>",
"caching": "ReadWrite",
"vhd": {
"uri": "http://mystorage.blob.core.windows.net/vhds/mydatadisk3.vhd"
},
"createOption": "Attach"
}
}
Marketplace image
The following example shows the additional plan element that is required when you use a marketplace image:
{
"id": "/subscriptions/{subscription-id/resourceGroups/myresourcegroup1/providers/Microsoft.Compute/virtualMachines/myvm1",
"name": "myvm1",
"type": "Microsoft.Compute/virtualMachines",
"location": "westus",
"tags": {
"department": "finance"
},
"plan": {
"name": "imageName",
"publisher": "imagePublisher",
"product": "imageProduct"
},
"properties": {
...
Linux VM
The following example shows the linuxConfiguation element that is required when you are creating a Linux virtual machine.
"osProfile": {
"computerName": "virtualMachineName",
"adminUsername": "username",
"adminPassword": "password",
"customData": "",
"linuxConfiguration": {
"disablePasswordAuthentication": "true|false",
"ssh": {
"publicKeys": [ {
"path": "key-path-on-vm",
"keyData": "public-key"
} ]
}
}
...
On-Premises License/Hybrid Use Benefit
The following example shows the licenseType element that is used when the image or disk was licensed on-premises.
"properties": {
"licenseType": "Windows_Server",
"availabilitySet": {
"id":"/subscriptions/{subscription-id}/resourceGroups/myresourcegroup1/providers/Microsoft.Compute/availabilitySets/myav1"
},
...




