- Hands-On Cloud Solutions with Azure
- Greg Leonardo
- 574字
- 2021-06-10 19:44:41
azuredeploy.json
This is the file that contains the code version of the VM being deployed. It is made up of parameters, which are provided or overwritten by the preceding parameters file. The JSON defines three resources: a VNET, a VM, and a NIC resource. Let's look at how the resources in this file are added and how the sections are broken down. To add resources, you just need to right-click on the resource element in Visual Studio, as you can see in the following screenshot:

The parameters are the input to the template and are the values that are provided by the parameters file:
Let's take a look at the following code:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"adminUsername": {
"type": "string",
"metadata": {
"description": "The name of the administrator account of the new VM and domain"
}
},
"adminPassword": {
"type": "securestring",
"metadata": {
"description": "The password for the administrator account of the new VM and domain"
}
},
"PrivateSubnet": {
"type": "string",
"defaultValue": "10.0.1.0/24",
"metadata": { "description": "Private VNet IP Subnet" }
}
},
The variables section is for variables within the template that can leverage functions. As you can see, in the following code, we are using the split function to break apart the PrivateSubnet to help create unique names for our VMs:
"variables": {
"GroupStart": "[split(parameters('PrivateSubnet'), '.')[0]]",
"GroupMain": "[split(parameters('PrivateSubnet'), '.')[1]]",
"GroupNumber": "[split(parameters('PrivateSubnet'), '.')[2]]",
"instWin1": "[concat(variables('GroupMain'),'-',variables('GroupNumber'),'-Win1')]",
"instWin1NIC": "[concat(variables('GroupMain'),'-',variables('GroupNumber'),'-Win1NIC')]",
"NetworkVNetID": "[resourceId('Microsoft.Network/virtualNetworks', 'NetworkVNet')]",
"PrivateSubnetName": "PrivateSubnet",
"PrivateSubnetRef": "[concat(variables('NetworkVNetID'), '/subnets/', variables('PrivateSubnetName'))]"
},
In the resources section, we define the resource the template will deploy. In this scenario, we are deploying VNet, NIC, and VM resources. The VM will use the NIC card to connect to the VNet. The VNet is the virtual network that the VM will use to communicate to other resources deployed on the VNet. The following code explains how the NIC card is built into the ARM template:
"resources": [
{
"apiVersion": "2016-03-30",
"type": "Microsoft.Network/networkInterfaces",
"name": "[variables('instWin1NIC')]",
"location": "[resourceGroup().location]",
"dependsOn": [
"[resourceId('Microsoft.Network/virtualNetworks', 'NetworkVNet')]"
],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"privateIPAllocationMethod": "Static",
"privateIPAddress": "[concat(variables('GroupStart'),'.',variables('GroupMain'),'.',variables('GroupNumber'),'.31')]",
"subnet": {
"id": "[variables('PrivateSubnetRef')]"
}
}
}
]
}
}
Now, let's look at VM resource creation and how we add the NIC resource we created previously to the VM. As you can see, in the following code, the NIC is applied as the network interface resource for the VM:
{
"apiVersion": "2016-04-30-preview",
"type": "Microsoft.Compute/virtualMachines",
"name": "[variables('instWin1')]",
"location": "[resourceGroup().location]",
"dependsOn": [
"[resourceId('Microsoft.Network/networkInterfaces/', variables('instWin1NIC'))]"
],
"properties": {
"hardwareProfile": { "vmSize": "Standard_DS1" },
"osProfile": {
"computerName": "[variables('instWin1')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]"
},
"storageProfile": {
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "2012-R2-Datacenter",
"version": "latest"
},
"osDisk": {
"createOption": "FromImage",
"caching": "ReadWrite"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces',variables('instWin1NIC'))]"
}
]
}
}
}
]
}
As you can see, the ARM template helps us create a repeatable and configurable process. However, let's look at taking things a bit further. One of the biggest things folks realize is that there are other resources like firewalls, routers, and load balancers that are required when you choose to manage your applications in virtual machines. While this may be a choice that you may not be able to avoid, it also requires you to update the OS and Service Packs.
- 工業(yè)機器人技術(shù)及應(yīng)用
- 軟件架構(gòu)設(shè)計
- 網(wǎng)頁編程技術(shù)
- Dreamweaver CS3網(wǎng)頁設(shè)計50例
- Cloud Analytics with Microsoft Azure
- INSTANT Autodesk Revit 2013 Customization with .NET How-to
- 工業(yè)機器人應(yīng)用案例集錦
- Visual Studio 2010 (C#) Windows數(shù)據(jù)庫項目開發(fā)
- 嵌入式Linux系統(tǒng)實用開發(fā)
- INSTANT Adobe Story Starter
- 計算機應(yīng)用基礎(chǔ)實訓(xùn)(職業(yè)模塊)
- 大數(shù)據(jù)素質(zhì)讀本
- Machine Learning with Spark(Second Edition)
- PHP求職寶典
- 基于Quartus Ⅱ的數(shù)字系統(tǒng)Verilog HDL設(shè)計實例詳解