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

Performing deployments using ARM with templates

One of the most important features of any computer system is the ability to introduce changes to it seamlessly and in an automatic fashion. When infrastructure is considered, it is especially handy if there is a way to code it. This enables us to replicate it anywhere at any time with a single command. This approach, often abbreviated as Infrastructure-as-Code (IaC), plays a major role in modern applications as it guarantees that all the components are scripted and that no manual work is required to restore them (for example, in the case of disaster recovery).

This section addresses this problem by introducing Azure Resource Manager (ARM) templates, which are JSON files that are used to describe how a service should behave and be configured.

There are multiple ways to prepare an ARM template, which can be reused and modified anytime you want. Before we get started, you have to understand how a typical template is structured. Let's take a look at the following JSON file:

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "",
"parameters": { },
"variables": { },
"functions": [ ],
"resources": [ ],
"outputs": { }
}

As you can see, it contains two metadata fields ($schema and contentVersion) and five sections. Each section is used for a different purpose:

  • parameters: Since each template can be used for different regions, tiers, or configuration settings, there has to be a way you can pass them. This section describes each parameter that can be passed to the template, including its type and the default value.
  • variables: Sometimes, you need to evaluate a value based on the passed parameters (or maybe you just want to avoid duplicates and define it in one place). When using ARM templates, this section can be used for defining values that you can use for other resources. As it is parsed after parameters, you can leverage each value that's passed from the outside of the template.
  • functions: A user-defined function that you can use in the template.
  • resources: The main section in a template. It contains descriptions of the resources you want to provision in Azure. To make things more flexible, you can use values from three other sections: parameters, variables, and functions.
  • outputs: This section can be used to return values from your template. Such a value could be a connection string to a storage account, resource ID, or a VM IP address.
ARM templates leverage the concept of resources managed by Azure Resource Manager. This means that with ARM templates, you can provision any element that is considered a resource in Azure. To be more specific, you can provision both an Azure App Service instance and its settings (called application settings) separately. A resource does not have to be a service, and you can find them in the Azure Marketplace.

Of course, not all sections are required – to make a template valid, it has to contain the following sections:

  • $schema
  • contentVersion (for versioning purposes)
  • resources

All other sections (parameters, variables, functions, and outputs) are optional. A full description of the structure and the syntax can be found at https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-authoring-templates.

Now that you have understood the basics of ARM templates, we can try to prepare some and deploy them. As we mentioned previously, there are a few ways to generate or create such a template – we will give each one a go. To make things easier, we will assume that we want to deploy two storage accounts, with the second one related to the first one.

Now that you understand the theoretical concepts of resource groups, we will focus on writing an actual template and using it. 

主站蜘蛛池模板: 哈巴河县| 丹寨县| 万安县| 固镇县| 宁波市| 嘉荫县| 刚察县| 咸丰县| 洪洞县| 曲麻莱县| 琼中| 淄博市| 太原市| 阳新县| 彩票| 公安县| 高陵县| 盱眙县| 乐至县| 油尖旺区| 阿拉善左旗| 泸水县| 达拉特旗| 大石桥市| 中宁县| 齐河县| 林口县| 临江市| 南澳县| 海盐县| 太湖县| 吉隆县| 崇礼县| 苗栗县| 南乐县| 金湖县| 恭城| 米脂县| 昭通市| 兰考县| 瓦房店市|