您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

了解 Azure 资源管理器模板的结构和语法Understand the structure and syntax of Azure Resource Manager templates

本文介绍 Azure 资源管理器模板的结构。This article describes the structure of an Azure Resource Manager template. 演示了模板的不同部分,以及可在相应部分使用的属性。It presents the different sections of a template and the properties that are available in those sections. 模板中包含可用于为部署构造值的 JSON 和表达式。The template consists of JSON and expressions that you can use to construct values for your deployment. 有关创建模板的分步教程,请参阅创建第一个 Azure 资源管理器模板For a step-by-step tutorial on creating a template, see Create your first Azure Resource Manager template.

模板格式Template format

使用最简单的结构时,模板包含以下元素:In its simplest structure, a template contains the following elements:

{
    "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "",
    "parameters": {  },
    "variables": {  },
    "resources": [  ],
    "outputs": {  }
}
元素名称Element name 必选Required 说明Description
$schema$schema Yes 描述模板语言版本的 JSON 架构文件所在的位置。Location of the JSON schema file that describes the version of the template language. 使用上一示例中所示的 URL。Use the URL shown in the preceding example.
contentVersioncontentVersion Yes 模板的版本(例如 1.0.0.0)。Version of the template (such as 1.0.0.0). 可为此元素提供任意值。You can provide any value for this element. 使用模板部署资源时,此值可用于确保使用正确的模板。When deploying resources using the template, this value can be used to make sure that the right template is being used.
参数parameters No 执行部署以自定义资源部署时提供的值。Values that are provided when deployment is executed to customize resource deployment.
variablesvariables No 在模板中用作 JSON 片段以简化模板语言表达式的值。Values that are used as JSON fragments in the template to simplify template language expressions.
资源resources Yes 已在资源组中部署或更新的资源类型。Resource types that are deployed or updated in a resource group.
outputsoutputs No 部署后返回的值。Values that are returned after deployment.

每个元素均包含可设置的属性。Each element contains properties you can set. 下例包含一个模板的完整语法:The following example contains the full syntax for a template:

{
    "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "",
    "parameters": {  
        "<parameter-name>" : {
            "type" : "<type-of-parameter-value>",
            "defaultValue": "<default-value-of-parameter>",
            "allowedValues": [ "<array-of-allowed-values>" ],
            "minValue": <minimum-value-for-int>,
            "maxValue": <maximum-value-for-int>,
            "minLength": <minimum-length-for-string-or-array>,
            "maxLength": <maximum-length-for-string-or-array-parameters>,
            "metadata": {
                "description": "<description-of-the parameter>" 
            }
        }
    },
    "variables": {
        "<variable-name>": "<variable-value>",
        "<variable-object-name>": {
            <variable-complex-type-value>
        },
        "<variable-object-name>": {
            "copy": [
                {
                    "name": "<name-of-array-property>",
                    "count": <number-of-iterations>,
                    "input": {
                        <properties-to-repeat>
                    }
                }
            ]
        },
        "copy": [
            {
                "name": "<variable-array-name>",
                "count": <number-of-iterations>,
                "input": {
                    <properties-to-repeat>
                }
            }
        ]
    },
    "resources": [
      {
          "condition": "<boolean-value-whether-to-deploy>",
          "apiVersion": "<api-version-of-resource>",
          "type": "<resource-provider-namespace/resource-type-name>",
          "name": "<name-of-the-resource>",
          "location": "<location-of-resource>",
          "tags": {
              "<tag-name1>": "<tag-value1>",
              "<tag-name2>": "<tag-value2>"
          },
          "comments": "<your-reference-notes>",
          "copy": {
              "name": "<name-of-copy-loop>",
              "count": "<number-of-iterations>",
              "mode": "<serial-or-parallel>",
              "batchSize": "<number-to-deploy-serially>"
          },
          "dependsOn": [
              "<array-of-related-resource-names>"
          ],
          "properties": {
              "<settings-for-the-resource>",
              "copy": [
                  {
                      "name": ,
                      "count": ,
                      "input": {}
                  }
              ]
          },
          "resources": [
              "<array-of-child-resources>"
          ]
      }
    ],
    "outputs": {
        "<outputName>" : {
            "type" : "<type-of-output-value>",
            "value": "<output-value-expression>"
        }
    }
}

本文稍后将更详细地介绍模板的各个节。This article describes the sections of the template in greater detail.

表达式和函数Expressions and functions

模板的基本语法为 JSON。The basic syntax of the template is JSON. 但是,表达式和函数扩展了模板中可用的 JSON 值。However, expressions and functions extend the JSON values available within the template. 表达式在 JSON 字符串文本中编写,其中第一个和最后一个字符分别是 [] 括号。Expressions are written within JSON string literals whose first and last characters are the brackets: [ and ], respectively. 部署模板时会计算表达式的值。The value of the expression is evaluated when the template is deployed. 尽管编写为字符串文本,但表达式的计算结果可以是不同的 JSON 类型,例如数组或整数,具体取决于实际的表达式。While written as a string literal, the result of evaluating the expression can be of a different JSON type, such as an array or integer, depending on the actual expression. 要使用一个括号 [ 在开头括住文本字符串但不将其解释为表达式,请额外添加一个括号,使字符串以 [[ 开头。To have a literal string start with a bracket [, but not have it interpreted as an expression, add an extra bracket to start the string with [[.

通常,会将表达式与函数一起使用,以执行用于配置部署的操作。Typically, you use expressions with functions to perform operations for configuring the deployment. 如同在 JavaScript 中一样,函数调用的格式为 functionName(arg1,arg2,arg3)Just like in JavaScript, function calls are formatted as functionName(arg1,arg2,arg3). 使用点和 [index] 运算符引用属性。You reference properties by using the dot and [index] operators.

以下示例演示如何在构造值时使用一些函数:The following example shows how to use several functions when constructing values:

"variables": {
    "location": "[resourceGroup().location]",
    "usernameAndPassword": "[concat(parameters('username'), ':', parameters('password'))]",
    "authorizationHeader": "[concat('Basic ', base64(variables('usernameAndPassword')))]"
}

有关模板函数的完整列表,请参阅 Azure 资源管理器模板函数For the full list of template functions, see Azure Resource Manager template functions.

parametersParameters

在模板的 parameters 节中,可以指定在部署资源时能够输入的值。In the parameters section of the template, you specify which values you can input when deploying the resources. 提供针对特定环境(例如开发、测试和生产环境)定制的参数值可以自定义部署。These parameter values enable you to customize the deployment by providing values that are tailored for a particular environment (such as dev, test, and production). 无需在模板中提供参数,但如果没有参数,模板始终部署具有相同名称、位置和属性的相同资源。You do not have to provide parameters in your template, but without parameters your template would always deploy the same resources with the same names, locations, and properties.

使用以下结构定义参数:You define parameters with the following structure:

"parameters": {
    "<parameter-name>" : {
        "type" : "<type-of-parameter-value>",
        "defaultValue": "<default-value-of-parameter>",
        "allowedValues": [ "<array-of-allowed-values>" ],
        "minValue": <minimum-value-for-int>,
        "maxValue": <maximum-value-for-int>,
        "minLength": <minimum-length-for-string-or-array>,
        "maxLength": <maximum-length-for-string-or-array-parameters>,
        "metadata": {
            "description": "<description-of-the parameter>" 
        }
    }
}
元素名称Element name 必选Required 说明Description
parameterNameparameterName Yes 参数的名称。Name of the parameter. 必须是有效的 JavaScript 标识符。Must be a valid JavaScript identifier.
typetype Yes 参数值的类型。Type of the parameter value. 请参阅允许类型的列表(此表后面)。See the list of allowed types after this table.
defaultValuedefaultValue No 参数的默认值,如果没有为参数提供任何值。Default value for the parameter, if no value is provided for the parameter.
allowedValuesallowedValues No 用来确保提供正确值的参数的允许值数组。Array of allowed values for the parameter to make sure that the right value is provided.
minValueminValue No int 类型参数的最小值,此值是包容性的。The minimum value for int type parameters, this value is inclusive.
maxValuemaxValue No int 类型参数的最大值,此值是包容性的。The maximum value for int type parameters, this value is inclusive.
minLengthminLength No string、secureString 和 array 类型参数的最小长度,此值是包容性的。The minimum length for string, secureString, and array type parameters, this value is inclusive.
maxLengthmaxLength No string、secureString 和 array 类型参数的最大长度,此值是包容性的。The maximum length for string, secureString, and array type parameters, this value is inclusive.
descriptiondescription No 通过门户向用户显示的参数的说明。Description of the parameter that is displayed to users through the portal.

允许的类型和值是:The allowed types and values are:

  • stringstring
  • secureStringsecureString
  • intint
  • boolbool
  • objectobject
  • secureObjectsecureObject
  • arrayarray

要将某个参数指定为可选,请提供 defaultValue(可以为空字符串)。To specify a parameter as optional, provide a defaultValue (can be an empty string).

如果在模板中指定的参数名称与部署模板时所用命令中的参数匹配,则可能会对提供的值造成混淆。If you specify a parameter name in your template that matches a parameter in the command to deploy the template, there is potential ambiguity about the values you provide. Resource Manager 解决此混淆问题的方式是将后缀 FromTemplate 添加到模板参数。Resource Manager resolves this confusion by adding the postfix FromTemplate to the template parameter. 例如,如果在模板中包括一个名为“ResourceGroupName”的参数,则该参数会与 New-AzureRmResourceGroupDeployment cmdlet 中的“ResourceGroupName”参数冲突。For example, if you include a parameter named ResourceGroupName in your template, it conflicts with the ResourceGroupName parameter in the New-AzureRmResourceGroupDeployment cmdlet. 在部署期间,系统会提示用户提供 ResourceGroupNameFromTemplate 的值。During deployment, you are prompted to provide a value for ResourceGroupNameFromTemplate. 通常,为避免此类混乱,不应按部署操作所用的参数名称命令参数。In general, you should avoid this confusion by not naming parameters with the same name as parameters used for deployment operations.

备注

所有密码、密钥和其他机密信息应使用 secureString 类型。All passwords, keys, and other secrets should use the secureString type. 要将敏感数据传入 JSON 对象,请使用 secureObject 类型。If you pass sensitive data in a JSON object, use the secureObject type. 部署资源后,无法读取 secureString 或 secureObject 类型的模板参数。Template parameters with secureString or secureObject types cannot be read after resource deployment.

例如,部署历史记录中的以下条目会显示字符串和对象的值,但不会显示 secureString 和 secureObject 的值。For example, the following entry in the deployment history shows the value for a string and object but not for secureString and secureObject.

显示部署值

以下示例演示如何定义参数:The following example shows how to define parameters:

"parameters": {
    "siteName": {
        "type": "string",
        "defaultValue": "[concat('site', uniqueString(resourceGroup().id))]"
    },
    "hostingPlanName": {
        "type": "string",
        "defaultValue": "[concat(parameters('siteName'),'-plan')]"
    },
    "skuName": {
        "type": "string",
        "defaultValue": "F1",
        "allowedValues": [
          "F1",
          "D1",
          "B1",
          "B2",
          "B3",
          "S1",
          "S2",
          "S3",
          "P1",
          "P2",
          "P3",
          "P4"
        ]
    },
    "skuCapacity": {
        "type": "int",
        "defaultValue": 1,
        "minValue": 1
    }
}

若要了解如何在部署过程中输入参数值,请参阅使用 Azure 资源管理器模板部署应用程序For how to input the parameter values during deployment, see Deploy an application with Azure Resource Manager template.

变量Variables

在 variables 节中构造可在整个模板中使用的值。In the variables section, you construct values that can be used throughout your template. 不需要定义变量,但使用变量可以减少复杂的表达式,从而简化模板。You do not need to define variables, but they often simplify your template by reducing complex expressions.

使用以下结构定义变量:You define variables with the following structure:

"variables": {
    "<variable-name>": "<variable-value>",
    "<variable-name>": { 
        <variable-complex-type-value> 
    }
}

以下示例演示如何定义从两个参数值构造出的变量:The following example shows how to define a variable that is constructed from two parameter values:

"variables": {
    "connectionString": "[concat('Name=', parameters('username'), ';Password=', parameters('password'))]"
}

下一个示例演示一个属于复杂的 JSON 类型的变量,以及从其他变量构造出的变量:The next example shows a variable that is a complex JSON type, and variables that are constructed from other variables:

"parameters": {
    "environmentName": {
        "type": "string",
        "allowedValues": [
          "test",
          "prod"
        ]
    }
},
"variables": {
    "environmentSettings": {
        "test": {
            "instancesSize": "Small",
            "instancesCount": 1
        },
        "prod": {
            "instancesSize": "Large",
            "instancesCount": 4
        }
    },
    "currentEnvironmentSettings": "[variables('environmentSettings')[parameters('environmentName')]]",
    "instancesSize": "[variables('currentEnvironmentSettings').instancesSize]",
    "instancesCount": "[variables('currentEnvironmentSettings').instancesCount]"
}

你可以使用 copy 语法创建带有多个元素数组的变量。You can use the copy syntax to create a variable with an array of multiple elements. 为元素数量提供一个数字。You provide a count for the number of elements. 每个元素的属性都包含在 input 对象中。Each element contains the properties within the input object. 你可以在变量中使用 copy,或用其创建变量。You can use copy either within a variable or to create the variable. 下例说明了这两种方法:Both approaches are shown in the following example:

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {},
  "variables": {
    "disk-array-on-object": {
      "copy": [
        {
          "name": "disks",
          "count": 5,
          "input": {
            "name": "[concat('myDataDisk', copyIndex('disks', 1))]",
            "diskSizeGB": "1",
            "diskIndex": "[copyIndex('disks')]"
          }
        }
      ]
    },
    "copy": [
      {
        "name": "disks-top-level-array",
        "count": 5,
        "input": {
          "name": "[concat('myDataDisk', copyIndex('disks-top-level-array', 1))]",
          "diskSizeGB": "1",
          "diskIndex": "[copyIndex('disks-top-level-array')]"
        }
      }
    ]
  },
  "resources": [],
  "outputs": {
    "exampleObject": {
      "value": "[variables('disk-array-on-object')]",
      "type": "object"
    },
    "exampleArrayOnObject": {
      "value": "[variables('disk-array-on-object').disks]",
      "type" : "array"
    },
    "exampleArray": {
      "value": "[variables('disks-top-level-array')]",
      "type" : "array"
    }
  }
}

使用 copy 创建变量时,还可以指定多个对象。You can also specify more than one object when using copy to create variables. 以下示例将两个数组定义为变量。The following example defines two arrays as variables. 一个数组名为 disks-top-level-array,包含五个元素。One is named disks-top-level-array and has five elements. 另一个数组名为 a-different-array,包含三个元素。The other is named a-different-array and has three elements.

"variables": {
    "copy": [
        {
            "name": "disks-top-level-array",
            "count": 5,
            "input": {
                "name": "[concat('oneDataDisk', copyIndex('disks-top-level-array', 1))]",
                "diskSizeGB": "1",
                "diskIndex": "[copyIndex('disks-top-level-array')]"
            }
        },
        {
            "name": "a-different-array",
            "count": 3,
            "input": {
                "name": "[concat('twoDataDisk', copyIndex('a-different-array', 1))]",
                "diskSizeGB": "1",
                "diskIndex": "[copyIndex('a-different-array')]"
            }
        }
    ]
},

资源Resources

在 resources 节,可以定义部署或更新的资源。In the resources section, you define the resources that are deployed or updated. 本部分可能比较复杂,因为必须了解所部署类型才能提供正确的值。This section can get complicated because you must understand the types you are deploying to provide the right values. 有关需要设置的特定资源值(apiVersion、type 和 properties),请参阅在 Azure 资源管理器模板中定义资源For the resource-specific values (apiVersion, type, and properties) that you need to set, see Define resources in Azure Resource Manager templates.

使用以下结构定义资源:You define resources with the following structure:

"resources": [
  {
      "condition": "<boolean-value-whether-to-deploy>",
      "apiVersion": "<api-version-of-resource>",
      "type": "<resource-provider-namespace/resource-type-name>",
      "name": "<name-of-the-resource>",
      "location": "<location-of-resource>",
      "tags": {
          "<tag-name1>": "<tag-value1>",
          "<tag-name2>": "<tag-value2>"
      },
      "comments": "<your-reference-notes>",
      "copy": {
          "name": "<name-of-copy-loop>",
          "count": "<number-of-iterations>",
          "mode": "<serial-or-parallel>",
          "batchSize": "<number-to-deploy-serially>"
      },
      "dependsOn": [
          "<array-of-related-resource-names>"
      ],
      "properties": {
          "<settings-for-the-resource>",
          "copy": [
              {
                  "name": ,
                  "count": ,
                  "input": {}
              }
          ]
      },
      "resources": [
          "<array-of-child-resources>"
      ]
  }
]
元素名称Element name 必选Required 说明Description
条件condition No 指示是否部署资源的布尔值。Boolean value that indicates whether the resource is deployed.
apiVersionapiVersion Yes 用于创建资源的 REST API 版本。Version of the REST API to use for creating the resource.
typetype Yes 资源的类型。Type of the resource. 此值是资源提供程序的命名空间和资源类型(例如 Microsoft.Storage/storageAccounts)的组合。This value is a combination of the namespace of the resource provider and the resource type (such as Microsoft.Storage/storageAccounts).
名称name Yes 资源的名称。Name of the resource. 该名称必须遵循 RFC3986 中定义的 URI 构成部分限制。The name must follow URI component restrictions defined in RFC3986. 此外,向第三方公开资源名称的 Azure 服务会验证名称,以确保它不是尝试窃取另一个身份。In addition, Azure services that expose the resource name to outside parties validate the name to make sure it is not an attempt to spoof another identity.
locationlocation 多种多样Varies 提供的资源支持的地理位置。Supported geo-locations of the provided resource. 可以选择任何可用位置,但通常最好选取一个接近用户的位置。You can select any of the available locations, but typically it makes sense to pick one that is close to your users. 通常,在同一区域放置彼此交互的资源也很有用。Usually, it also makes sense to place resources that interact with each other in the same region. 大多数资源类型需要一个位置,但某些类型 (如角色分配)不需要位置。Most resource types require a location, but some types (such as a role assignment) do not require a location. 请参阅在 Azure 资源管理器模板中设置资源位置See Set resource location in Azure Resource Manager templates.
标记tags No 与资源关联的标记。Tags that are associated with the resource. 请参阅标记 Azure 资源管理器模板中的资源See Tag resources in Azure Resource Manager templates.
注释comments No 用于描述模板中资源的注释Your notes for documenting the resources in your template
复制copy No 需要多个实例时应创建的资源数。If more than one instance is needed, the number of resources to create. 默认模式为并行。The default mode is parallel. 在不想同时部署所有资源时,请指定为串行模式。Specify serial mode when you do not want all or the resources to deploy at the same time. 有关详细信息,请参阅在 Azure 资源管理器中创建多个资源实例For more information, see Create multiple instances of resources in Azure Resource Manager.
dependsOndependsOn No 必须在部署此资源前部署的资源。Resources that must be deployed before this resource is deployed. Resource Manager 评估资源之间的依赖关系,并根据正确顺序进行部署。Resource Manager evaluates the dependencies between resources and deploys them in the correct order. 如果资源互不依赖,则会并行部署资源。When resources are not dependent on each other, they are deployed in parallel. 该值可以是资源名称或资源唯一标识符的逗号分隔列表。The value can be a comma-separated list of a resource names or resource unique identifiers. 仅列出在此模板中部署的资源。Only list resources that are deployed in this template. 此模板中未定义的资源必须已存在。Resources that are not defined in this template must already exist. 避免添加不必要的依赖项,因为这些依赖项可能会降低部署速度并创建循环依赖项。Avoid adding unnecessary dependencies as they can slow your deployment and create circular dependencies. 有关设置依赖项的指导,请参阅在 Azure 资源管理器模板中定义依赖项For guidance on setting dependencies, see Defining dependencies in Azure Resource Manager templates.
propertiesproperties No 特定于资源的配置设置。Resource-specific configuration settings. properties 的值与创建资源时,在 REST API 操作(PUT 方法)的请求正文中提供的值相同。The values for the properties are the same as the values you provide in the request body for the REST API operation (PUT method) to create the resource. 还可以指定副本数组,以创建一个属性的多个实例。You can also specify a copy array to create multiple instances of a property. 有关详细信息,请参阅在 Azure 资源管理器中创建多个资源实例For more information, see Create multiple instances of resources in Azure Resource Manager.
资源resources No 依赖于所定义的资源的子资源。Child resources that depend on the resource being defined. 只能提供父资源的架构允许的资源类型。Only provide resource types that are permitted by the schema of the parent resource. 子资源的完全限定类型包含父资源类型,例如 Microsoft.Web/sites/extensionsThe fully qualified type of the child resource includes the parent resource type, such as Microsoft.Web/sites/extensions. 不隐式表示对父资源的依赖。Dependency on the parent resource is not implied. 必须显式定义该依赖关系。You must explicitly define that dependency.

resources 节包含要部署的资源数组。The resources section contains an array of the resources to deploy. 在每个资源内,还可以定义子资源数组。Within each resource, you can also define an array of child resources. 因此,resources 节的结构可能类似于:Therefore, your resources section could have a structure like:

"resources": [
  {
      "name": "resourceA",
  },
  {
      "name": "resourceB",
      "resources": [
        {
            "name": "firstChildResourceB",
        },
        {   
            "name": "secondChildResourceB",
        }
      ]
  },
  {
      "name": "resourceC",
  }
]

有关定义子资源的详细信息,请参阅在 Resource Manager 模板中设置子资源的名称和类型For more information about defining child resources, see Set name and type for child resource in Resource Manager template.

“条件”元素指定是否部署资源。The condition element specifies whether the resource is deployed. 此元素的值解析为 true 或 false。The value for this element resolves to true or false. 例如,若要指定是否部署新的存储帐户,请使用:For example, to specify whether a new storage account is deployed, use:

{
    "condition": "[equals(parameters('newOrExisting'),'new')]",
    "type": "Microsoft.Storage/storageAccounts",
    "name": "[variables('storageAccountName')]",
    "apiVersion": "2017-06-01",
    "location": "[resourceGroup().location]",
    "sku": {
        "name": "[variables('storageAccountType')]"
    },
    "kind": "Storage",
    "properties": {}
}

有关使用新资源或现有资源的示例,请参阅新的或现有的条件模板For an example of using a new or existing resource, see New or existing condition template.

若要指定是使用密码还是 SSH 密钥来部署虚拟机,请在模板中定义两个虚拟机版本,并使用“条件”来区分使用情况。To specify whether a virtual machine is deployed with a password or SSH key, define two versions of the virtual machine in your template and use condition to differentiate usage. 传递参数,其指定部署哪种方案。Pass a parameter that specifies which scenario to deploy.

{
    "condition": "[equals(parameters('passwordOrSshKey'),'password')]",
    "apiVersion": "2016-03-30",
    "type": "Microsoft.Compute/virtualMachines",
    "name": "[concat(variables('vmName'),'password')]",
    "properties": {
        "osProfile": {
            "computerName": "[variables('vmName')]",
            "adminUsername": "[parameters('adminUsername')]",
            "adminPassword": "[parameters('adminPassword')]"
        },
        ...
    },
    ...
},
{
    "condition": "[equals(parameters('passwordOrSshKey'),'sshKey')]",
    "apiVersion": "2016-03-30",
    "type": "Microsoft.Compute/virtualMachines",
    "name": "[concat(variables('vmName'),'ssh')]",
    "properties": {
        "osProfile": {
            "linuxConfiguration": {
                "disablePasswordAuthentication": "true",
                "ssh": {
                    "publicKeys": [
                        {
                            "path": "[variables('sshKeyPath')]",
                            "keyData": "[parameters('adminSshKey')]"
                        }
                    ]
                }
            }
        },
        ...
    },
    ...
}

有关使用密码或 SSH 密钥部署虚拟机的示例,请参阅用户名或 SSH 条件模板For an example of using a password or SSH key to deploy virtual machine, see Username or SSH condition template.

OutputsOutputs

在 Outputs 节中,可以指定从部署返回的值。In the Outputs section, you specify values that are returned from deployment. 例如,可能会返回用于访问已部署资源的 URI。For example, you could return the URI to access a deployed resource.

以下示例演示了输出定义的结构:The following example shows the structure of an output definition:

"outputs": {
    "<outputName>" : {
        "type" : "<type-of-output-value>",
        "value": "<output-value-expression>"
    }
}
元素名称Element name 必选Required 说明Description
outputNameoutputName Yes 输出值的名称。Name of the output value. 必须是有效的 JavaScript 标识符。Must be a valid JavaScript identifier.
typetype Yes 输出值的类型。Type of the output value. 输出值支持的类型与模板输入参数相同。Output values support the same types as template input parameters.
valuevalue Yes 评估并作为输出值返回的模板语言表达式。Template language expression that is evaluated and returned as output value.

以下示例演示了 Outputs 节中返回的值。The following example shows a value that is returned in the Outputs section.

"outputs": {
    "siteUri" : {
        "type" : "string",
        "value": "[concat('http://',reference(resourceId('Microsoft.Web/sites', parameters('siteName'))).hostNames[0])]"
    }
}

有关如何处理输出的详细信息,请参阅在 Azure 资源管理器模板中共享状态For more information about working with output, see Sharing state in Azure Resource Manager templates.

模板限制Template limits

将模板大小限制为 1 MB 以内,每个参数文件大小限制为 64 KB 以内。Limit the size of your template to 1 MB, and each parameter file to 64 KB. 已完成对迭代资源定义、变量值和参数值的扩展后,1 MB 的限制将适用于该模板的最终状态。The 1-MB limit applies to the final state of the template after it has been expanded with iterative resource definitions, and values for variables and parameters.

还将受限于:You are also limited to:

  • 256 个参数256 parameters
  • 256 个变量256 variables
  • 800 个资源(包括副本计数)800 resources (including copy count)
  • 64 个输出值64 output values
  • 模板表达式中 24,576 个字符24,576 characters in a template expression

通过使用嵌套模板,可超出某些模板限制。You can exceed some template limits by using a nested template. 有关详细信息,请参阅部署 Azure 资源时使用链接的模板For more information, see Using linked templates when deploying Azure resources. 若要减少参数、变量或输出的数量,可以将几个值合并为一个对象。To reduce the number of parameters, variables, or outputs, you can combine several values into an object. 有关详细信息,请参阅对象即参数For more information, see Objects as parameters.

后续步骤Next steps