教程:利用 Azure 资源管理器模板参考Tutorial: Utilize the Azure Resource Manager template reference

了解如何查找模板架构信息,以及如何使用该信息创建 Azure 资源管理器模板。Learn how to find the template schema information, and use the information to create Azure Resource Manager templates.

在本教程中,请使用 Azure 快速入门模板中提供的基础模板。In this tutorial, you use a base template from Azure Quickstart templates. 根据模板参考文档自定义模板,以便创建加密的存储帐户。Using template reference documentation, you customize the template to create an encrypted Storage account.

资源管理器模板参考部署加密的存储帐户

本教程涵盖以下任务:This tutorial covers the following tasks:

  • 打开快速入门模板Open a Quickstart template
  • 了解模板Understand the template
  • 编辑模板Edit the template
  • 部署模板Deploy the template

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

先决条件Prerequisites

若要完成本文,需要做好以下准备:To complete this article, you need:

打开快速入门模板Open a Quickstart template

Azure 快速入门模板是资源管理器模板的存储库。Azure QuickStart Templates is a repository for Resource Manager templates. 无需从头开始创建模板,只需找到一个示例模板并对其自定义即可。Instead of creating a template from scratch, you can find a sample template and customize it. 本快速入门中使用的模板称为创建标准存储帐户The template used in this quickstart is called Create a standard storage account. 该模板定义 Azure 存储帐户资源。The template defines an Azure Storage account resource.

  1. 在 Visual Studio Code 中,选择“文件”>“打开文件”。From Visual Studio Code, select File>Open File.

  2. 在“文件名”中粘贴以下 URL:In File name, paste the following URL:

    https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-storage-account-create/azuredeploy.json
    
  3. 选择“打开”以打开该文件。Select Open to open the file.

  4. 选择“文件”>“另存为”,将该文件作为 azuredeploy.json 保存到本地计算机。Select File>Save As to save the file as azuredeploy.json to your local computer.

了解架构Understand the schema

  1. 在 VS Code 中将模板折叠到根级别。From VS Code, collapse the template to the root level. 你使用最简单的结构,其中包含以下元素:You have the simplest structure with the following elements:

    资源管理器模板的最简单结构

    • $schema:指定描述模板语言版本的 JSON 架构文件所在的位置。$schema: specify the location of the JSON schema file that describes the version of the template language.
    • contentVersion:为此元素指定任意值,以便记录模板中的重要更改。contentVersion: specify any value for this element to document significant changes in your template.
    • parameters:指定执行部署以自定义资源部署时提供的值。parameters: specify the values that are provided when deployment is executed to customize resource deployment.
    • variables:指定在模板中用作 JSON 片段以简化模板语言表达式的值。variables: specify the values that are used as JSON fragments in the template to simplify template language expressions.
    • resources:指定已在资源组中部署或更新的资源类型。resources: specify the resource types that are deployed or updated in a resource group.
    • outputs:指定部署后返回的值。outputs: specify the values that are returned after deployment.
  2. 展开“resources”。Expand resources. 已定义 Microsoft.Storage/storageAccounts 资源。There is a Microsoft.Storage/storageAccounts resource defined. 此模板创建非加密存储帐户。The template creates a non-encrypted Storage account.

    资源管理器模板存储帐户定义

    加密对象应如下所示:Your encryption object shall look like:

    "encryption": {
        "services": {
            "blob": {
                "enabled": true
            },
            "file": {
              "enabled": true
            }
        },
        "keySource": "Microsoft.Storage"
    }
    

编辑模板Edit the template

在 Visual Studio Code 中修改模板,使 resources 元素如下所示:From Visual Studio Code, modify the template so that the resources element looks like:

资源管理器模板加密的存储帐户资源

部署模板Deploy the template

有关部署过程,请参阅 Visual Studio Code 快速入门中的部署模板部分。Refer to the Deploy the template section in the Visual Studio Code quickstart for the deployment procedure.

以下屏幕快照显示的 CLI 命令用于列出新创建的存储帐户,该命令指示已为 Blob 存储启用加密。The following screenshot shows the CLI command for listing the newly created storage account, which indicates encryption has been enabled for the blob storage.

Azure 资源管理器加密的存储帐户

清理资源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 门户上的左侧菜单中选择“资源组”。From the Azure portal, select Resource group from the left menu.
  2. 在“按名称筛选”字段中输入资源组名称。Enter the resource group name in the Filter by name field.
  3. 选择资源组名称。Select the resource group name. 应会看到,该资源组中总共有六个资源。You shall see a total of six resources in the resource group.
  4. 在顶部菜单中选择“删除资源组”。Select Delete resource group from the top menu.

后续步骤Next steps

本教程介绍了如何使用模板参考来自定义现有的模板。In this tutorial, you learned how to use template reference to customize an existing template. 若要了解如何创建多个存储帐户实例,请参阅:To learn how to create multiple storage account instances, see: