arm-template-helper

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

ARM Template Helper

ARM 模板助手

Quick Start

快速开始

Create and validate Azure Resource Manager templates for infrastructure as code deployments.
创建并验证用于基础设施即代码部署的Azure Resource Manager模板。

Instructions

操作步骤

Step 1: Create ARM template structure

步骤1:创建ARM模板结构

json
{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]"
    }
  },
  "variables": {},
  "resources": [],
  "outputs": {}
}
json
{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]"
    }
  },
  "variables": {},
  "resources": [],
  "outputs": {}
}

Step 2: Add resources

步骤2:添加资源

json
"resources": [
  {
    "type": "Microsoft.Storage/storageAccounts",
    "apiVersion": "2021-04-01",
    "name": "[parameters('storageAccountName')]",
    "location": "[parameters('location')]",
    "sku": {
      "name": "Standard_LRS"
    },
    "kind": "StorageV2"
  }
]
json
"resources": [
  {
    "type": "Microsoft.Storage/storageAccounts",
    "apiVersion": "2021-04-01",
    "name": "[parameters('storageAccountName')]",
    "location": "[parameters('location')]",
    "sku": {
      "name": "Standard_LRS"
    },
    "kind": "StorageV2"
  }
]

Step 3: Validate template

步骤3:验证模板

bash
undefined
bash
undefined

Validate ARM template

Validate ARM template

az deployment group validate
--resource-group myResourceGroup
--template-file template.json
--parameters parameters.json
az deployment group validate
--resource-group myResourceGroup
--template-file template.json
--parameters parameters.json

Test deployment (what-if)

Test deployment (what-if)

az deployment group what-if
--resource-group myResourceGroup
--template-file template.json
undefined
az deployment group what-if
--resource-group myResourceGroup
--template-file template.json
undefined

Step 4: Deploy template

步骤4:部署模板

bash
undefined
bash
undefined

Deploy ARM template

Deploy ARM template

az deployment group create
--resource-group myResourceGroup
--template-file template.json
--parameters parameters.json
undefined
az deployment group create
--resource-group myResourceGroup
--template-file template.json
--parameters parameters.json
undefined

Best Practices

最佳实践

  1. Use parameters for configurable values
  2. Use variables for computed values
  3. Add outputs for important resource properties
  4. Use dependsOn for resource dependencies
  5. Implement proper naming conventions
  6. Add tags for resource organization
  7. Use linked templates for modularity
  8. Validate before deploying
  1. 为可配置值使用参数
  2. 为计算值使用变量
  3. 为重要资源属性添加输出
  4. 为资源依赖项使用dependsOn
  5. 实施规范的命名约定
  6. 添加标签以组织资源
  7. 使用链接模板实现模块化
  8. 部署前先进行验证