Duke Dougal
Duke Dougal

Reputation: 26336

How do I create a public virtual machine image using Azure ARM?

I want to create a virtual machine that anyone can launch using the ARM REST API.

How do I do that? I cannot find instructions.

Upvotes: 1

Views: 720

Answers (3)

squillace
squillace

Reputation: 41

This is to elaborate on @Michael B's answer: To discover what images are available, you can use the VMDepot -- of course -- or you can query for all the marketplace images. Look at the publishers list first, and then from there you can decide which images you would like.

The URN value you discover will be the one you want to use in your REST call. Hope this helps...

Upvotes: 0

Michael B
Michael B

Reputation: 12228

There are a couple of ways you could do this. Presuming you have got a website / application etc at the frontend, and it is simply the backend communication you're looking for.

Prerequisites

The option here presumes that you have an active Microsoft Azure account, and are able to create a VM there via the portal. Once you are at a stage that you can do that, you can use the REST API to create a machine instead.

Option 1

You can either use the REST API to directly create a VM by PUTing a request to this URI -

https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/Microsoft.Compute/virtualMachines/{vm-name}?validating={true|false}&api-version={api-version}

You would need to attach a JSON document to that request that would define the machine you are creating.

{  
  "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/myav1"
    },
    "hardwareProfile": {  
      "vmSize":"Standard_A0"
    },
    "storageProfile": {  
      "imageReference": {  
        "publisher":"MicrosoftWindowsServerEssentials",
        "offer":"WindowsServerEssentials",
        "sku":"WindowsServerEssentials",
        "version":"latest"
      },
      "osDisk": {  
        "name":"myosdisk1",
        "vhd": {  
          "uri":"http://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",
      "adminPassword":"password",
      "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"
      } ]
    }
  }
}

More details about the authentication and parameters can be found at the Azure Virtual Machine Rest documentation - Create or update a virtual machine

Option 2

Alternatively you can create an Azure Resource Manager Template, such as 101-vm-simple-linux on Azure's Github template repository

Once you have a template defined for the VM you want to deploy you can PUT another request to this URI

https://management.azure.com/subscriptions/{subscription-id}/resourcegroups/{resource-group-name}/providers/microsoft.resources/deployments/{deployment-name}?api-version={api-version}

If you copy that template file to an Azure blob, along with another file specifying any parameters it needs, and send this JSON document with the PUT request

{
  "properties": {
    "templateLink": {
      "uri": "http://mystorageaccount.blob.core.windows.net/templates/template.json",
      "contentVersion": "1.0.0.0",
    },
    "mode": "Incremental",
    "parametersLink": {
      "uri": "http://mystorageaccount.blob.core.windows.net/templates/parameters.json",
      "contentVersion": "1.0.0.0",      
    }
  }
}

You can find the documentation for this at - Create a template deployment

Upvotes: 0

Duke Dougal
Duke Dougal

Reputation: 26336

Apparently it is possible to create public virtual machine images here: https://vmdepot.msopentech.com/help/contribute/vhd.html/

Upvotes: 1

Related Questions