ARM 模板中的数据类型Data types in ARM templates

本文介绍 Azure 资源管理器模板(ARM 模板)中支持的数据类型。This article describes the data types supported in Azure Resource Manager templates (ARM templates). 其中涵盖 JSON 和 Bicep 两种数据类型。It covers both JSON and Bicep data types.

支持的类型Supported types

在 ARM 模板中,可以使用以下数据类型:Within an ARM template, you can use these data types:

  • arrayarray
  • boolbool
  • intint
  • 对象 (object)object
  • secureObject - 在 Bicep 中用修饰符表示secureObject - indicated by modifier in Bicep
  • secureString - 在 Bicep 中用修饰符表示secureString - indicated by modifier in Bicep
  • stringstring

数组Arrays

数组以左中括号 ([) 开头,以右中括号 (]) 结尾。Arrays start with a left bracket ([) and end with a right bracket (]).

在 JSON 中,可以在一行中或多行中声明数组。In JSON, an array can be declared in a single line or multiple lines. 各个元素用逗号分隔。Each element is separated by a comma.

在 Bicep 中,必须在多行中声明数组。In Bicep, an array must be declared in multiple lines. 请不要在值之间使用逗号。Don't use commas between values.

"parameters": {
  "exampleArray": {
    "type": "array",
    "defaultValue": [
      1,
      2,
      3
    ]
  }
},

数组的元素可以是同一类型,也可以是不同类型。The elements of an array can be the same type or different types.

"variables": {
  "mixedArray": [
    "[resourceGroup().name]",
    1,
    true,
    "example string"
  ]
}

布尔型Booleans

在指定布尔值时,请使用 truefalseWhen specifying boolean values, use true or false. 请不要将值置于引号中。Don't surround the value with quotation marks.

"parameters": {
  "exampleBool": {
    "type": "bool",
    "defaultValue": true
  }
},

整数Integers

在指定整数值时,请不要使用引号。When specifying integer values, don't use quotation marks.

"parameters": {
  "exampleInt": {
    "type": "int",
    "defaultValue": 1
  }
}

对于作为内联参数传递的整数,值的范围可能受限于用于部署的 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.

对象Objects

对象以左大括号 ({) 开头,以右大括号 (}) 结尾。Objects start with a left brace ({) and end with a right brace (}). 对象中的每个属性都包含键和值。Each property in an object consists of key and value. 键和值用冒号 (:) 分隔。The key and value are separated by a colon (:).

在 JSON 中,键置于双引号中。In JSON, the key is enclosed in double quotes. 各个属性用逗号分隔。Each property is separated by a comma.

"parameters": {
  "exampleObject": {
    "type": "object",
    "defaultValue": {
      "name": "test name",
      "id": "123-abc",
      "isCurrent": true,
      "tier": 1
    }
  }
}

字符串Strings

在 JSON 中,用双引号标记字符串。In JSON, strings are marked with double quotes. 在 Bicep 中,用单引号标记字符串。In Bicep, strings are marked with singled quotes.

"parameters": {
  "exampleString": {
    "type": "string",
    "defaultValue": "test value"
  }
},

安全字符串和对象Secure strings and objects

安全字符串使用与字符串相同的格式,安全对象使用与对象相同的格式。Secure string uses the same format as string, and secure object uses the same format as object. 将参数设置为安全字符串或安全对象时,参数的值不会保存到部署历史记录中,也不会记入日志。When you set a parameter to a secure string or secure object, the value of the parameter isn't saved to the deployment history and isn't logged. 但是,如果将该安全值设置为不应为安全值的属性,则该值不会受到保护。However, if you set that secure value to a property that isn't expecting a secure value, the value isn't protected. 例如,如果将安全字符串设置为标记,则该值将以纯文本的形式存储。For example, if you set a secure string to a tag, that value is stored as plain text. 使用安全字符串作为密码和机密。Use secure strings for passwords and secrets.

在使用 Bicep 时,请将 @secure() 修饰符添加到字符串或对象。With Bicep, you add the @secure() modifier to a string or object.

以下示例显示了两个安全参数:The following example shows two secure parameters:

"parameters": {
  "password": {
    "type": "secureString"
  },
  "configValues": {
    "type": "secureObject"
  }
}

后续步骤Next steps

若要了解模板语法,请参阅了解 ARM 模板的结构和语法To learn about the template syntax, see Understand the structure and syntax of ARM templates.