快速入门:使用 Azure 门户创建和部署 ARM 模板Quickstart: Create and deploy ARM templates by using the Azure portal

了解如何使用 Azure 门户生成 Azure 资源管理器 (ARM) 模板,以及从门户编辑和部署该模板的过程。Learn how to generate an Azure Resource Manager (ARM) template using the Azure portal, and the process of editing and deploying the template from the portal. ARM 模板为 JSON 文件,用于定义针对解决方案进行部署时所需的资源。ARM templates are JSON files that define the resources you need to deploy for your solution. 若要了解与部署和管理 Azure 解决方案关联的概念,请参阅模版部署概述To understand the concepts associated with deploying and managing your Azure solutions, see template deployment overview.


完成本教程后,部署 Azure 存储帐户。After completing the tutorial, you deploy an Azure Storage account. 可以通过同一过程来部署其他 Azure 资源。The same process can be used to deploy other Azure resources.

如果没有 Azure 订阅,请在开始前创建一个试用帐户If you don't have an Azure subscription, create a trial account before you begin.

使用门户生成模板Generate a template using the portal

从头开始创建 ARM 模板不是一项容易的任务,尤其是在不熟悉 Azure 部署和 JSON 格式的情况下。Creating an ARM template from scratch is not an easy task, especially if you are new to Azure deployment and you are not familiar with the JSON format. 可以使用 Azure 门户来配置资源(例如 Azure 存储帐户)。Using the Azure portal, you can configure a resource, for example an Azure Storage account. 在部署资源之前,可以将配置导出到模板中。Before you deploy the resource, you can export your configuration into a template. 可以保存模板,便于将来重复使用。You can save the template and reuse it in the future.

需要有经验的模板开发人员在尝试部署不熟悉的 Azure 资源时,会使用此方法来生成模板。Many experienced template developers use this method to generate templates when they try to deploy Azure resources that they are not familiar with. 有关使用门户导出模板的更多信息,请参阅将资源组导出到模板For more information about exporting templates by using the portal, see Export resource groups to templates. 查找工作模板的另一种方法是 Azure 快速入门模板The other way to find a working template is from Azure Quickstart templates.

  1. 在 Web 浏览器中转到 Azure 门户,然后登录。In a web browser, go to the Azure portal and sign in.

  2. 在 Azure 门户菜单中,选择“创建资源”。From the Azure portal menu, select Create a resource.

    在 Azure 门户菜单中,选择“创建资源”

  3. 选择“存储” > “存储帐户” 。Select Storage > Storage account.

    创建 Azure 存储帐户

  4. 输入以下信息:Enter the following information:

    名称Name ValueValue
    资源组Resource group 选择“新建”,然后指定所选资源组的名称。Select Create new, and specify a resource group name of your choice. 在屏幕截图中,资源组名称为 mystorage1016rgOn the screenshot, the resource group name is mystorage1016rg. 资源组是 Azure 资源的容器。Resource group is a container for Azure resources. 资源组方便 Azure 资源的管理。Resource group makes it easier to manage Azure resources.
    名称Name 为存储帐户指定唯一的名称。Give your storage account a unique name. 存储帐户名称在整个 Azure 中必须是唯一的,且仅包含小写字母和数字。The storage account name must be unique across all of Azure, and it contain only lowercase letters and numbers. 名称长度必须介于 3 到 24 个字符之间。Name must be between 3 and 24 characters. 如果收到错误消息“存储帐户名称‘mystorage1016’已被占用”,请尝试使用“<名称>存储<MMDD 格式的今日日期>”,例如“johndolestorage1016” 。If you get an error message saying "The storage account name 'mystorage1016' is already taken", try using <your name>storage<Today's date in MMDD>, for example johndolestorage1016.

    可对剩余的属性使用默认值。You can use the default values for the rest of the properties.

    使用 Azure 门户创建 Azure 存储帐户配置


    某些导出的模板需要经过一些编辑才能部署。Some of the exported templates require some edits before you can deploy them.

  5. 在屏幕底部选择“查看 + 创建”。Select Review + create on the bottom of the screen. 请勿在下一步中选择“创建”。Do not select Create in the next step.

  6. 在屏幕底部选择“下载自动化模板”。Select Download a template for automation on the bottom of the screen. 门户显示生成的模板:The portal shows the generated template:


    主窗格会显示该模板。The main pane shows the template. 它是包含六个顶级元素(schemacontentVersionparametersvariablesresourcesoutput)的 JSON 文件。It is a JSON file with six top-level elements - schema, contentVersion, parameters, variables, resources, and output. 有关详细信息,请参阅了解 ARM 模板的结构和语法For more information, see Understand the structure and syntax of ARM templates

    定义了 8 个参数。There are eight parameters defined. 其中一个名为 storageAccountNameOne of them is called storageAccountName. 在上一屏幕截图中,第二个突出显示的部分显示如何在模板中引用此参数。The second highlighted part on the previous screenshot shows how to reference this parameter in the template. 在下一部分,请编辑此模板,以便将生成的名称用于存储帐户。In the next section, you edit the template to use a generated name for the storage account.

    在模板中定义了一个 Azure 资源。In the template, one Azure resource is defined. 类型为 Microsoft.Storage/storageAccountsThe type is Microsoft.Storage/storageAccounts. 查看资源定义方式和定义结构。Take a look of how the resource is defined, and the definition structure.

  7. 在屏幕顶部选择“下载”。Select Download from the top of the screen.

  8. 打开下载的 zip 文件,然后将“template.json”保存到计算机。Open the downloaded zip file, and then save template.json to your computer. 在下一部分,请使用模板部署工具来编辑此模板。In the next section, you use a template deployment tool to edit the template.

  9. 选择“参数”选项卡,查看为参数提供的值。Select the Parameter tab to see the values you provided for the parameters. 部署模板时,请写下这些值,下一部分需要它们。Write down these values, you need them in the next section when you deploy the template.


    使用模板文件和参数文件可以创建一个资源(在本教程中为 Azure 存储帐户)。Using both the template file and the parameters file, you can create a resource, in this tutorial, an Azure storage account.

编辑和部署模板Edit and deploy the template

可以使用 Azure 门户执行一些基本的模板编辑操作。The Azure portal can be used to perform some basic template editing. 在本快速入门中,请使用名为“模板部署”的门户工具。In this quickstart, you use a portal tool called Template Deployment. 在本教程中使用模板部署,因此可以使用一个界面(Azure 门户)来完成整个教程。Template Deployment is used in this tutorial so you can complete the whole tutorial using one interface - the Azure portal. 若要编辑更复杂的模板,请考虑使用 Visual Studio Code,因为它提供更丰富的编辑功能。To edit a more complex template, consider using Visual Studio Code, which provides richer edit functionalities.


模板部署提供了用于测试简单模板的接口。Template Deployment provides an interface for testing simple templates. 建议不要在生产环境中使用此功能,It is not recommended to use this feature in production. 而是将模板存储在 Azure 存储帐户或 GitHub 等源代码存储库中。Instead, store your templates in an Azure storage account, or a source code repository like GitHub.

Azure 要求每个 Azure 服务都具有唯一的名称。Azure requires that each Azure service has a unique name. 如果输入了已存在的存储帐户名,则部署可能失败。The deployment could fail if you entered a storage account name that already exists. 若要避免此问题,可以修改模板,以便使用模板函数调用 uniquestring(),以生成唯一的存储帐户名。To avoid this issue, you modify the template to use a template function call uniquestring() to generate a unique storage account name.

  1. 从 Azure 门户菜单的搜索框中,键入“部署”,然后选择“部署自定义模板” 。From the Azure portal menu, in the search box, type deploy, and then select Deploy a custom template.

    Azure 资源管理器模板库

  2. 选择“在编辑器中生成自己的模板”。Select Build your own template in the editor.

  3. 选择“加载文件”,然后按说明加载在上部分下载的 template.json。Select Load file, and then follow the instructions to load template.json you downloaded in the last section.

  4. 对模板进行以下三处更改:Make the following three changes to the template:

    Azure Resource Manager 模板

    • 删除“storageAccountName”参数,如上一屏幕截图所示。Remove the storageAccountName parameter as shown in the previous screenshot.

    • 添加一个名为“storageAccountName”的变量,如上一屏幕截图所示:Add one variable called storageAccountName as shown in the previous screenshot:

      "storageAccountName": "[concat(uniqueString(subscription().subscriptionId), 'storage')]"

      此处使用了两个模板函数:concat()uniqueString()Two template functions are used here: concat() and uniqueString().

    • 更新 Microsoft.Storage/storageAccounts 资源的 name 元素,以使用新定义的变量而不是参数:Update the name element of the Microsoft.Storage/storageAccounts resource to use the newly defined variable instead of the parameter:

      "name": "[variables('storageAccountName')]",

      最终的模板应如下所示:The final template shall look like:

         "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
         "contentVersion": "",
         "parameters": {
             "location": {
                 "type": "string"
             "accountType": {
                 "type": "string"
             "kind": {
                 "type": "string"
             "accessTier": {
                 "type": "string"
             "minimumTlsVersion": {
                 "type": "string"
             "supportsHttpsTrafficOnly": {
                 "type": "bool"
             "allowBlobPublicAccess": {
                 "type": "bool"
         "variables": {
             "storageAccountEndPoint": "https://core.chinacloudapi.cn/",
             "storageAccountName": "[concat(uniqueString(subscription().subscriptionId), 'storage')]"
         "resources": [
                 "name": "[variables('storageAccountName')]",
                 "type": "Microsoft.Storage/storageAccounts",
                 "apiVersion": "2019-06-01",
                 "location": "[parameters('location')]",
                 "properties": {
                     "accessTier": "[parameters('accessTier')]",
                     "minimumTlsVersion": "[parameters('minimumTlsVersion')]",
                     "supportsHttpsTrafficOnly": "[parameters('supportsHttpsTrafficOnly')]",
                     "allowBlobPublicAccess": "[parameters('allowBlobPublicAccess')]"
                 "dependsOn": [],
                 "sku": {
                     "name": "[parameters('accountType')]"
                 "kind": "[parameters('kind')]",
                 "tags": {}
         "outputs": {}
  5. 选择“保存” 。Select Save.

  6. 输入以下值:Enter the following values:

    名称Name ValueValue
    资源组Resource group 选择在上一部分中创建的资源组名称。Select the resource group name you created in the last section.
    区域Region 选择资源组的位置。Select a location for the resource group. 例如,中国北部For example, China North.
    位置Location 选择存储帐户的位置。Select a location for the storage account. 例如,中国北部For example, China North.
    帐户类型Account Type 对于本快速入门,请输入 Standard_LRSEnter Standard_LRS for this quickstart.
    种类Kind 对于本快速入门,请输入“StorageV2”。Enter StorageV2 for this quickstart.
    访问层Access Tier 对于本快速入门,请输入“热”。Enter Hot for this quickstart.
    最低 TLS 版本Minimum Tls Version 输入 TLS1_0。Enter TLS1_0.
    仅支持 Https 流量Supports Https Traffic Only 对于本快速入门,请选择“true”。Select true for this quickstart.
    允许 Blob 公共访问Allow Blob Public Access 对于本快速入门,请选择“false”。Select false for this quickstart.
  7. 选择“查看 + 创建”。Select Review + create.

  8. 选择“创建” 。Select Create.

  9. 选择屏幕顶部的铃铛图标(通知)可查看部署状态。Select the bell icon (notifications) from the top of the screen to see the deployment status. 此时会看到“部署正在进行”。You shall see Deployment in progress. 等待部署完成。Wait until the deployment is completed.

    Azure 资源管理器模板部署通知

  10. 从通知窗格选择“转到资源组”。Select Go to resource group from the notification pane. 将看到类似于以下的屏幕:You shall see a screen similar to:

    Azure 资源管理器模板部署资源组

    可以看到部署状态为成功,资源组中只有一个存储帐户。You can see the deployment status was successful, and there is only one storage account in the resource group. 存储帐户名称是模板生成的唯一字符串。The storage account name is a unique string generated by the template. 若要详细了解如何使用 Azure 存储帐户,请参阅快速入门:使用 Azure 门户上传、下载和列出 BlobTo learn more about using Azure storage accounts, see Quickstart: Upload, download, and list blobs using the Azure portal.

清理资源Clean up resources

不再需要 Azure 资源时,请通过删除资源组来清理部署的资源。When the Azure resources are no longer needed, clean up the resources you deployed by deleting the resource group.

  1. 在 Azure 门户上的左侧菜单中选择“资源组”。In the Azure portal, select Resource group on the left menu.
  2. 在“按名称筛选”字段中输入资源组名称。Enter the resource group name in the Filter by name field.
  3. 选择资源组名称。Select the resource group name. 应会看到资源组中的存储帐户。You shall see the storage account in the resource group.
  4. 在顶部菜单中选择“删除资源组”。Select Delete resource group in the top menu.

后续步骤Next steps

本教程已介绍如何通过 Azure 门户生成模板,以及如何使用门户部署模板。In this tutorial, you learned how to generate a template from the Azure portal, and how to deploy the template using the portal. 本快速入门中使用的模板是包含一个 Azure 资源的简单模板。The template used in this Quickstart is a simple template with one Azure resource. 如果模板较为复杂,使用 Visual Studio Code 或 Visual Studio 开发模板会更方便。When the template is complex, it is easier to use Visual Studio Code or Visual Studio to develop the template. 若要详细了解模板开发,请参阅新的初学者教程系列:To learn more about template development, see our new beginner tutorial series: