了解 Azure Resource Manager 範本的結構和語法Understand the structure and syntax of Azure Resource Manager templates

本文說明 Azure Resource Manager 範本的結構。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.

本文適用于熟悉 Resource Manager 範本的使用者。This article is intended for users who have some familiarity with Resource Manager templates. 它會提供有關範本結構的詳細資訊。It provides detailed information about the structure of the template. 如需逐步教學課程,引導您完成建立範本的程式,請參閱教學課程:建立及部署您的第一個 Azure Resource Manager 範本For a step-by-step tutorial that guides you through the process of creating a template, see Tutorial: Create and deploy your first Azure Resource Manager template.

範本格式Template format

在最簡單的結構中,範本具有下列元素:In its simplest structure, a template has the following elements:

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "",
  "apiProfile": "",
  "parameters": {  },
  "variables": {  },
  "functions": [  ],
  "resources": [  ],
  "outputs": {  }
}
元素名稱Element name 必要Required 描述Description
$schema$schema yesYes JSON 結構描述檔案的位置,說明範本語言的版本。Location of the JSON schema file that describes the version of the template language.

針對資源群組部署,使用:https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#For resource group deployments, use: https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#

針對訂用帳戶部署,使用:https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#For subscription deployments, use: https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#
contentVersioncontentVersion yesYes 範本版本 (例如 1.0.0.0)。Version of the template (such as 1.0.0.0). 您可以為此元素提供任何值。You can provide any value for this element. 使用此值在範本中記載重大變更。Use this value to document significant changes in your template. 使用範本部署資源時,這個值可用來確定使用的是正確的範本。When deploying resources using the template, this value can be used to make sure that the right template is being used.
apiProfileapiProfile No API 版本,可作為資源類型的 API 版本集合。An API version that serves as a collection of API versions for resource types. 使用此值可避免必須為範本中的每個資源指定 API 版本。Use this value to avoid having to specify API versions for each resource in the template. 當您指定 API 設定檔版本,但未指定資源類型的 API 版本時,Resource Manager 會使用設定檔中所定義之該資源類型的 API 版本。When you specify an API profile version and don't specify an API version for the resource type, Resource Manager uses the API version for that resource type that is defined in the profile.

將範本部署到不同的環境(例如 Azure Stack 和全域 Azure)時,API 配置檔案屬性特別有用。The API profile property is especially helpful when deploying a template to different environments, such as Azure Stack and global Azure. 使用 API 設定檔版本,以確保您的範本會自動使用兩個環境中支援的版本。Use the API profile version to make sure your template automatically uses versions that are supported in both environments. 如需目前的 API 設定檔版本清單和設定檔中定義的資源 API 版本,請參閱API 設定檔For a list of the current API profile versions and the resources API versions defined in the profile, see API Profile.

如需詳細資訊,請參閱使用 API 設定檔來追蹤版本For more information, see Track versions using API profiles.
參數parameters No 執行部署以自訂資源部署時所提供的值。Values that are provided when deployment is executed to customize resource deployment.
變數variables No 範本中做為 JSON 片段以簡化範本語言運算式的值。Values that are used as JSON fragments in the template to simplify template language expressions.
函式functions No 範本中可用的使用者定義函式。User-defined functions that are available within the template.
resourcesresources yesYes 在資源群組或訂用帳戶中部署或更新的資源類型。Resource types that are deployed or updated in a resource group or subscription.
產出outputs No 部署後傳回的值。Values that are returned after deployment.

每個元素都有可以設定的屬性。Each element has properties you can set. 本文將詳細說明範本的各個區段。This article describes the sections of the template in greater detail.

parametersParameters

在範本的 parameters 區段中,您會指定可在部署資源時輸入的值。In the parameters section of the template, you specify which values you can input when deploying the resources. 範本中限制使用 256 個參數。You're limited to 256 parameters in a template. 您可以使用包含多個屬性的物件,以減少參數數目。You can reduce the number of parameters by using objects that contain multiple properties.

參數的可用屬性包括:The available properties for a parameter are:

"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
參數-名稱parameter-name yesYes 參數名稱。Name of the parameter. 必須是有效的 JavaScript 識別碼。Must be a valid JavaScript identifier.
類型type yesYes 參數值類型。Type of the parameter value. 允許的類型和值為 stringsecurestringintboolobjectsecureObject,以及 arrayThe allowed types and values are string, securestring, int, bool, object, secureObject, and array. 請參閱資料類型See Data types.
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 字串、securestring 及陣列類型參數長度的最小值,含此值。The minimum length for string, secure string, and array type parameters, this value is inclusive.
maxLengthmaxLength No 字串、securestring 及陣列類型參數長度的最大值,含此值。The maximum length for string, secure string, and array type parameters, this value is inclusive.
Descriptiondescription No 透過入口網站向使用者顯示的參數說明。Description of the parameter that is displayed to users through the portal. 如需詳細資訊,請參閱範本中的註解For more information, see Comments in templates.

如需如何使用參數的範例,請參閱Azure Resource Manager 範本中的參數For examples of how to use parameters, see Parameters in Azure Resource Manager templates.

資料類型Data types

針對當做內嵌參數傳遞的整數,值的範圍可能會受到您用於部署的 SDK 或命令列工具所限制。For integers passed as inline parameters, the range of values may be limited by the SDK or command-line tool you use for deployment. 例如,當使用 PowerShell 來部署範本時,整數類型的範圍可以從-2147483648 到2147483647。For example, when using PowerShell to deploy a template, integer types can range from -2147483648 to 2147483647. 若要避免這項限制,請在參數檔案中指定較大的整數值。To avoid this limitation, specify large integer values in a parameter file. 資源類型會對整數屬性套用自己的限制。Resource types apply their own limits for integer properties.

在您的範本中指定布林值和整數值時,請不要將值括在引號內。When specifying boolean and integer values in your template, don't surround the value with quotation marks. 開頭和結尾的字串值加上雙引號。Start and end string values with double quotation marks.

物件的開頭是左大括弧,結尾則是右大括弧。Objects start with a left brace and end with a right brace. 陣列的開頭為左括弧,結尾則是右方括弧。Arrays start with a left bracket and end with a right bracket.

在資源部署之後,無法讀取安全字串和安全物件。Secure strings and secure objects can't be read after resource deployment.

如需格式化資料類型的範例,請參閱參數類型格式For samples of formatting data types, see Parameter type formats.

變數Variables

在 variables 區段中,您會建構可用於整個範本中的值。In the variables section, you construct values that can be used throughout your template. 您不需要定義變數,但它們通常會經由減少複雜運算式來簡化您的範本。You don't need to define variables, but they often simplify your template by reducing complex expressions.

下列範例顯示定義變數的可用選項:The following example shows the available options for defining a variable:

"variables": {
  "<variable-name>": "<variable-value>",
  "<variable-name>": {
    <variable-complex-type-value>
  },
  "<variable-object-name>": {
    "copy": [
      {
        "name": "<name-of-array-property>",
        "count": <number-of-iterations>,
        "input": <object-or-value-to-repeat>
      }
    ]
  },
  "copy": [
    {
      "name": "<variable-array-name>",
      "count": <number-of-iterations>,
      "input": <object-or-value-to-repeat>
    }
  ]
}

如需使用 copy 為變數建立數個值的詳細資訊,請參閱變數反復專案。For information about using copy to create several values for a variable, see Variable iteration.

如需如何使用變數的範例,請參閱Azure Resource Manager 範本中的變數For examples of how to use variables, see Variables in Azure Resource Manager template.

函式Functions

在您的範本內,您可以建立自己的函式。Within your template, you can create your own functions. 這些函式可供您在範本中使用。These functions are available for use in your template. 通常,您會定義不想要在整個範本中重複的複雜運算式。Typically, you define complicated expressions that you don't want to repeat throughout your template. 您會從範本中支援的運算式和函式建立使用者定義的函式。You create the user-defined functions from expressions and functions that are supported in templates.

在定義使用者函式時,有一些限制:When defining a user function, there are some restrictions:

  • 此函式無法存取變數。The function can't access variables.
  • 此函式只能使用函式中定義的參數。The function can only use parameters that are defined in the function. 當您在使用者定義函數中使用parameters函式時,會限制為該函數的參數。When you use the parameters function within a user-defined function, you're restricted to the parameters for that function.
  • 此函式無法呼叫其他的使用者定義函式。The function can't call other user-defined functions.
  • 此函式不能使用參考函式The function can't use the reference function.
  • 函式的參數不能有預設值。Parameters for the function can't have default values.
"functions": [
  {
    "namespace": "<namespace-for-functions>",
    "members": {
      "<function-name>": {
        "parameters": [
          {
            "name": "<parameter-name>",
            "type": "<type-of-parameter-value>"
          }
        ],
        "output": {
          "type": "<type-of-output-value>",
          "value": "<function-return-value>"
        }
      }
    }
  }
],
元素名稱Element name 必要Required 描述Description
namespacenamespace yesYes 自訂函式的命名空間。Namespace for the custom functions. 使用來避免與範本函式的命名衝突。Use to avoid naming conflicts with template functions.
函數名稱function-name yesYes 自訂函式的名稱。Name of the custom function. 呼叫函式時,請將函式名稱與命名空間結合。When calling the function, combine the function name with the namespace. 例如,若要在 contoso 命名空間中呼叫名為 uniqueName 的函式,請使用 "[contoso.uniqueName()]"For example, to call a function named uniqueName in the namespace contoso, use "[contoso.uniqueName()]".
參數-名稱parameter-name No 要在自訂函數內使用的參數名稱。Name of the parameter to be used within the custom function.
參數-值parameter-value No 參數值類型。Type of the parameter value. 允許的類型和值為 stringsecurestringintboolobjectsecureObject,以及 arrayThe allowed types and values are string, securestring, int, bool, object, secureObject, and array.
輸出類型output-type yesYes 輸出值的類型。Type of the output value. 輸出值支援與函數輸入參數相同的類型。Output values support the same types as function input parameters.
輸出值output-value yesYes 評估並從函式傳回的範本語言運算式。Template language expression that is evaluated and returned from the function.

如需如何使用自訂函式的範例,請參閱Azure Resource Manager 範本中的使用者定義函數For examples of how to use custom functions, see User-defined functions in Azure Resource Manager template.

資源Resources

在資源區段中,您會定義要部署或更新的資源。In the resources section, you define the resources that are deployed or updated.

您會定義結構如下的資源:You define resources with the following structure:

"resources": [
  {
      "condition": "<true-to-deploy-this-resource>",
      "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": {}
              }
          ]
      },
      "sku": {
          "name": "<sku-name>",
          "tier": "<sku-tier>",
          "size": "<sku-size>",
          "family": "<sku-family>",
          "capacity": <sku-capacity>
      },
      "kind": "<type-of-resource>",
      "plan": {
          "name": "<plan-name>",
          "promotionCode": "<plan-promotion-code>",
          "publisher": "<plan-publisher>",
          "product": "<plan-product>",
          "version": "<plan-version>"
      },
      "resources": [
          "<array-of-child-resources>"
      ]
  }
]
元素名稱Element name 必要Required 描述Description
conditioncondition No 布林值,指出是否會在此部署期間佈建資源。Boolean value that indicates whether the resource will be provisioned during this deployment. 若為 true,就會在部署期間建立資源。When true, the resource is created during deployment. 若為 false,則會略過此部署的資源。When false, the resource is skipped for this deployment. 請參閱條件See condition.
apiVersionapiVersion yesYes 要用來建立資源的 REST API 版本。Version of the REST API to use for creating the resource. 若要判斷可用的值,請參閱範本參考To determine available values, see template reference.
類型type yesYes 資源類型。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). 若要判斷可用的值,請參閱範本參考To determine available values, see template reference. 對於子資源,類型的格式取決於它是內嵌在父資源內,還是在父資源外部定義。For a child resource, the format of the type depends on whether it's nested within the parent resource or defined outside of the parent resource. 請參閱設定子資源的名稱和類型See Set name and type for child resources.
名稱name yesYes 資源名稱。Name of the resource. 此名稱必須遵循在 RFC3986 中定義的 URI 元件限制。The name must follow URI component restrictions defined in RFC3986. 將資源名稱公開給外部合作物件的 Azure 服務會驗證該名稱,以確保不會嘗試偽造另一個身分識別。Azure services that expose the resource name to outside parties validate the name to make sure it isn't an attempt to spoof another identity. 對於子資源,名稱的格式取決於它是內嵌在父資源內,還是在父資源外部定義。For a child resource, the format of the name depends on whether it's nested within the parent resource or defined outside of the parent resource. 請參閱設定子資源的名稱和類型See Set name and type for child resources.
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) don't require a location. 請參閱設定資源位置See Set resource location.
標籤tags No 與資源相關聯的標記。Tags that are associated with the resource. 套用標籤,既可以邏輯方式組織訂用帳戶中的資源。Apply tags to logically organize resources across your subscription.
註解comments No 您在範本中記錄資源的註解。Your notes for documenting the resources in your template. 如需詳細資訊,請參閱範本中的註解For more information, see Comments in templates.
複製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 don't want all or the resources to deploy at the same time. 如需詳細資訊,請參閱在 Azure Resource Manager 中建立資源的數個執行個體For more information, see Create several 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 aren't dependent on each other, they're 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 aren't defined in this template must already exist. 避免加入不必要的相依性,因為可能會降低部署速度並產生循環相依性。Avoid adding unnecessary dependencies as they can slow your deployment and create circular dependencies. 如需設定相依性的指引,請參閱定義 Azure Resource Manager 範本中的相依性For guidance on setting dependencies, see Defining dependencies in Azure Resource Manager templates.
propertiesproperties No 資源特定的組態設定。Resource-specific configuration settings. 屬性的值和您在 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 several instances of a property. 若要判斷可用的值,請參閱範本參考To determine available values, see template reference.
skusku No 某些資源允許以值定義要部署的 SKU。Some resources allow values that define the SKU to deploy. 例如,您可以指定儲存體帳戶的備援類型。For example, you can specify the type of redundancy for a storage account.
kindkind No 某些資源允許以值定義您所部署的資源類型。Some resources allow a value that defines the type of resource you deploy. 例如,您可以指定要建立的 Cosmos DB 類型。For example, you can specify the type of Cosmos DB to create.
計劃plan No 某些資源允許以值定義要部署的計劃。Some resources allow values that define the plan to deploy. 例如,您可以指定虛擬機器的 Marketplace 映像。For example, you can specify the marketplace image for a virtual machine.
資源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. 沒有隱含父資源的相依性。Dependency on the parent resource isn't implied. 您必須明確定義該相依性。You must explicitly define that dependency. 請參閱設定子資源的名稱和類型See Set name and type for child resources.

referenceOutputs

在輸出區段中,您可以指定從部署傳回的值。In the Outputs section, you specify values that are returned from deployment. 通常,您會從已部署的資源傳回值。Typically, you return values from resources that were deployed.

下列範例顯示輸出定義的結構:The following example shows the structure of an output definition:

"outputs": {
  "<output-name>" : {
    "condition": "<boolean-value-whether-to-output-value>",
    "type" : "<type-of-output-value>",
    "value": "<output-value-expression>"
  }
}
元素名稱Element name 必要Required 描述Description
輸出-名稱output-name yesYes 輸出值的名稱。Name of the output value. 必須是有效的 JavaScript 識別碼。Must be a valid JavaScript identifier.
conditioncondition No 布林值,指出是否傳回此輸出值。Boolean value that indicates whether this output value is returned. 當為 true 時,該值會包含在部署的輸出中。When true, the value is included in the output for the deployment. 若為 false,則會略過此部署的輸出值。When false, the output value is skipped for this deployment. 未指定時,預設值為 trueWhen not specified, the default value is true.
類型type yesYes 輸出值的類型。Type of the output value. 輸出值支援與範本輸入參數相同的類型。Output values support the same types as template input parameters. 如果您針對輸出類型指定securestring ,此值不會顯示在部署歷程記錄中,而且無法從另一個範本抓取。If you specify securestring for the output type, the value isn't displayed in the deployment history and can't be retrieved from another template. 若要在多個範本中使用秘密值,請將密碼儲存在 Key Vault 中,並在參數檔案中參考密碼。To use a secret value in more than one template, store the secret in a Key Vault and reference the secret in the parameter file. 如需詳細資訊,請參閱在部署期間使用 Azure Key Vault 以傳遞安全的參數值For more information, see Use Azure Key Vault to pass secure parameter value during deployment.
value yesYes 評估並傳回做為輸出值的範本語言運算式。Template language expression that is evaluated and returned as output value.

如需如何使用輸出的範例,請參閱Azure Resource Manager 範本中的輸出For examples of how to use outputs, see Outputs in Azure Resource Manager template.

註解與中繼資料Comments and metadata

有幾個選項可將註解與中繼資料新增到您的範本中。You have a few options for adding comments and metadata to your template.

註解Comments

針對內嵌批註,您可以使用 ///* ... */,但此語法不適用於所有工具。For inline comments, you can use either // or /* ... */ but this syntax doesn't work with all tools. 您無法使用入口網站範本編輯器來處理具有內嵌批註的範本。You can't use the portal template editor to work on templates with inline comments. 如果您新增這種樣式的註解,請務必使用支援內嵌 JSON 註解的工具。If you add this style of comment, be sure the tools you use support inline JSON comments.

注意

若要使用 Azure CLI 來部署具有批註的範本,您必須使用 --handle-extended-json-format 參數。To deploy templates with comments by using Azure CLI, you must use the --handle-extended-json-format switch.

{
  "type": "Microsoft.Compute/virtualMachines",
  "name": "[variables('vmName')]", // to customize name, change it in variables
  "location": "[parameters('location')]", //defaults to resource group location
  "apiVersion": "2018-10-01",
  "dependsOn": [ /* storage account and network interface must be deployed first */
    "[resourceId('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]",
    "[resourceId('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
  ],

在 Visual Studio Code 中, Azure Resource Manager Tools 延伸模組可以自動偵測 Resource Manager 範本,並據此變更語言模式。In Visual Studio Code, the Azure Resource Manager Tools extension can automatically detect Resource Manager template and change the language mode accordingly. 如果您在 VS Code 右下角看到Azure Resource Manager 範本,您可以使用內嵌批註。If you see Azure Resource Manager Template at the bottom right corner of VS Code, you can use the inline comments. 內嵌註解不再被標示為無效。The inline comments are no longer marked as invalid.

Visual Studio Code Azure Resource Manager 範本模式

中繼資料Metadata

幾乎在範本的任何位置都可以新增 metadata 物件。You can add a metadata object almost anywhere in your template. Resource Manager 會略過該物件,但您的 JSON 編輯器可能會警告您該屬性無效。Resource Manager ignores the object, but your JSON editor may warn you that the property isn't valid. 在物件中,定義您需要的屬性。In the object, define the properties you need.

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "metadata": {
    "comments": "This template was developed for demonstration purposes.",
    "author": "Example Name"
  },

對於參數,新增 metadata 屬性的 description 物件。For parameters, add a metadata object with a description property.

"parameters": {
  "adminUsername": {
    "type": "string",
    "metadata": {
      "description": "User name for the Virtual Machine."
    }
  },

透過入口網站部署範本時,您在描述中提供的文字會自動做為該參數的提示。When deploying the template through the portal, the text you provide in the description is automatically used as a tip for that parameter.

顯示參數提示

對於資源,新增 comments 項目或中繼資料物件。For resources, add a comments element or a metadata object. 下列範例顯示註解項目和中繼資料物件。The following example shows both a comments element and a metadata object.

"resources": [
  {
    "comments": "Storage account used to store VM disks",
    "apiVersion": "2018-07-01",
    "type": "Microsoft.Storage/storageAccounts",
    "name": "[concat('storage', uniqueString(resourceGroup().id))]",
    "location": "[parameters('location')]",
    "metadata": {
      "comments": "These tags are needed for policy compliance."
    },
    "tags": {
      "Dept": "[parameters('deptName')]",
      "Environment": "[parameters('environment')]"
    },
    "sku": {
      "name": "Standard_LRS"
    },
    "kind": "Storage",
    "properties": {}
  }
]

對於輸出,將中繼資料物件新增至輸出值。For outputs, add a metadata object to the output value.

"outputs": {
  "hostname": {
    "type": "string",
    "value": "[reference(variables('publicIPAddressName')).dnsSettings.fqdn]",
    "metadata": {
      "comments": "Return the fully qualified domain name"
    }
  },

您無法將中繼資料物件新增至使用者定義函式。You can't add a metadata object to user-defined functions.

多行字串Multi-line strings

您可以將字串分成多行。You can break a string into multiple lines. 例如,location 屬性和下列 JSON 範例中的其中一個批註。For example the location property and one of the comments in the following JSON example.

{
  "type": "Microsoft.Compute/virtualMachines",
  "name": "[variables('vmName')]", // to customize name, change it in variables
  "location": "[
    parameters('location')
    ]", //defaults to resource group location
  "apiVersion": "2018-10-01",
  /*
    storage account and network interface
    must be deployed first
  */
  "dependsOn": [
    "[resourceId('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]",
    "[resourceId('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
  ],

若要使用 Azure CLI 來部署含有多行字串的範本,您必須使用 --handle-extended-json-format 參數。To deploy templates with multi-line strings by using Azure CLI, you must use the --handle-extended-json-format switch.

後續步驟Next steps