Understanding the resources format

In this section of the template we define what we are deploying or updating. Usually we define the resources and their configuration values here. The configuration values could be defined within this section or you could reference values that are already added in the parameter or variables section.

The basic resource structure looks as follows:

"resources": [ 
 { 
  "apiVersion": "apiVersion of Resourece", 
  "type": "ResoureceProviderNamespace/ResoureceTypeName", 
  "name": "Name Of Resource", 
  "location": "Location Of Resource", 
  "tags": "Name value pairs" 
  "dependsOn": [ 
    "Array of Related Resource" 
], 
"properties": "settings of the resource", 
"resources": [ 
"Array of dependint Resources" 
    ] 
 } 
], 

The elements are used as follows:

Element name

Mandatory

Description

apiVersion

Yes

API version that supports this resource.

Type

Yes

Defines the type of resource.

Name

Yes

Name of the resource

Location

No

Resources providers are available at Azure Stack (local) or at Microsoft Azure locations like West Europe. This element defines which to call.

Tags

No

Tags could be used to group resources. Then if you want to delete or update a certain group you could select all of the resources using the defined tag.

dependsOn

No

Defines dependencies of resources. Configuring the virtual NIC with IP, gateway and so on depends on the availability of a virtual NIC when the VM is created. Therefore, it defines the deployment order as a virtual NIC is required first before configuring it. Another example is storage account. If no storage account exists, it must be created first before deploying the VM to it. If no dependsOn is defined resources will be created in parallel.

Properties

No

Resource specific configuration settings.

Resources

No

Defines child resources that depend on the resources that are currently defined.

 

Let us look at two examples. The first one is the resource to create a vNIC for a VM. In type, we define that a network interface should be created. The name of this vNIC is already defined in the variable section with a value of nicName. Another important part within Resources is the depondsOn elements. As mentioned before, this allows you to define dependencies during deployment as resources are created in parallel for faster deployment. Therefore, to create a vNIC for a VM at least the virtual network to which the VM should be connected to must exist prior to configuration of the vNIC itself The resource section for the network interface looks as follows:

  "resources": [ 
{ 
      "apiVersion": "2015-05-01-preview", 
      "type": "Microsoft.Network/networkInterfaces", 
      "name": "[variables('nicName')]", 
      "location": "[variables('location')]", 
      "dependsOn": [ 
        "[concat('Microsoft.Network/publicIPAdresses/',
variables('publicIPnicsName'))]", "[concat('Microsoft.Network/virtualNetworks/',
variables('virtualNetworkName'))]" ], ],

Also in the resource section we will add the resource provider compute to configure our virtual machine. All the parameters and variables defined before will be used in this section to configure the settings of our virtual machine. In the parameter section we defined vmname. In the resource section we just referenced name to the previous defined parameter vmName. As another example we will use the value storageAccountName we defined in the parameter section and use this parameter to place our VHD into this existing storage account. Therefore, the resource provider will look as follows:

    "resources": [ 
{ 
      "apiVersion": "2015-05-01-preview", 
      "type": "Microsoft.Compute/virtualMachines", 
      "name": "[parameters('vmName')]", 
      "location": "[variables('location')]", 
      "dependsOn": [ 
        "[concat('Microsoft.Network/networkInterfaces/',
variables('nicName'))]" ], "properties": { "hardwareProfile": { "vmSize": "[parameters('vmSize')]" }, "osProfile": { "computername": "[parameters('vmName')]", "adminUsername": "[parameters('adminUsername')]", "adminPassword": "[parameters('adminPassword')]", "windowsConfiguration": "{ "enableAutomaticUpdates": true, "provisionVMAgent": true } }, "storageProfile": { "imageReference": { "publisher": "[variables('osType').publisher]", "offer": "[variables('osType').offer]", "sku": "[ variables('osType').sku]", "version": "latest" }, "osDisk": { "createOption": "fromImage", "name":"[parameters('vmName')]", "vhd": { "uri": "[concat('http://',parameters('storageAccountName'),'.' parameters('storageendpoint'),'/',parameters('storageAccountContainerName'),'/',variables('OSDiskName'),'.vhd')]" }, "caching": "ReadWrite" } } ],
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.240.75