create Azure VM and virtualNetworks with Template

In the toolbar of the Cloud Shell pane, click the Upload/Download files icon, in the drop-down menu, click Upload and upload the files az104-06-vms-template.json, and az104-06-vm-parameters.json into the Cloud Shell home directory.

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmSize": {
"type": "string",
"defaultValue": "Standard_D2s_v3",
"metadata": {
"description": "Virtual machine size"
}
},
"nameSuffix": {
"type": "string",
"allowedValues": [
"0",
"1",
"2"
],
"metadata": {
"description": "Naming suffix"
}
},
"adminUsername": {
"type": "string",
"metadata": {
"description": "Admin username"
}
},
"adminPassword": {
"type": "securestring",
"metadata": {
"description": "Admin password"
}
}
},
"variables": {
"vmName": "[concat('az104-05-vm',parameters('nameSuffix'))]",
"nicName": "[concat('az104-05-nic',parameters('nameSuffix'))]",
"virtualNetworkName": "[concat('az104-05-vnet',parameters('nameSuffix'))]",
"publicIPAddressName": "[concat('az104-05-pip',parameters('nameSuffix'))]",
"nsgName": "[concat('az104-05-nsg',parameters('nameSuffix'))]",
"vnetIpPrefix": "[concat('10.5',parameters('nameSuffix'),'.0.0/22')]",
"subnetIpPrefix": "[concat('10.5',parameters('nameSuffix'),'.0.0/24')]",
"subnetName": "subnet0",
"subnetRef": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('virtualNetworkName'), variables('subnetName'))]",
"computeApiVersion": "2018-06-01",
"networkApiVersion": "2018-08-01"
},
"resources": [
{
"name": "[variables('vmName')]",
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "[variables('computeApiVersion')]",
"location": "[resourceGroup().location]",
"dependsOn": [
"[variables('nicName')]"
],
"properties": {
"osProfile": {
"computerName": "[variables('vmName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]",
"windowsConfiguration": {
"provisionVmAgent": "true"
}
},
"hardwareProfile": {
"vmSize": "[parameters('vmSize')]"
},
"storageProfile": {
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "2019-Datacenter",
"version": "latest"
},
"osDisk": {
"createOption": "fromImage"
},
"dataDisks": []
},
"networkProfile": {
"networkInterfaces": [
{
"properties": {
"primary": true
},
"id": "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]"
}
]
}
}
},
{
"type": "Microsoft.Network/virtualNetworks",
"name": "[variables('virtualNetworkName')]",
"apiVersion": "[variables('networkApiVersion')]",
"location": "[resourceGroup().location]",
"comments": "Virtual Network",
"properties": {
"addressSpace": {
"addressPrefixes": [
"[variables('vnetIpPrefix')]"
]
},
"subnets": [
{
"name": "[variables('subnetName')]",
"properties": {
"addressPrefix": "[variables('subnetIpPrefix')]"
}
}
]
}
},
{
"name": "[variables('nicName')]",
"type": "Microsoft.Network/networkInterfaces",
"apiVersion": "[variables('networkApiVersion')]",
"location": "[resourceGroup().location]",
"comments": "Primary NIC",
"dependsOn": [
"[variables('publicIpAddressName')]",
"[variables('nsgName')]",
"[variables('virtualNetworkName')]"
],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"subnet": {
"id": "[variables('subnetRef')]"
},
"privateIPAllocationMethod": "Dynamic",
"publicIpAddress": {
"id": "[resourceId('Microsoft.Network/publicIpAddresses', variables('publicIpAddressName'))]"
}
}
}
],
"networkSecurityGroup": {
"id": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('nsgName'))]"
}
}
},
{
"name": "[variables('publicIpAddressName')]",
"type": "Microsoft.Network/publicIpAddresses",
"apiVersion": "[variables('networkApiVersion')]",
"location": "[resourceGroup().location]",
"comments": "Public IP for Primary NIC",
"properties": {
"publicIpAllocationMethod": "Dynamic"
}
},
{
"name": "[variables('nsgName')]",
"type": "Microsoft.Network/networkSecurityGroups",
"apiVersion": "[variables('networkApiVersion')]",
"location": "[resourceGroup().location]",
"comments": "Network Security Group (NSG) for Primary NIC",
"properties": {
"securityRules": [
{
"name": "default-allow-rdp",
"properties": {
"priority": 1000,
"sourceAddressPrefix": "*",
"protocol": "Tcp",
"destinationPortRange": "3389",
"access": "Allow",
"direction": "Inbound",
"sourcePortRange": "*",
"destinationAddressPrefix": "*"
}
}
]
}
}
],
"outputs": {}
}
{ "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "vmSize": { "type": "string", "defaultValue": "Standard_D2s_v3", "metadata": { "description": "Virtual machine size" } }, "nameSuffix": { "type": "string", "allowedValues": [ "0", "1", "2" ], "metadata": { "description": "Naming suffix" } }, "adminUsername": { "type": "string", "metadata": { "description": "Admin username" } }, "adminPassword": { "type": "securestring", "metadata": { "description": "Admin password" } } }, "variables": { "vmName": "[concat('az104-05-vm',parameters('nameSuffix'))]", "nicName": "[concat('az104-05-nic',parameters('nameSuffix'))]", "virtualNetworkName": "[concat('az104-05-vnet',parameters('nameSuffix'))]", "publicIPAddressName": "[concat('az104-05-pip',parameters('nameSuffix'))]", "nsgName": "[concat('az104-05-nsg',parameters('nameSuffix'))]", "vnetIpPrefix": "[concat('10.5',parameters('nameSuffix'),'.0.0/22')]", "subnetIpPrefix": "[concat('10.5',parameters('nameSuffix'),'.0.0/24')]", "subnetName": "subnet0", "subnetRef": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('virtualNetworkName'), variables('subnetName'))]", "computeApiVersion": "2018-06-01", "networkApiVersion": "2018-08-01" }, "resources": [ { "name": "[variables('vmName')]", "type": "Microsoft.Compute/virtualMachines", "apiVersion": "[variables('computeApiVersion')]", "location": "[resourceGroup().location]", "dependsOn": [ "[variables('nicName')]" ], "properties": { "osProfile": { "computerName": "[variables('vmName')]", "adminUsername": "[parameters('adminUsername')]", "adminPassword": "[parameters('adminPassword')]", "windowsConfiguration": { "provisionVmAgent": "true" } }, "hardwareProfile": { "vmSize": "[parameters('vmSize')]" }, "storageProfile": { "imageReference": { "publisher": "MicrosoftWindowsServer", "offer": "WindowsServer", "sku": "2019-Datacenter", "version": "latest" }, "osDisk": { "createOption": "fromImage" }, "dataDisks": [] }, "networkProfile": { "networkInterfaces": [ { "properties": { "primary": true }, "id": "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]" } ] } } }, { "type": "Microsoft.Network/virtualNetworks", "name": "[variables('virtualNetworkName')]", "apiVersion": "[variables('networkApiVersion')]", "location": "[resourceGroup().location]", "comments": "Virtual Network", "properties": { "addressSpace": { "addressPrefixes": [ "[variables('vnetIpPrefix')]" ] }, "subnets": [ { "name": "[variables('subnetName')]", "properties": { "addressPrefix": "[variables('subnetIpPrefix')]" } } ] } }, { "name": "[variables('nicName')]", "type": "Microsoft.Network/networkInterfaces", "apiVersion": "[variables('networkApiVersion')]", "location": "[resourceGroup().location]", "comments": "Primary NIC", "dependsOn": [ "[variables('publicIpAddressName')]", "[variables('nsgName')]", "[variables('virtualNetworkName')]" ], "properties": { "ipConfigurations": [ { "name": "ipconfig1", "properties": { "subnet": { "id": "[variables('subnetRef')]" }, "privateIPAllocationMethod": "Dynamic", "publicIpAddress": { "id": "[resourceId('Microsoft.Network/publicIpAddresses', variables('publicIpAddressName'))]" } } } ], "networkSecurityGroup": { "id": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('nsgName'))]" } } }, { "name": "[variables('publicIpAddressName')]", "type": "Microsoft.Network/publicIpAddresses", "apiVersion": "[variables('networkApiVersion')]", "location": "[resourceGroup().location]", "comments": "Public IP for Primary NIC", "properties": { "publicIpAllocationMethod": "Dynamic" } }, { "name": "[variables('nsgName')]", "type": "Microsoft.Network/networkSecurityGroups", "apiVersion": "[variables('networkApiVersion')]", "location": "[resourceGroup().location]", "comments": "Network Security Group (NSG) for Primary NIC", "properties": { "securityRules": [ { "name": "default-allow-rdp", "properties": { "priority": 1000, "sourceAddressPrefix": "*", "protocol": "Tcp", "destinationPortRange": "3389", "access": "Allow", "direction": "Inbound", "sourcePortRange": "*", "destinationAddressPrefix": "*" } } ] } } ], "outputs": {} }
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
      "vmSize": {
        "type": "string",
        "defaultValue": "Standard_D2s_v3",
        "metadata": {
          "description": "Virtual machine size"
        }
      },
      "nameSuffix": {
        "type": "string",
        "allowedValues": [
          "0",
          "1",
          "2"
        ],
        "metadata": {
          "description": "Naming suffix"
        }
      },
      "adminUsername": {
        "type": "string",
        "metadata": {
          "description": "Admin username"
        }
      },
      "adminPassword": {
        "type": "securestring",
        "metadata": {
          "description": "Admin password"
        }
      }
    },
  "variables": {
    "vmName": "[concat('az104-05-vm',parameters('nameSuffix'))]",
    "nicName": "[concat('az104-05-nic',parameters('nameSuffix'))]",
    "virtualNetworkName": "[concat('az104-05-vnet',parameters('nameSuffix'))]",
    "publicIPAddressName": "[concat('az104-05-pip',parameters('nameSuffix'))]",
    "nsgName": "[concat('az104-05-nsg',parameters('nameSuffix'))]",
    "vnetIpPrefix": "[concat('10.5',parameters('nameSuffix'),'.0.0/22')]", 
    "subnetIpPrefix": "[concat('10.5',parameters('nameSuffix'),'.0.0/24')]", 
    "subnetName": "subnet0",
    "subnetRef": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('virtualNetworkName'), variables('subnetName'))]",
    "computeApiVersion": "2018-06-01",
    "networkApiVersion": "2018-08-01"
  },
    "resources": [
        {
            "name": "[variables('vmName')]",
            "type": "Microsoft.Compute/virtualMachines",
            "apiVersion": "[variables('computeApiVersion')]",
            "location": "[resourceGroup().location]",
            "dependsOn": [
                "[variables('nicName')]"
            ],
            "properties": {
                "osProfile": {
                    "computerName": "[variables('vmName')]",
                    "adminUsername": "[parameters('adminUsername')]",
                    "adminPassword": "[parameters('adminPassword')]",
                    "windowsConfiguration": {
                        "provisionVmAgent": "true"
                    }
                },
                "hardwareProfile": {
                    "vmSize": "[parameters('vmSize')]"
                },
                "storageProfile": {
                    "imageReference": {
                        "publisher": "MicrosoftWindowsServer",
                        "offer": "WindowsServer",
                        "sku": "2019-Datacenter",
                        "version": "latest"
                    },
                    "osDisk": {
                        "createOption": "fromImage"
                    },
                    "dataDisks": []
                },
                "networkProfile": {
                    "networkInterfaces": [
                        {
                            "properties": {
                                "primary": true
                            },
                            "id": "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]"
                        }
                    ]
                }
            }
        },
        {
            "type": "Microsoft.Network/virtualNetworks",
            "name": "[variables('virtualNetworkName')]",
            "apiVersion": "[variables('networkApiVersion')]",
            "location": "[resourceGroup().location]",
            "comments": "Virtual Network",
            "properties": {
                "addressSpace": {
                    "addressPrefixes": [
                        "[variables('vnetIpPrefix')]"
                    ]
                },
                "subnets": [
                    {
                        "name": "[variables('subnetName')]",
                        "properties": {
                            "addressPrefix": "[variables('subnetIpPrefix')]"
                        }
                    }
                ]
            }
        },
        {
            "name": "[variables('nicName')]",
            "type": "Microsoft.Network/networkInterfaces",
            "apiVersion": "[variables('networkApiVersion')]",
            "location": "[resourceGroup().location]",
            "comments": "Primary NIC",
            "dependsOn": [
                "[variables('publicIpAddressName')]",
                "[variables('nsgName')]",
                "[variables('virtualNetworkName')]"
            ],
            "properties": {
                "ipConfigurations": [
                    {
                        "name": "ipconfig1",
                        "properties": {
                            "subnet": {
                                "id": "[variables('subnetRef')]"
                            },
                            "privateIPAllocationMethod": "Dynamic",
                            "publicIpAddress": {
                                "id": "[resourceId('Microsoft.Network/publicIpAddresses', variables('publicIpAddressName'))]"
                            }
                        }
                    }
                ],
                "networkSecurityGroup": {
                    "id": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('nsgName'))]"
                }
            }
        },
        {
            "name": "[variables('publicIpAddressName')]",
            "type": "Microsoft.Network/publicIpAddresses",
            "apiVersion": "[variables('networkApiVersion')]",
            "location": "[resourceGroup().location]",
            "comments": "Public IP for Primary NIC",
            "properties": {
                "publicIpAllocationMethod": "Dynamic"
            }
        },
        {
            "name": "[variables('nsgName')]",
            "type": "Microsoft.Network/networkSecurityGroups",
            "apiVersion": "[variables('networkApiVersion')]",
            "location": "[resourceGroup().location]",
            "comments": "Network Security Group (NSG) for Primary NIC",
            "properties": {
                "securityRules": [
                    {
                        "name": "default-allow-rdp",
                        "properties": {
                            "priority": 1000,
                            "sourceAddressPrefix": "*",
                            "protocol": "Tcp",
                            "destinationPortRange": "3389",
                            "access": "Allow",
                            "direction": "Inbound",
                            "sourcePortRange": "*",
                            "destinationAddressPrefix": "*"
                        }
                    }
                ]
            }
        }
    ],
    "outputs": {}
}
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmSize": {
"value": "Standard_D2s_v3"
},
"adminUsername": {
"value": "Student"
},
"adminPassword": {
"value": "Pa55w.rd1234"
}
}
}
{ "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#", "contentVersion": "1.0.0.0", "parameters": { "vmSize": { "value": "Standard_D2s_v3" }, "adminUsername": { "value": "Student" }, "adminPassword": { "value": "Pa55w.rd1234" } } }
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "vmSize": {
            "value": "Standard_D2s_v3"
        },
        "adminUsername": {
            "value": "Student"
        },
        "adminPassword": {
            "value": "Pa55w.rd1234"
        }
    }
}
From the Cloud Shell pane, run the following to create the first resource group that will be hosting the first virtual network and the pair of virtual machines:
$location = 'West US'
$rgName = 'My-RG01' 
New-AzResourceGroup -Name $rgName -Location $location

From the Cloud Shell pane, run the following to create the first virtual network and deploy a pair of virtual machines into it by using the template and parameter files you uploaded:
New-AzResourceGroupDeployment `
  -ResourceGroupName $rgName `
  -TemplateFile $HOME/az104-06-vms-template.json `
  -TemplateParameterFile $HOME/az104-06-vm-parameters.json `
  -AsJob

Leave a Reply

Your email address will not be published. Required fields are marked *