0
votes

Below ARM template I was trying to run to create 3 VMs in one Resource group. From the Azure portal errors I found out that template failing on VirtualNetwork creation.

   "name": "[variables('virtualNetworkName')]",
    "type": "Microsoft.Network/virtualNetworks"

What I need is simple expand ~900 identical VMs with private IPs in the same resource group. No DNS or join domain is required.

I found out that to create VM I need Virtual Network and Network security group.I think I don't need storage account for them or at least I somehow can use one storage account for all of them.
In the quickstart templates from Azure I didn't find such template. Will appreciate your help to make it work.

virtualMachineSize:Basic_A0

{
  "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": { 
        "virtualMachineName": {
            "type": "string",
			"defaultValue": "uservm0010"
        }, 
        "virtualMachineSize": {
            "type": "string"
			
        },
        "adminUsername": {
            "type": "string",
			"defaultValue": "user"
        },
           "adminPassword": {
            "type": "securestring",
			 "value": null
        }
  },
   "variables": {
       
		"nicName": "myVMNic",
		"addressPrefix": "10.0.0.0/16",
		"subnetName": "Subnet",
		"subnetPrefix": "10.0.0.0/24",
		"vmName": "SimpleLinVM",
		"virtualNetworkName": "MyVNET",			  
		"subnetRef": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('virtualNetworkName'), variables('subnetName'))]"
				
    },
  "resources": [
      {
           "apiVersion": "2017-12-01",
           "name": "[concat(variables('vmName'), padLeft(copyIndex(), 2, '0'))]",
            "type": "Microsoft.Compute/virtualMachines",				            
            "location": "[parameters('location')]",
            "properties": {
                "osProfile": {
                   "computerName": "[variables('vmName')]",
					"adminUsername": "[parameters('adminUsername')]",
					"adminPassword": "[parameters('adminPassword')]"
                },
                "hardwareProfile": {
                    "vmSize": "Basic_A0"
                },
                "storageProfile": {
                    "imageReference": {
                        "publisher": "credativ",
                        "offer": "Debian",
                        "sku": "9",
                        "version": "latest"
                    },
                    
                    "dataDisks": []
                },
                "networkProfile": {
                    "networkInterfaces": [
                        {
							"id": "[resourceId('Microsoft.Network/networkInterfaces',variables('nicName'))]"
						}
                    ]
                }

            }
      },
      {  
            "name": "[variables('virtualNetworkName')]",
            "type": "Microsoft.Network/virtualNetworks",
            "apiVersion": "2018-02-01",
            "location": "[parameters('location')]",
            "properties": {
                "addressSpace": {
                    "addressPrefixes": [
                        "[variables('addressPrefix')]"
                    ]
                },
                "subnets": [
                    {
                        "name": "[variables('subnetName')]",
                        "properties": {
                            "addressPrefix": "[variables('subnetPrefix')]"
                        }
                    }
                ]
            }
        },
        { 
			"name": "[variables('nicName')]",	
			"type": "Microsoft.Network/networkInterfaces",
			"apiVersion": "2016-09-01",
			"location": "[parameters('location')]",
			            
            "properties": {
                "ipConfigurations": [
                    {
                        "name": "ipconfig1",
                        "properties": {
                            "subnet": {
                                "id": "[variables('subnetRef')]"
                            },
                            "privateIPAllocationMethod": "Dynamic"
                        }
                    }
                ]
            
            }
        },
        {"copy":{
			"name": "[parameters('virtualMachineName')]",
			"count": 3
			}
        }
  ]
}
1
If you need to deploy the same VM x times, you may want to use a VM scale set ? have a lok at this template github.com/Azure/azure-quickstart-templates/tree/master/…Thomas

1 Answers

1
votes

You can use the template I tested below. The template contains one Availability Set and one virtual network and three VMs, no NSG. And I advise you Availability Set so much. You can change something as you want.

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "adminUsername": {
            "type": "string",
            "metadata": {
                "description": "Admin username for VM"
            }
        },
        "adminPassword": {
            "type": "securestring",
            "metadata": {
                "description": "Admin password for VMs"
            }
        },
        "numberOfInstances": {
            "type": "int",
            "defaultValue": 2,
            "minValue": 2,
            "maxValue": 5,
            "metadata": {
                "description": "Number of VMs to deploy, limit 5 since this sample is using a single storage account"
            }
        },
        "OS": {
            "type": "string",
            "defaultValue": "Ubuntu",
            "allowedValues": [
                "Ubuntu",
                "Windows"
            ],
            "metadata": {
                "description": "OS Platform for the VM"
            }
        },
        "location": {
            "type": "string",
            "defaultValue": "[resourceGroup().location]",
            "metadata": {
                "description": "Location for all resources."
            }
        },
        "vmSizes": {
            "type": "string",
            "allowedValues": [
                "Basic_A0",
                "Standard_D1_v2"
            ],
            "defaultValue": "Standard_D1_v2",
            "metadata": {
                    "description": "The type of replication to use for the VM size."
            }
        }
    },
    "variables": {
        "virtualNetworkName": "myVNET",
        "addressPrefix": "10.0.0.0/16",
        "subnet1Name": "Subnet-1",
        "subnet1Prefix": "10.0.0.0/24",
        "subnet1Ref": "[resourceId('Microsoft.Network/virtualNetworks/subnets',variables('virtualNetworkName'),variables('subnet1Name'))]",
        "availabilitySetName": "myAvSet",
        "Ubuntu": {
            "publisher": "Canonical",
            "offer": "UbuntuServer",
            "sku": "16.04.0-LTS",
            "version": "latest"
        },
        "Windows": {
            "publisher": "MicrosoftWindowsServer",
            "offer": "WindowsServer",
            "sku": "2016-Datacenter",
            "version": "latest"
        },
        "imageReference": "[variables(parameters('OS'))]"
    },
    "resources": [
        {
            "type": "Microsoft.Compute/availabilitySets",
            "name": "[variables('availabilitySetName')]",
            "apiVersion": "2016-04-30-preview",
            "location": "[parameters('location')]",
            "properties": {
                "platformFaultDomainCount": 2,
                "platformUpdateDomainCount": 2,
                "managed": true
            }
        },
        {
            "type": "Microsoft.Network/virtualNetworks",
            "name": "[variables('virtualNetworkName')]",
            "apiVersion": "2016-03-30",
            "location": "[parameters('location')]",
            "properties": {
                "addressSpace": {
                    "addressPrefixes": [
                        "[variables('addressPrefix')]"
                    ]
                },
                "subnets": [
                    {
                        "name": "[variables('subnet1Name')]",
                        "properties": {
                            "addressPrefix": "[variables('subnet1Prefix')]"
                        }
                    }
                ]
            }
        },
        {
            "type": "Microsoft.Network/networkInterfaces",
            "name": "[concat('nic', copyindex())]",
            "apiVersion": "2016-03-30",
            "location": "[parameters('location')]",
            "copy": {
                "name": "nicLoop",
                "count": "[parameters('numberOfInstances')]"
            },
            "dependsOn": [
                "[variables('virtualNetworkName')]"
            ],
            "properties": {
                "ipConfigurations": [
                    {
                        "name": "ipconfig1",
                        "properties": {
                            "privateIPAllocationMethod": "Dynamic",
                            "subnet": {
                                "id": "[variables('subnet1Ref')]"
                            }
                        }
                    }
                ]
            }
        },
        {
            "type": "Microsoft.Compute/virtualMachines",
            "name": "[concat('myvm', copyIndex())]",
            "apiVersion": "2016-04-30-preview",
            "location": "[parameters('location')]",
            "copy": {
                "name": "virtualMachineLoop",
                "count": "[parameters('numberOfInstances')]"
            },
            "dependsOn": [
                "nicLoop"
            ],
            "properties": {
                "availabilitySet": {
                    "id": "[resourceId('Microsoft.Compute/availabilitySets', variables('availabilitySetName'))]"
                },
                "hardwareProfile": {
                    "vmSize": "[parameters('vmSizes')]"
                },
                "osProfile": {
                    "computerName": "[concat('vm', copyIndex())]",
                    "adminUsername": "[parameters('adminUsername')]",
                    "adminPassword": "[parameters('adminPassword')]"
                },
                "storageProfile": {
                    "imageReference": "[variables('imageReference')]",
                    "osDisk": {
                        "createOption": "FromImage"
                    }
                },
                "networkProfile": {
                    "networkInterfaces": [
                        {
                            "id": "[resourceId('Microsoft.Network/networkInterfaces',concat('nic', copyindex()))]"
                        }
                    ]
                }
            }
        }
    ]
}

Please let me know if the template can help you.