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

Writing a template from scratch

Conceptually, the easiest way to generate an ARM template is to write our very own. While, initially, it is pretty easy, you will probably reconsider your approach after a while. When your infrastructure contains tens of components, maintaining a JSON file with over 1,000 lines may be really painful. Nonetheless, this is one of the options and we should cover it so that you have the full picture of all the available options.

In the following link, you can view all the resources that are managed by ARM and their references: https://docs.microsoft.com/en-us/azure/templates/microsoft.aad/allversions. Each resource belongs to a particular namespace (so if you search for Storage Account, you will go to the Storage section). ARM also maintains more than one version of its API, which is why you can select from multiple available APIs.

Since we are about to create a brand-new piece of storage, it seems like a good idea to use the most recent version. The minimal (containing only required fields) version of the storage account resource for version 2019-06-01 looks like this:

{
  "name": "<string>",
  "type": "Microsoft.Storage/storageAccounts",
  "apiVersion": "2019-04-01",
  "sku": {
    "name": "Standard_LRS"
  },
  "kind": "Storage",
  "location": "<string>",
"properties" {} }

Now, let's check what the full template containing the aforementioned storage accounts would look like. Go and check it out at https://gist.github.com/kamil-mrzyglod/7b868e6a892cba008b7a909a1baabf43.

In the presented template, the second storage account is linked to the first one with the dependsOn property. This property is used to define identifiers of resources that have to be deployed before this particular one. This is especially helpful when deploying resources that rely on connection strings or other parameters that have to be injected into a configuration.

There is no guarantee regarding the order of deployments performed by Azure Resource Manager. This is why you should always use the dependsOn  property to avoid conflicts during deployments.

In the preceding example, we used a special function named resourceId. It takes two parameters – the namespace and the resource name. Once it has been evaluated, it returns the full resource identifier, which uniquely defines the relationship.

This section should have helped you understand some of the common concepts of writing ARM templates such as structure, syntax, and use cases. However, writing a template from scratch is not always necessary. The next section will show you how you can export a template with a single click.

主站蜘蛛池模板: 虎林市| 上杭县| 翁牛特旗| 鄄城县| 石台县| 渑池县| 商城县| 湾仔区| 海南省| 分宜县| 大荔县| 泰和县| 咸阳市| 堆龙德庆县| 东海县| 长丰县| 平武县| 眉山市| 资源县| 定安县| 监利县| 汕头市| 望城县| 商都县| 河池市| 克什克腾旗| 仙桃市| 石嘴山市| 封丘县| 运城市| 玉林市| 安达市| 永兴县| 克什克腾旗| 锦屏县| 南汇区| 贵溪市| 西华县| 小金县| 聂荣县| 黄山市|