ARM 範本中的資料類型

本文說明 Azure Resource Manager 範本 (ARM 範本) 支援的資料類型。

支援的類型

在 ARM 範本內,您可以使用下列資料類型:

  • 陣列
  • bool
  • int
  • object
  • secureObject
  • securestring
  • string

陣列

陣列開頭為左括弧 ([),結尾為右括弧 (])。 陣列可在單行或多行中宣告。 每個元素都以逗號分隔。

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

"outputs": {
  "arrayOutput": {
    "type": "array",
    "value": "[variables('exampleArray')]"
  },
  "firstExampleArrayElement": {
    "type": "int",
    "value": "[parameters('exampleArray')[0]]"
  }
}

陣列的元素可以是相同或不同類型。

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

"outputs": {
  "arrayOutput": {
    "type": "array",
    "value": "[variables('mixedArray')]"
  },
  "firstMixedArrayElement": {
    "type": "string",
    "value": "[variables('mixedArray')[0]]"
  }
}

布林值

指定布林值時,請使用 truefalse。 請勿用引號括住值。

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

整數

指定整數值時,請勿使用引號。

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

若以內嵌參數形式傳遞整數,值的範圍可能受限於部署所用的 SDK 或命令列工具。 例如,使用 PowerShell 來部署範本時,整數類型的範圍可介於 -2147483648 到 2147483647。 若要避免這項限制,請在參數檔案中指定較大的整數值。 資源類型自身具有整數屬性的限制。

物件

物件開頭為左大括弧 ({),結尾為右大括弧 (})。 物件中的每個屬性都是由 keyvalue 組成。 keyvalue 會以雙引號括住,並以冒號 (:) 分隔。 每個屬性都以逗號分隔。

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

您可以從採用點標記法的物件取得屬性。

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "exampleObject": {
            "type": "object",
            "defaultValue": {
                "name": "test name",
                "id": "123-abc",
                "isCurrent": true,
                "tier": 1
            }
        }
    },
    "resources": [
    ],
    "outputs": {
        "nameFromObject": {
            "type": "string",
            "value": "[parameters('exampleObject').name]"
        }
    }
}

在 JSON 中,物件是零或多個索引鍵/值組的未排序集合。 根據實作而定,排序可能會不同。 例如,Bicep items() 函式會依字母順序排序物件。 在其他位置,可以保留原始排序。 由於這種非確定性,因此請避免在編寫與部署參數和輸出互動的程式碼時,對物件索引鍵的排序進行任何假設。

字串

字串以雙引號標記。

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

安全字串和物件

安全字串所用的格式與字串相同,安全物件所用的格式則與物件相同。 將參數設為安全字串或安全物件時,參數的值不會儲存至部署歷程記錄,且不會記錄。 但若將該安全值設為不需要安全值的屬性,此值則不受保護。 例如,若將安全字串設為標記,該值便會儲存為純文字。 密碼及秘密請使用安全字串。

下列範例呈現兩個安全參數。

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

注意

請勿使用安全字串或物件作為輸出值。 如果您包含安全值作為輸出值,此值就不會顯示在部署歷程記錄中,也無法從另一個範本擷取。 反而,將安全值儲存在金鑰保存庫中,並從金鑰保存庫以參數形式傳遞

下一步

若要了解範本語法,請參閱了解 ARM 範本的結構和語法