您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

创建 Azure 资源管理器模板以便自动部署 Azure 逻辑应用Create Azure Resource Manager templates to automate deployment for Azure Logic Apps

为了帮助你自动创建和部署逻辑应用,本文介绍了可为逻辑应用创建Azure 资源管理器模板的方式。To help you automate creating and deploying your logic app, this article describes the ways that you can create an Azure Resource Manager template for your logic app. 有关包含工作流定义和部署所需的其他资源的模板的结构和语法的概述,请参阅概述:使用 Azure 资源管理器模板自动部署逻辑应用For an overview about the structure and syntax for a template that includes your workflow definition and other resources necessary for deployment, see Overview: Automate deployment for logic apps with Azure Resource Manager templates.

Azure 逻辑应用提供了一个预建的逻辑应用 Azure 资源管理器模板,你可以重复使用该模板来创建逻辑应用,还可以定义用于部署的资源和参数。Azure Logic Apps provides a prebuilt logic app Azure Resource Manager template that you can reuse, not only for creating logic apps, but also to define the resources and parameters to use for deployment. 可以将此模板用于自己的业务方案,也可以根据需要自定义此模板。You can use this template for your own business scenarios or customize the template to meet your requirements.

重要

请确保模板中的连接与逻辑应用使用相同的 Azure 资源组和位置。Make sure that connections in your template use the same Azure resource group and location as your logic app.

有关 Azure 资源管理器模板的详细信息,请参阅以下主题:For more about Azure Resource Manager templates, see these topics:

用 Visual Studio 创建模板Create templates with Visual Studio

若要创建最适合部署的有效参数化逻辑应用模板,请使用 Visual Studio (免费社区版或更高版本)以及适用于 Visual Studio 的 Azure 逻辑应用工具。For the easiest way to create valid parameterized logic app templates that are mostly ready for deployment, use Visual Studio (free Community edition or greater) and the Azure Logic Apps Tools for Visual Studio. 然后,你可以在 Visual studio 中创建逻辑应用 ,或者查找 Azure 门户中的现有逻辑应用并将其下载到 Visual studioYou can then either create your logic app in Visual Studio or find and download an existing logic app from the Azure portal into Visual Studio.

下载逻辑应用后,你将获得一个模板,其中包含逻辑应用和其他资源(如连接)的定义。By downloading your logic app, you get a template that includes the definitions for your logic app and other resources such as connections. 模板还参数化或定义用于部署逻辑应用和其他资源的值的参数。The template also parameterizes, or defines parameters for, the values used for deploying your logic app and other resources. 可以在单独的参数文件中提供这些参数的值。You can provide the values for these parameters in a separate parameters file. 这样,你就可以根据你的部署需要更轻松地更改这些值。That way, you can more easily change these values based on your deployment needs. 有关详细信息,请参阅以下主题:For more information, see these topics:

创建具有 Azure PowerShell 的模板Create templates with Azure PowerShell

可以通过将 Azure PowerShell 与LogicAppTemplate 模块一起使用来创建资源管理器模板。You can create Resource Manager templates by using Azure PowerShell with the LogicAppTemplate module. 此开源模块首先计算逻辑应用和逻辑应用使用的任何连接。This open-source module first evaluates your logic app and any connections that the logic app uses. 然后,该模块会生成模板资源,其中包含部署所必需的参数。The module then generates template resources with the necessary parameters for deployment.

例如,假设有一个逻辑应用,该应用从 Azure 服务总线队列接收消息,并将数据上传到 Azure SQL 数据库。For example, suppose you have a logic app that receives a message from an Azure Service Bus queue and uploads data to an Azure SQL database. 模块将保留所有业务流程逻辑,并参数化 SQL 和服务总线连接字符串,以便可以根据部署需要提供和更改这些值。The module preserves all the orchestration logic and parameterizes the SQL and Service Bus connection strings so that you can provide and change those values based on your deployment needs.

这些示例演示如何使用 Azure 资源管理器模板、Azure Pipelines 在 Azure DevOps 中创建和部署逻辑应用,并 Azure PowerShell:These samples show how to create and deploy logic apps by using Azure Resource Manager templates, Azure Pipelines in Azure DevOps, and Azure PowerShell:

安装 PowerShell 模块Install PowerShell modules

  1. 如果尚未安装,请安装Azure PowerShellIf you haven't already, install Azure PowerShell.

  2. 若要从PowerShell 库最简单的方法安装 LogicAppTemplate 模块,请运行以下命令:For the easiest way to install the LogicAppTemplate module from the PowerShell Gallery, run this command:

    PS> Install-Module -Name LogicAppTemplate
    

    若要更新到最新版本,请运行以下命令:To update to the latest version, run this command:

    PS> Update-Module -Name LogicAppTemplate
    

或者,若要手动安装,请遵循适用于逻辑应用模板创建者的 GitHub 中的步骤。Or, to install manually, follow the steps in GitHub for Logic App Template Creator.

安装 Azure 资源管理器客户端Install Azure Resource Manager client

若要使 LogicAppTemplate 模块可与任何 Azure 租户和订阅访问令牌一起使用,请安装azure 资源管理器客户端工具,该工具是一个调用 AZURE 资源管理器 API 的简单命令行工具。For the LogicAppTemplate module to work with any Azure tenant and subscription access token, install the Azure Resource Manager client tool, which is a simple command line tool that calls the Azure Resource Manager API.

使用此工具运行 Get-LogicAppTemplate 命令时,该命令将首先通过 ARMClient 工具获取一个访问令牌,通过管道将令牌传递给 PowerShell 脚本,并将该模板创建为 JSON 文件。When you run the Get-LogicAppTemplate command with this tool, the command first gets an access token through the ARMClient tool, pipes the token to the PowerShell script, and creates the template as a JSON file. 有关该工具的详细信息,请参阅有关 Azure 资源管理器客户端工具的文章For more information about the tool, see this article about the Azure Resource Manager client tool.

通过 PowerShell 生成模板Generate template with PowerShell

若要在安装 LogicAppTemplate 模块并Azure CLI后生成模板,请运行以下 PowerShell 命令:To generate your template after installing the LogicAppTemplate module and Azure CLI, run this PowerShell command:

PS> Get-LogicAppTemplate -Token (az account get-access-token | ConvertFrom-Json).accessToken -LogicApp <logic-app-name> -ResourceGroup <Azure-resource-group-name> -SubscriptionId $SubscriptionId -Verbose | Out-File C:\template.json

若要根据azure 资源管理器客户端工具中的令牌进行管道的建议,请改为运行此命令,其中 $SubscriptionId 是你的 AZURE 订阅 ID:To follow the recommendation for piping in a token from the Azure Resource Manager client tool, run this command instead where $SubscriptionId is your Azure subscription ID:

PS> armclient token $SubscriptionId | Get-LogicAppTemplate -LogicApp <logic-app-name> -ResourceGroup <Azure-resource-group-name> -SubscriptionId $SubscriptionId -Verbose | Out-File C:\template.json

提取后,可以通过运行以下命令从模板创建参数文件:After extraction, you can then create a parameters file from your template by running this command:

PS> Get-ParameterTemplate -TemplateFile $filename | Out-File '<parameters-file-name>.json'

若要提取 Azure Key Vault 引用(仅限静态),请运行以下命令:For extraction with Azure Key Vault references (static only), run this command:

PS> Get-ParameterTemplate -TemplateFile $filename -KeyVault Static | Out-File $fileNameParameter
参数Parameters 需要Required DescriptionDescription
TemplateFileTemplateFile Yes 模板文件的文件路径The file path to your template file
KeyVaultKeyVault No 描述如何处理可能的 key vault 值的枚举。An enum that describes how to handle possible key vault values. 默认为 NoneThe default is None.

后续步骤Next steps