官术网_书友最值得收藏!

Writing your first template

Now it's time to focus and create our first ARM template using Visual Studio 2017. Open Visual Studio 2017 and select File | New | Project | Cloud | Azure Resource Group. Provide a Name and Location in New Project dialog box and click on OK:

Select Blank Template and click on OK:

This should create a solution and the MyFirstTemplate project in Visual Studio. It will also create an ARM template file named azureDeploy.json and a template parameters file named azureDeploy.parameters.json. There is also a PowerShell file, Deploy-AzureResourceGroup.ps1, for both creating a resource group and deploying a template in it. We are not going to use it. Readers can go ahead and delete it:

The content of the azuredeploy.json file is the same as shown before; for simplicity's sake, it is shown again:

{

"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",

"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {},
"resources": [],
"outputs": {}

}

If readers try to deploy this template, it will successfully get deployed, however, it would not do anything meaningful at this stage.

Let's add a parameter, variable, resource, and an output to this template so it does something meaningful. It is possible that readers might not be able to understand many sections within this ARM template, but let me assure you that by the time you finish reading Chapter 5IaaS Solutions Using Templates, everything will become crystal clear to you.

This template is responsible for provisioning a new storage account on Azure. The name of the storage account is available as a parameter, the SKU of the storage account is defined in the variables section, and the output consists of the storage name concatenated with the storage SKU.

The entire code listing is shown here:

Let's take a look at each of these elements:

  • Line 2 declares the schema element.
  • Line 3 defines the version of the template.
  • Lines 4—8 define a single parameter named storageAccountName of the string type.
  • Lines 9—11 define a single variable named storageType with the Standard_LRS value.
  • Lines 12—23 define a single storage account resource within the resources array. The name for the resource gets its value from the parameters and syntax. [parameters('storageAccountName')] is an expression that is evaluated at runtime to get a value from the storageAccountName parameter. Similarly, the [variables('storageType')] syntax on line 19 is an expression that is evaluated at runtime to get a value from the strorageType variable. Line 17 has an expression that consists of an out-of-the-box ARM template function, resourceGroup, with the location as its property. It returns the Azure location for the resource group within which the resource is getting provisioned. ARM template expressions and functions will be covered in Chapter 3, Understanding Core Elements of ARM Templates.
  • Lines 24—29 define the outputs section and it consist of single output named storageDetails of the string type. The value is generated at runtime using the concat function, which concatenates the storageAccountName parameter and the strorageType variable together.
主站蜘蛛池模板: 九龙坡区| 兴山县| 凌云县| 越西县| 泌阳县| 铁岭县| 灌云县| 东城区| 聂拉木县| 乐平市| 张北县| 法库县| 西安市| 余姚市| 吉首市| 吉木乃县| 义乌市| 义马市| 金寨县| 铜陵市| 永嘉县| 易门县| 桂平市| 湖南省| 神农架林区| 根河市| 托克托县| 郴州市| 塔城市| 永胜县| 腾冲县| 马龙县| 关岭| 常州市| 奉新县| 新津县| 尚义县| 巴塘县| 水富县| 福鼎市| 武陟县|