- 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è)機(jī)器人虛擬仿真實(shí)例教程:KUKA.Sim Pro(全彩版)
- 構(gòu)建高質(zhì)量的C#代碼
- 火格局的時(shí)空變異及其在電網(wǎng)防火中的應(yīng)用
- 21天學(xué)通C#
- Windows環(huán)境下32位匯編語言程序設(shè)計(jì)
- 新手學(xué)電腦快速入門
- Visual C++編程全能詞典
- Google SketchUp for Game Design:Beginner's Guide
- Dreamweaver CS6精彩網(wǎng)頁制作與網(wǎng)站建設(shè)
- 機(jī)器人人工智能
- 工業(yè)機(jī)器人入門實(shí)用教程
- 單片機(jī)硬件接口電路及實(shí)例解析
- 淘寶網(wǎng)店頁面設(shè)計(jì)、布局、配色、裝修一本通
- 工業(yè)機(jī)器人設(shè)計(jì)與實(shí)例詳解
- 小數(shù)據(jù)之美:精準(zhǔn)捕捉未來的商業(yè)小趨勢