none
How to use an existing Container and Storage Account in an ARM Template for creation of Windows Jumpbox VM

    Question

  • I am trying to create a Windows Server 2012 R2 VM using ARM which will act as my Jump Box.

    I already had a Linux Template which i used to create one of my Suse Linux workload and now i want to tweak the same template and just use it for my Windows VM.

    I already created manually another Storage Account by the name of "mystor2017" and a container inside it by the name of "testcontainer".

    I want to tell my template to use the storage account that i created and the container manually, to put the new Jump Box vhd.

    So can anyone tell me what all i need to put in the variable section in storage account name and in resources also ?
    What shall i remove from resources, should i remove the storage account name section or i keep it and Azure would ignore it since it's already there.

    Also, in general, what if i create certain things manually and then want to use them in a template for building a VM, what is the procedure to do it.

    Also what needs to be there in Output section.

    Thanks.

    Appreciate your help

    *********************************************************************************

    {
      "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "parameters": {
        "adminPassword": {
          "type": "securestring",
          "metadata": {
            "description": "Password for the Virtual Machine."
          }
        },
        "adminUsername": {
          "type": "string",
          "metadata": {
            "description": "User name for the Virtual Machine."
          }
        },
        "dnsLabelPrefix": {
          "type": "string",
          "metadata": {
            "description": "Unique DNS Name for the Public IP used to access the Virtual Machine."
          }
        },
        "windowsOSVersion": {
          "type": "string",
          "defaultValue": "Server 2012 R2 SP2",
          "metadata": {
            "description": "The Windows version for the VM. This will pick the latest available image of this given Windows version."
          }
        }
      },
      "variables": {
        "addressPrefix": "10.0.0.0/16",
        "dataDisk1VhdName": "datadisk1",
        "imageOffer": "Server 2012 R2 SP2",
        "imagePublisher": "Microsoft",
        "nicName": "myVMNic",
        "OSDiskName": "WINVMOSD",
        "publicIPAddressName": "myPublicIP",
        "publicIPAddressType": "Dynamic",
        "storageAccountName": "[concat(uniquestring(resourceGroup().id), 'jumpboxvm')]",
        "storageAccountType": "Standard_LRS",
        "subnetName": "mywinSubnet",
        "subnetPrefix": "10.0.0.0/24",
        "subnetRef": "[concat(variables('vnetID'),'/subnets/',variables('subnetName'))]",
        "virtualNetworkName": "MyVNET",
        "vmName": "jumpdevvm",
        "vmSize": "Standard_A4_v2",
        "vmStorageAccountContainerName": "vhds",
        "vnetID": "[resourceId('Microsoft.Network/virtualNetworks',variables('virtualNetworkName'))]"
      },
      "resources": [
        {
          "apiVersion": "2015-06-15",
          "location": "[resourceGroup().location]",
          "name": "[variables('storageAccountName')]",
          "properties": {
            "accountType": "[variables('storageAccountType')]"
          },
          "type": "Microsoft.Storage/storageAccounts"
        },
        {
          "apiVersion": "2015-06-15",
          "type": "Microsoft.Network/publicIPAddresses",
          "name": "[variables('publicIPAddressName')]",
          "location": "[resourceGroup().location]",
          "properties": {
            "publicIPAllocationMethod": "[variables('publicIPAddressType')]",
            "dnsSettings": {
              "domainNameLabel": "[parameters('dnsLabelPrefix')]"
            }
          }
        },
        {
          "apiVersion": "2015-06-15",
          "type": "Microsoft.Network/virtualNetworks",
          "name": "[variables('virtualNetworkName')]",
          "location": "[resourceGroup().location]",
          "properties": {
            "addressSpace": {
              "addressPrefixes": [
                "[variables('addressPrefix')]"
              ]
            },
            "subnets": [
              {
                "name": "[variables('subnetName')]",
                "properties": {
                  "addressPrefix": "[variables('subnetPrefix')]"
                }
              }
            ]
          }
        },
        {
          "apiVersion": "2015-06-15",
          "type": "Microsoft.Network/networkInterfaces",
          "name": "[variables('nicName')]",
          "location": "[resourceGroup().location]",
          "dependsOn": [
            "[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]",
            "[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]"
          ],
          "properties": {
            "ipConfigurations": [
              {
                "name": "ipconfig1",
                "properties": {
                  "privateIPAllocationMethod": "Dynamic",
                  "publicIPAddress": {
                    "id": "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]"
                  },
                  "subnet": {
                    "id": "[variables('subnetRef')]"
                  }
                }
              }
            ]
          }
        },
        {
          "apiVersion": "2015-06-15",
          "type": "Microsoft.Compute/virtualMachines",
          "name": "[variables('vmName')]",
          "location": "[resourceGroup().location]",
          "dependsOn": [
            "[concat('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]",
            "[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
          ],
          "properties": {
            "hardwareProfile": {
              "vmSize": "[variables('vmSize')]"
            },
            "osProfile": {
              "computerName": "[variables('vmName')]",
              "adminUsername": "[parameters('adminUsername')]",
              "adminPassword": "[parameters('adminPassword')]"
            },
            "storageProfile": {
              "imageReference": {
                "publisher": "[variables('imagePublisher')]",
                "offer": "[variables('imageOffer')]",
                "sku": "[parameters('suseOSVersion')]",
                "version": "latest"
              },
              "osDisk": {
                "name": "osdisk",
                "vhd": {
                  "uri": "[concat(reference(concat('Microsoft.Storage/storageAccounts/', variables('storageAccountName')), '2015-06-15').primaryEndpoints.blob, variables('vmStorageAccountContainerName'),'/',variables('OSDiskName'),'.vhd')]"
                },
                "caching": "ReadWrite",
                "createOption": "FromImage"
              },
              "dataDisks": [
                {
                  "name": "datadisk1",
                  "diskSizeGB": "100",
                  "lun": 0,
                  "vhd": {
                    "uri": "[concat(reference(concat('Microsoft.Storage/storageAccounts/', variables('storageAccountName')), '2015-06-15').primaryEndpoints.blob, variables('vmStorageAccountContainerName'),'/',variables('dataDisk1VhdName'),'.vhd')]"
                  },
                  "createOption": "Empty"
                }
              ]
            },
            "networkProfile": {
              "networkInterfaces": [
                {
                  "id": "[resourceId('Microsoft.Network/networkInterfaces',variables('nicName'))]"
                }
              ]
            },
            "diagnosticsProfile": {
              "bootDiagnostics": {
                "enabled": "true",
                "storageUri": "[reference(concat('Microsoft.Storage/storageAccounts/', variables('storageAccountName')), '2015-06-15').primaryEndpoints.blob]"
              }
            }
          }
        }
      ],
      "outputs": {
         "hostname": {
             "type": "string",
             "value": "[concat(parameters('dnsLabelPrefix'), '.', resourceGroup().location, '.cloudapp.azure.com')]"
         },
        "sshCommand": {
          "type": "string",
          "value": "[concat('ssh ', parameters('adminUsername'), '@', parameters('dnsLabelPrefix'), '.', resourceGroup().location, '.cloudapp.azure.com')]"
        }
      }
    }


    Pallab Chakraborty

    Friday, March 24, 2017 2:55 PM

Answers