概述:使用 Azure 资源管理器模板将 Azure 逻辑应用部署自动化Overview: Automate deployment for Azure Logic Apps by using Azure Resource Manager templates

准备好自动创建和部署逻辑应用时,可将逻辑应用的基础工作流定义扩展到 Azure 资源管理器模板中。When you're ready to automate creating and deploying your logic app, you can expand your logic app's underlying workflow definition into an Azure Resource Manager template. 此模板定义了用于预配和部署逻辑应用的基础结构、资源、参数和其他信息。This template defines the infrastructure, resources, parameters, and other information for provisioning and deploying your logic app. 通过为部署时会发生改变的值定义参数(也称为“参数化”),可以根据不同的部署需求重复且一致地部署逻辑应用。By defining parameters for values that vary at deployment, also known as parameterizing, you can repeatedly and consistently deploy logic apps based on different deployment needs.

例如,如果部署到开发、测试和生产环境,则可以对每个环境使用不同的连接字符串。For example, if you deploy to environments for development, test, and production, you likely use different connection strings for each environment. 可以声明接受不同连接字符串的模板参数,然后将这些字符串存储在单独的参数文件中。You can declare template parameters that accept different connection strings and then store those strings in a separate parameters file. 这样,无需更新和重新部署模板即可更改这些值。That way, you can change those values without having to update and redeploy the template. 对于其中的参数值比较敏感或者必须予以保护(例如密码和机密)的方案,可将这些值存储在 Azure Key Vault 中,并让参数文件检索这些值。For scenarios where you have parameter values that are sensitive or must be secured, such as passwords and secrets, you can store those values in Azure Key Vault and have your parameters file retrieve those values. 但是,在这些方案中,需要重新部署才能检索当前值。However, in these scenarios, you'd redeploy to retrieve the current values.

本概述文章介绍包含逻辑应用工作流定义的资源管理器模板中的属性。This overview describes the attributes in a Resource Manager template that includes a logic app workflow definition. 模板和工作流定义都使用 JSON 语法,但两者存在一些差异,因为工作流定义也遵循工作流定义语言架构Both the template and your workflow definition use JSON syntax, but some differences exist because the workflow definition also follows the Workflow Definition Language schema. 例如,模板表达式和工作流定义表达式在引用参数的方式以及可接受的值方面有所不同。For example, template expressions and workflow definition expressions differ in how they reference parameters and the values that they can accept.

提示

若要获取最适合部署的有效参数化逻辑应用模板,请使用 Visual Studio(免费的社区版或更高版本)以及适用于 Visual Studio 的 Azure 逻辑应用工具。For the easiest way to get a valid parameterized logic app template that's 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 Azure into Visual Studio.

或者,可以结合 LogicAppTemplate 模块使用 Azure PowerShell 创建逻辑应用模板。Or, you can create logic app templates by using Azure PowerShell with the LogicAppTemplate module.

本主题中的示例逻辑应用使用一个 Office 365 Outlook 触发器(在新电子邮件抵达时触发)以及一个 Azure Blob 存储操作(用于创建电子邮件正文的 Blob,并将该 Blob 上传到 Azure 存储容器)。The example logic app in this topic uses an Office 365 Outlook trigger that fires when a new email arrives and an Azure Blob Storage action that creates a blob for the email body and uploads that blob to an Azure storage container. 这些示例还演示如何参数化在部署时会改变的值。The examples also show how to parameterize values that vary at deployment.

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

有关示例逻辑应用模板,请参阅以下示例:For sample logic app templates, see these examples:

有关特定于逻辑应用、集成帐户和集成帐户项目的模板资源信息,请参阅 Microsoft.Logic 资源类型For template resource information specific to logic apps, integration accounts, and integration account artifacts, see Microsoft.Logic resource types.

模板结构Template structure

在最高级别,资源管理器模板遵循此结构,Azure 资源管理器模板的结构和语法主题中对此做了全面介绍:At the top level, a Resource Manager template follows this structure, which is fully described in the Azure Resource Manager template structure and syntax topic:

{
   "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
   "contentVersion": "1.0.0.0",
   "parameters": {},
   "variables": {},
   "functions": [],
   "resources": [],
   "outputs": {}
}

对于逻辑应用模板,主要使用以下模板对象:For a logic app template, you primarily work with these template objects:

属性Attribute 说明Description
parameters 声明模板参数,用于接受在 Azure 中创建和自定义部署资源时要使用的值。Declares the template parameters for accepting the values to use when creating and customizing resources for deployment in Azure. 例如,这些参数接受逻辑应用的名称和位置、连接以及部署所需的其他资源的值。For example, these parameters accept the values for your logic app's name and location, connections, and other resources necessary for deployment. 可将这些参数值存储在本主题稍后将会介绍的参数文件中。You can store these parameter values in a parameters file, which is described later in this topic. 有关一般详细信息,请参阅参数 - 资源管理器模板的结构和语法For general details, see Parameters - Resource Manager template structure and syntax.
resources 定义用于创建或更新以及部署到 Azure 资源组的资源,例如逻辑应用、连接、Azure 存储帐户等。Defines the resources to create or update and deploy to an Azure resource group, such as your logic app, connections, Azure storage accounts, and so on. 有关一般详细信息,请参阅资源 - 资源管理器模板的结构和语法For general details, see Resources - Resource Manager template structure and syntax.

逻辑应用模板使用以下文件名格式:Your logic app template uses this file name format:

<逻辑应用名称>.json<logic-app-name>.json

重要

模板语法区分大小写,因此请确保使用一致的大小写。Template syntax is case-sensitive so make sure that you use consistent casing.

模板参数Template parameters

逻辑应用模板包含多个位于不同级别的、可执行不同功能的 parameters 对象。A logic app template has multiple parameters objects that exist at different levels and perform different functions. 例如,在最高级别,可以针对部署期间在 Azure 中创建和部署资源时要接受和使用的值声明模板参数,例如:For example, at the top level, you can declare template parameters for the values to accept and use at deployment when creating and deploying resources in Azure, for example:

  • 你的逻辑应用Your logic app
  • 逻辑用来通过托管连接器访问其他服务和系统的连接Connections that your logic uses to access other services and systems through managed connectors
  • 逻辑应用需要对部署使用的其他资源Other resources that your logic app needs for deployment

例如,如果逻辑应用针对企业对企业 (B2B) 方案使用集成帐户,则模板的顶级 parameters 对象会声明接受该集成帐户的资源 ID 的参数。For example, if your logic app uses an integration account for business-to-business (B2B) scenarios, the template's top-level parameters object declares the parameter that accepts the resource ID for that integration account.

下面是参数定义的一般结构和语法,参数 - 资源管理器模板的结构和语法中对此做了全面介绍:Here is the general structure and syntax for a parameter definition, which is fully described by Parameters - Resource Manager template structure and syntax:

"<parameter-name>": {
   "type": "<parameter-type>",
   "defaultValue": <default-parameter-value>,
   <other-parameter-attributes>,
   "metadata": {
      "description": "<parameter-description>"
   }
},

此示例只显示了用于在 Azure 中创建和部署这些资源的值的模板参数:This example shows just the template parameters for the values used to create and deploy these resources in Azure:

  • 逻辑应用的名称和位置Name and location for your logic app
  • 要对链接到逻辑应用的集成帐户使用的 IDID to use for an integration account that's linked to the logic app
{
   "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
   "contentVersion": "1.0.0.0",
   // Template parameters
   "parameters": {
      "LogicAppName": {
         "type": "string",
         "minLength": 1,
         "maxLength": 80,
         "defaultValue": "MyLogicApp",
         "metadata": {
            "description": "The resource name for the logic app"
         }
      },
      "LogicAppLocation": {
         "type": "string",
         "minLength": 1,
         "defaultValue": "[resourceGroup().location]",
         "metadata": {
            "description": "The resource location for the logic app"
         }
      },
      "LogicAppIntegrationAccount": {
         "type":"string",
         "minLength": 1,
         "defaultValue": "/subscriptions/<Azure-subscription-ID>/resourceGroups/fabrikam-integration-account-rg/providers/Microsoft.Logic/integrationAccounts/fabrikam-integration-account",
         "metadata": {
            "description": "The ID to use for the integration account"
         }
      }
   },
   "variables": {},
   "functions": [],
   "resources": [],
   "outputs": {}
}

除了用于处理敏感值或必须保护的值(例如用户名、密码和机密)的参数以外,所有这些参数都包含 defaultValue 属性,不过,在某些情况下,默认值为空值。Except for parameters that handle values that are sensitive or must be secured, such as usernames, passwords, and secrets, all these parameters include defaultValue attributes, although in some cases, the default values are empty values. 用于这些模板参数的部署值由本主题稍后所述的示例参数文件提供。The deployment values to use for these template parameters are provided by the sample parameters file described later in this topic.

有关保护模板参数的详细信息,请参阅以下主题:For more information about securing template parameters, see these topics:

其他模板对象通常引用模板参数,以便可以使用通过模板参数传递的值,例如:Other template objects often reference template parameters so that they can use the values that pass through template parameters, for example:

  • 本主题稍后所述的模板的资源对象定义 Azure 中要创建和部署的每个资源,例如逻辑应用的资源定义Your template's resources object, described later in this topic, defines each resource in Azure that you want to create and deploy, such as your logic app's resource definition. 这些资源通常使用模板参数值,例如逻辑应用的名称、位置和连接信息。These resources often use template parameter values, such as your logic app's name and location and connection information.

  • 在逻辑应用资源定义的较深级别,工作流定义的参数对象声明要在逻辑应用运行时使用的值的参数。At a deeper level in your logic app's resource definition, your workflow definition's parameters object declares parameters for the values to use at your logic app's runtime. 例如,可以针对 HTTP 触发器用来进行身份验证的用户名和密码声明工作流定义参数。For example, you can declare workflow definition parameters for the username and password that an HTTP trigger uses for authentication. 若要指定工作流定义参数的值,请使用位于工作流定义的外部、但仍位于逻辑应用资源定义的内部的 parameters 对象。 To specify the values for workflow definition parameters, use the parameters object that's outside your workflow definition but still inside your logic app's resource definition. 在此外部 parameters 对象中,可以引用以前声明的模板参数,在部署时,这些参数可以接受参数文件中的值。In this outer parameters object, you can reference previously declared template parameters, which can accept values at deployment from a parameters file.

引用参数时,模板表达式和函数将使用不同的语法,其行为与工作流定义表达式和函数不同。When referencing parameters, template expressions and functions use different syntax and behave differently from workflow definition expressions and functions. 有关这些差异的详细信息,请参阅本主题稍后的对参数的引用For more information about these differences, see References to parameters later in this topic.

最佳做法 - 模板参数Best practices - template parameters

下面是有关定义参数的最佳做法:Here are some best practices for defining parameters:

  • 仅为根据部署需求而异的值声明参数。Declare parameters only for values that vary, based on your deployment needs. 对于尽管部署要求不同,但也仍保持相同的值,请不要声明参数。Don't declare parameters for values that stay the same across different deployment requirements.

  • 包含 defaultValue 属性,对于除敏感值或必须保护的值以外的所有参数,该属性可指定空值。Include the defaultValue attribute, which can specify empty values, for all parameters except for values that are sensitive or must be secured. 始终对用户名、密码和机密使用安全参数。Always use secured parameters for user names, passwords, and secrets. 若要隐藏或保护敏感的参数值,请遵循以下主题中的指导:To hide or protect sensitive parameter values, follow the guidance in these topics:

  • 若要区分工作流定义参数名称和模板参数名称,可以使用描述性的模板参数名称,例如:TemplateFabrikamPasswordTo differentiate template parameter names from workflow definition parameter names, you can use descriptive template parameter names, for example: TemplateFabrikamPassword

有关更多的模板最佳做法,请参阅模板参数的最佳做法For more template best practices, see Best practices for template parameters.

模板参数文件Template parameters file

若要提供模板参数的值,请将这些值存储在参数文件中。To provide the values for template parameters, store those values in a parameters file. 这样,就可以根据部署需求使用不同的参数文件。That way, you can use different parameters files based on your deployment needs. 下面是要使用的文件名格式:Here is the file name format to use:

  • 逻辑应用模板文件名: <逻辑应用名称>.jsonLogic app template file name: <logic-app-name>.json
  • 参数文件名: <逻辑应用名称>.parameters.jsonParameters file name: <logic-app-name>.parameters.json

下面是参数文件中的结构,其中包括一个用于通过 Azure Key Vault 传递受保护参数值的密钥保管库引用:Here is the structure inside the parameters file, which includes a key vault reference for passing a secured parameter value with Azure Key Vault:

{
   "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
   "contentVersion": "1.0.0.0",
   // Template parameter values
   "parameters": {
      "<parameter-name-1>": {
         "value": "<parameter-value>"
      },
      "<parameter-name-2>": {
         "value": "<parameter-value>"
      },
      "<secured-parameter-name>": {
         "reference": {
            "keyVault": {
               "id": "/subscriptions/<Azure-subscription-ID>/resourceGroups/<Azure-resource-group-name>/Microsoft.KeyVault/vaults/<key-vault-name>",
            },
            "secretName: "<secret-name>"
         }
      },
      <other-parameter-values>
   }
}

此示例参数文件指定前面在本主题中声明的模板参数的值:This example parameters file specifies the values for the template parameters declared earlier in this topic:

{
   "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
   "contentVersion": "1.0.0.0",
   // Template parameter values
   "parameters": {
      "LogicAppName": {
         "value": "Email-Processor-Logic-App"
      },
      "LogicAppLocation": {
         "value": "chinanorth"
      }
   }
}

模板资源Template resources

模板包含一个 resources 对象,该对象是一个数组,包含要在 Azure 中创建和部署的每个资源的定义,例如逻辑应用的资源定义、任何连接资源定义,以及逻辑应用需要对部署使用的任何其他资源。Your template has a resources object, which is an array that contains definitions for each resource to create and deploy in Azure, such as your logic app's resource definition, any connection resource definitions, and any other resources that your logic app needs for deployment.

{
   "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
   "contentVersion": "1.0.0.0",
   "parameters": {<template-parameters>},
   "variables": {},
   "functions": [],
   "resources": [
      {
         <logic-app-resource-definition>
      },
      // Start connection resource definitions
      {
         <connection-resource-definition-1>
      },
      {
         <connection-resource-definition-2>
      }
   ],
   "outputs": {}
}

备注

模板可包含多个逻辑应用的资源定义,因此请确保所有逻辑应用资源指定相同的 Azure 资源组。Templates can include resource definitions for multiple logic apps, so make sure that all your logic app resources specify the same Azure resource group. 使用 Visual Studio 将模板部署到 Azure 资源组时,系统会提示你指定要打开的逻辑应用。When you deploy the template to an Azure resource group by using Visual Studio, you're prompted for which logic app that you want to open. 此外,Azure 资源组项目可包含多个模板,因此请确保在出现提示时选择正确的参数文件。Also, your Azure resource group project can contain more than one template, so make sure that you select the correct parameters file when prompted.

有关模板资源及其属性的一般信息,请参阅以下主题:For general information about template resources and their attributes, see these topics:

逻辑应用资源定义Logic app resource definition

逻辑应用的资源定义从 properties 对象开始,该对象包含以下信息:Your logic app's resource definition starts with the properties object, which includes this information:

  • 逻辑应用在部署时的状态Your logic app's state at deployment
  • 逻辑应用使用的任何集成帐户的 IDThe ID for any integration account used by your logic app
  • 逻辑应用的工作流定义Your logic app's workflow definition
  • 用于设置要在运行时使用的值的 parameters 对象A parameters object that sets the values to use at runtime
  • 有关逻辑应用的其他资源信息,例如名称、类型、位置等Other resource information about your logic app, such as name, type, location, and so on
{
   "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
   "contentVersion": "1.0.0.0",
   "parameters": {<template-parameters>},
   "variables": {},
   "functions": [],
   "resources": [
      {
         // Start logic app resource definition
         "properties": {
            "state": "<Enabled or Disabled>",
            "integrationAccount": {
               "id": "[parameters('LogicAppIntegrationAccount')]" // Template parameter reference
            },
            "definition": {<workflow-definition>},
            "parameters": {<workflow-definition-parameter-values>},
            "accessControl": {}
         },
         "name": "[parameters('LogicAppName')]", // Template parameter reference
         "type": "Microsoft.Logic/workflows",
         "location": "[parameters('LogicAppLocation')]", // Template parameter reference
         "tags": {
           "displayName": "LogicApp"
         },
         "apiVersion": "2016-06-01",
         "dependsOn": [
         ]
      }
      // End logic app resource definition
   ],
   "outputs": {}
}

下面是特定于逻辑应用资源定义的属性:Here are the attributes that are specific to your logic app resource definition:

属性Attribute 必须Required 类型Type 说明Description
state Yes StringString 逻辑应用在部署时的状态,Enabled 表示逻辑应用处于活动状态,Disabled 表示逻辑应用处于非活动状态。Your logic app's state at deployment where Enabled means your logic app is live and Disabled means that your logic app is inactive. 例如,如果你尚未准备好推出逻辑应用,而是想要部署草稿版本,则可以使用 Disabled 选项。For example, if you're not ready for your logic app to go live but want to deploy a draft version, you can use the Disabled option.
integrationAccount No ObjectObject 如果逻辑应用使用集成帐户(用于存储企业到企业 (B2B) 方案的项目),则此对象包含用于指定集成帐户 ID 的 id 属性。If your logic app uses an integration account, which stores artifacts for business-to-business (B2B) scenarios, this object includes the id attribute, which specifies the ID for the integration account.
definition Yes ObjectObject 逻辑应用的基础工作流定义,它是代码视图中显示的相同对象,工作流定义语言的架构参考主题中对此做了全面介绍。Your logic app's underlying workflow definition, which is the same object that appears in code view and is fully described in the Schema reference for Workflow Definition Language topic. 在此工作流定义中,parameters 对象声明要在逻辑应用运行时使用的值的参数。In this workflow definition, the parameters object declares parameters for the values to use at logic app runtime. 有关详细信息,请参阅工作流定义和参数For more information, see Workflow definition and parameters.

若要查看逻辑应用工作流定义中的属性,请在 Azure 门户或 Visual Studio 中或使用 Azure 资源浏览器之类的工具,从“设计视图”切换到“代码视图”。To view the attributes in your logic app's workflow definition, switch from "design view" to "code view" in the Azure portal or Visual Studio, or by using a tool such as Azure Resource Explorer.

parameters No ObjectObject 要在逻辑应用运行时使用的工作流定义参数值The workflow definition parameter values to use at logic app runtime. 这些值的参数定义显示在工作流定义的 parameters 对象中The parameter definitions for these values appear inside your workflow definition's parameters object. 此外,如果逻辑应用使用托管连接器来访问其他服务和系统,则此对象将包含一个用于设置要在运行时使用的连接值的 $connections 对象。Also, if your logic app uses managed connectors for accessing other services and systems, this object includes a $connections object that sets the connection values to use at runtime.
accessControl No ObjectObject 用于指定逻辑应用的安全属性,例如限制对请求触发器或运行历史记录输入和输出的 IP 访问。For specifying security attributes for your logic app, such as restricting IP access to request triggers or run history inputs and outputs. 有关详细信息,请参阅保护对逻辑应用的访问For more information, see Secure access to logic apps.

有关特定于逻辑应用、集成帐户和集成帐户项目的模板资源信息,请参阅 Microsoft.Logic 资源类型For template resource information specific to logic apps, integration accounts, and integration account artifacts, see Microsoft.Logic resource types.

工作流定义和参数Workflow definition and parameters

逻辑应用的工作流定义显示在 definition 对象中,而该对象显示在逻辑应用资源定义中的 properties 对象内。Your logic app's workflow definition appears in the definition object, which appears in the properties object inside your logic app's resource definition. definition 对象是代码视图中显示的相同对象,工作流定义语言的架构参考主题中对此做了全面介绍。This definition object is the same object that appears in code view and is fully described in the Schema reference for Workflow Definition Language topic. 工作流定义包含一个内部 parameters 声明对象,在对象中,可以定义在运行时工作流定义要使用的值的新参数,或编辑现有的参数。Your workflow definition includes an inner parameters declaration object where you can define new or edit existing parameters for the values that are used by your workflow definition at runtime. 然后,可以在工作流中的触发器或操作内部引用这些参数。You can then reference these parameters inside the trigger or actions in your workflow. 默认情况下,除非逻辑应用通过托管连接器与其他服务和系统建立了连接,否则此 parameters 对象是空的。By default, this parameters object is empty unless your logic app creates connections to other services and systems through managed connectors.

若要设置工作流定义参数的值,请使用位于工作流定义的外部、但仍位于逻辑应用资源定义的内部的 parameters 对象。 To set the values for workflow definition parameters, use the parameters object that's outside your workflow definition but still inside your logic app's resource definition. 然后,在此外部 parameters 对象中,可以引用以前声明的模板参数,在部署时,这些参数可以接受参数文件中的值。In this outer parameters object, you can then reference your previously declared template parameters, which can accept values at deployment from a parameters file.

提示

最佳做法是,不要直接从工作流定义内部引用部署时要评估的模板参数。As a best practice, don't directly reference template parameters, which are evaluated at deployment, from inside the workflow definition. 而是声明一个工作流定义参数,然后可以在位于工作流定义的外部、但仍位于逻辑应用资源定义的内部的 parameters 对象中设置该参数。 Instead, declare a workflow definition parameter, which you can then set in the parameters object that's outside your workflow definition but still inside your logic app's resource definition. 有关详细信息,请参阅对参数的引用For more information, see References to parameters.

此语法显示了可在模板和工作流定义级别声明的哪个位置声明参数,以及可在哪个位置通过引用模板和工作流定义参数来设置这些参数值:This syntax shows where you can declare parameters at both the template and workflow definition levels along with where you can set those parameter values by referencing the template and workflow definition parameters:

{
   "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
   "contentVersion": "1.0.0.0",
   // Template parameters
   "parameters": {
      "<template-parameter-name>": {
         "type": "<parameter-type>",
         "defaultValue": "<parameter-default-value>",
         "metadata": {
            "description": "<parameter-description>"
         }
      }
   },
   "variables": {},
   "functions": [],
   "resources": [
      {
         // Start logic app resource definition
         "properties": {
            <other-logic-app-resource-properties>,
            "definition": {
               "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
               "actions": {<action-definitions>},
               // Workflow definition parameters
               "parameters": {
                  "<workflow-definition-parameter-name>": {
                     "type": "<parameter-type>",
                     "defaultValue": "<parameter-default-value>",
                     "metadata": {
                        "description": "<parameter-description>"
                     }
                  }
               },
               "triggers": {
                  "<trigger-name>": {
                     "type": "<trigger-type>",
                     "inputs": {
                         // Workflow definition parameter reference
                         "<attribute-name>": "@parameters('<workflow-definition-parameter-name')"
                     }
                  }
               },
               <...>
            },
            // Workflow definition parameter value
            "parameters": {
               "<workflow-definition-parameter-name>": { 
                  "value": "[parameters('<template-parameter-name>')]"
               }
            },
            "accessControl": {}
         },
         <other-logic-app-resource-definition-attributes>
      }
      // End logic app resource definition
   ],
   "outputs": {}
}

安全工作流定义参数Secure workflow definition parameters

对于用于在运行时处理敏感信息、密码、访问密钥或机密的工作流定义参数,请将该参数声明或编辑为使用 securestringsecureobject 参数类型。For a workflow definition parameter that handles sensitive information, passwords, access keys, or secrets at runtime, declare or edit the parameter to use the securestring or secureobject parameter type. 可以在工作流定义中全面引用此参数。You can reference this parameter throughout and within your workflow definition. 在模板的最高级别,声明一个用于在部署时处理此信息的相同类型的参数。At the template's top level, declare a parameter that has the same type to handle this information at deployment.

若要设置工作流定义参数的值,请使用位于工作流定义的外部、但仍位于逻辑应用资源定义的内部的 parameters 对象来引用模板参数。 To set the value for the workflow definition parameter, use the parameters object that's outside your workflow definition but still inside your logic app resource definition to reference the template parameter. 最后,若要在部署时将值传递给模板参数,请将该值存储在 Azure Key Vault 中,并在部署时由模板使用的参数文件中引用该 Key Vault。Finally, to pass the value to your template parameter at deployment, store that value in Azure Key Vault and reference that key vault in the parameters file that's used by your template at deployment.

此示例模板演示如何在必要时定义安全参数来完成这些任务,以便可以将这些参数的值存储在 Azure Key Vault 中:This example template shows how you can complete these tasks by defining secured parameters when necessary so that you can store their values in Azure Key Vault:

  • 为用于对访问进行身份验证的值声明受保护参数。Declare secured parameters for the values used to authenticate access.
  • 在模板和工作流定义级别使用这些值。Use these values at both the template and workflow definition levels.
  • 使用参数文件提供这些值。Provide these values by using a parameters file.

模板Template

{
   "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
   "contentVersion": "1.0.0.0",
   "parameters": {
      <previously-defined-template-parameters>,
      // Additional template parameters for passing values to use in workflow definition
      "TemplateAuthenticationType": {
         "type": "string",
         "defaultValue": "",
         "metadata": {
            "description": "The type of authentication used for the Fabrikam portal"
         }
      },
      "TemplateFabrikamPassword": {
         "type": "securestring",
         "metadata": {
            "description": "The password for the Fabrikam portal"
         }
      },
      "TemplateFabrikamUserName": {
         "type": "securestring",
         "metadata": {
            "description": "The username for the Fabrikam portal"
         }
      }
   },
   "variables": {},
   "functions": [],
   "resources": [
      {
         // Start logic app resource definition
         "properties": {
            <other-logic-app-resource-properties>,
            // Start workflow definition
            "definition": {
               "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
               "actions": {<action-definitions>},
               // Workflow definition parameters
               "parameters": {
                  "authenticationType": {
                     "type": "string",
                     "defaultValue": "",
                     "metadata": {
                        "description": "The type of authentication used for the Fabrikam portal"
                     }
                  },
                  "fabrikamPassword": {
                     "type": "securestring",
                     "metadata": {
                        "description": "The password for the Fabrikam portal"
                     }
                  },
                  "fabrikamUserName": {
                     "type": "securestring",
                     "metadata": {
                        "description": "The username for the Fabrikam portal"
                     }
                  }
               },
               "triggers": {
                  "HTTP": {
                     "inputs": {
                        "authentication": {
                           // Reference workflow definition parameters
                           "password": "@parameters('fabrikamPassword')",
                           "type": "@parameters('authenticationType')",
                           "username": "@parameters('fabrikamUserName')"
                        }
                     },
                     "recurrence": {<...>},
                     "type": "Http"
                  }
               },
               <...>
            },
            // End workflow definition
            // Start workflow definition parameter values
            "parameters": {
               "authenticationType": "[parameters('TemplateAuthenticationType')]", // Template parameter reference
               "fabrikamPassword": "[parameters('TemplateFabrikamPassword')]", // Template parameter reference
               "fabrikamUserName": "[parameters('TemplateFabrikamUserName')]" // Template parameter reference
            },
            "accessControl": {}
         },
         <other-logic-app-resource-attributes>
      }
      // End logic app resource definition
   ],
   "outputs": {}
}

参数文件Parameters file

{
   "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
   "contentVersion": "1.0.0.0",
   // Template parameter values
   "parameters": {
      <previously-defined-template-parameter-values>,
     "TemplateAuthenticationType": {
        "value": "Basic"
     },
     "TemplateFabrikamPassword": {
        "reference": {
           "keyVault": {
              "id": "/subscriptions/<Azure-subscription-ID>/resourceGroups/<Azure-resource-group-name>/Microsoft.KeyVault/vaults/fabrikam-key-vault"
           },
           "secretName": "FabrikamPassword"
        }
     },
     "TemplateFabrikamUserName": {
        "reference": {
           "keyVault": {
              "id": "/subscriptions/<Azure-subscription-ID>/resourceGroups/<Azure-resource-group-name>/Microsoft.KeyVault/vaults/fabrikam-key-vault"
           },
           "secretName": "FabrikamUserName"
        }
     }
   }
}

最佳做法 - 工作流定义参数Best practices - workflow definition parameters

若要确保逻辑应用设计器正确显示工作流定义参数,请遵循以下最佳做法:To make sure that the Logic App Designer can correctly show workflow definition parameters, follow these best practices:

有关工作流定义参数的详细信息,请参阅参数 - 工作流定义语言For more information about workflow definition parameters, see Parameters - Workflow Definition Language.

连接资源定义Connection resource definitions

当逻辑应用通过托管连接器来创建并使用与其他服务和系统的连接时,模板的 resources 对象将包含这些连接的资源定义。When your logic app creates and uses connections to other services and system by using managed connectors, your template's resources object contains the resource definitions for those connections.

{
   "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
   "contentVersion": "1.0.0.0",
   "parameters": {<template-parameters>},
   "variables": {},
   "functions": [],
   "resources": [
      {
         <logic-app-resource-definition>
      },
      // Start connection resource definitions
      {
         <connection-resource-definition-1>
      },
      {
         <connection-resource-definition-2>
      }
   ],
   "outputs": {}
}

连接资源定义引用模板的顶级参数作为其值,这意味着,在部署时可以使用参数文件提供这些值。Connection resource definitions reference the template's top-level parameters for their values, which means you can provide these values at deployment by using a parameters file. 确保连接使用与逻辑应用相同的 Azure 资源组和位置。Make sure that connections use the same Azure resource group and location as your logic app.

下面是 Office 365 Outlook 连接的示例资源定义以及相应的模板参数:Here is an example resource definition for an Office 365 Outlook connection and the corresponding template parameters:

{
   "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
   "contentVersion": "1.0.0.0",
   // Template parameters
   "parameters": {
      "LogicAppName": {<parameter-definition>},
      "LogicAppLocation": {<parameter-definition>},
      "office365_1_Connection_Name": {
         "type": "string",
         "defaultValue": "office365",
         "metadata": {
            "description": "The resource name for the Office 365 Outlook connection"
         }
      },
      "office365_1_Connection_DisplayName": {
         "type": "string",
         "defaultValue": "",
         "metadata": {
            "description": "The display name for the Office 365 Outlook connection"
         }
      }
   },
   "variables": {},
   "functions": [],
   "resources": [
      {
         <logic-app-resource-definition>
      },
      // Office 365 Outlook API connection resource definition
      {
         "type": "MICROSOFT.WEB/CONNECTIONS",
         "apiVersion": "2016-06-01",
         // Template parameter reference for connection name
         "name": "[parameters('office365_1_Connection_Name')]",
         // Template parameter reference for connection resource location. Must match logic app location.
         "location": "[parameters('LogicAppLocation')]",
         "properties": {
            "api": {
               // Connector ID
               "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', parameters('LogicAppLocation'), '/managedApis/', 'office365')]"
            },
            // Template parameter reference for connection display name
            "displayName": "[parameters('office365_1_Connection_DisplayName')]"
         }
      }
   ],
   "outputs": {}
}

逻辑应用的资源定义还可通过以下方式来与连接资源定义配合使用:Your logic app's resource definition also works with connection resource definitions in these ways:

  • 在工作流定义中,parameters 对象为逻辑应用运行时要使用的连接值声明一个 $connections 参数。Inside your workflow definition, the parameters object declares a $connections parameter for the connection values to use at logic app runtime. 此外,创建连接的触发器或操作将使用通过此 $connections 参数传递的相应值。Also, the trigger or action that creates a connection uses the corresponding values that pass through this $connections parameter.

  • 在工作流定义的外部、但仍在逻辑应用资源定义的内部,另一个 parameters 对象通过引用相应的模板参数,来设置要在运行时对 $connections 参数使用的值。 Outside your workflow definition but still inside your logic app's resource definition, another parameters object sets the values to use at runtime for the $connections parameter by referencing the corresponding template parameters. 这些值使用模板表达式来引用安全存储逻辑应用中的连接的元数据的资源。These values use template expressions to reference resources that securely store the metadata for the connections in your logic app.

    例如,元数据可以包含可存储在 Azure Key Vault 中的连接字符串和访问令牌。For example, metadata can include connection strings and access tokens, which you can store in Azure Key Vault. 若要将这些值传递到模板参数,请在部署时模板要使用的参数文件中引用该 Key Vault。To pass those values to your template parameters, you reference that key vault in the parameters file that's used by your template at deployment. 有关引用参数的差异的详细信息,请参阅本主题稍后的对参数的引用For more information about differences in referencing parameters, see References to parameters later in this topic.

    通过 Azure 门户或 Visual Studio 在代码视图中打开逻辑应用的工作流定义时,$connections 对象将显示在工作流定义的外部,但处于同一级别。When you open your logic app's workflow definition in code view through the Azure portal or Visual Studio, the $connections object appears outside your workflow definition but at the same level. 代码视图的这种顺序可以方便在手动更新工作流定义时引用这些参数:This ordering in code view makes these parameters easier to reference when you manually update the workflow definition:

    {
       "$connections": {<workflow-definition-parameter-connection-values-runtime},
       "definition": {<workflow-definition>}
    }
    
  • 逻辑应用的资源定义包含一个 dependsOn 对象,该对象指定逻辑应用使用的连接的依赖关系。Your logic app's resource definition has a dependsOn object that specifies the dependencies on the connections used by your logic app.

创建的每个连接在 Azure 中都有唯一的名称。Each connection that you create has a unique name in Azure. 与同一服务或系统建立多个连接时,每个连接名称的后面将追加一个编号,每建立一个新连接,此编号就会递增,例如 office365office365-1、依此类推。When you create multiple connections to the same service or system, each connection name is appended with a number, which increments with each new connection created, for example, office365, office365-1, and so on.

此示例演示了逻辑应用的资源定义与 Office 365 Outlook 的连接资源定义之间的交互:This example shows the interactions between your logic app's resource definition and a connection resource definition for Office 365 Outlook:

{
   "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
   "contentVersion": "1.0.0.0",
   // Template parameters
   "parameters": {
      "LogicAppName": {<parameter-definition>},
      "LogicAppLocation": {<parameter-definition>},
      "office365_1_Connection_Name": {<parameter-definition>},
      "office365_1_Connection_DisplayName": {<parameter-definition>}
   },
   "variables": {},
   "functions": [],
   "resources": [
      {
         // Start logic app resource definition
         "properties": {
            <...>,
            "definition": {
               <...>,
               "parameters": {
                  // Workflow definition "$connections" parameter
                  "$connections": {
                     "defaultValue": {},
                     "type": "Object"
                  }
               },
               <...>
            },
            "parameters": {
               // Workflow definition "$connections" parameter values to use at runtime
               "$connections": {
                  "value": {
                     "office365": {
                        // Template parameter references
                        "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', parameters('LogicAppLocation'), '/managedApis/', 'office365')]",
                        "connectionId": "[resourceId('Microsoft.Web/connections', parameters('office365_1_Connection_Name'))]",
                        "connectionName": "[parameters('office365_1_Connection_Name')]"
                     }
                  }
               }
            },
            <other-logic-app-resource-information>,
            "dependsOn": [
               "[resourceId('Microsoft.Web/connections', parameters('office365_1_Connection_Name'))]"
            ]
         }
         // End logic app resource definition
      },
      // Office 365 Outlook API connection resource definition
      {
         "type": "MICROSOFT.WEB/CONNECTIONS",
         "apiVersion": "2016-06-01",
         // Template parameter reference for connection name
         "name": "[parameters('office365_1_Connection_Name')]",
         // Template parameter reference for connection resource location. Must match logic app location.
         "location": "[parameters('LogicAppLocation')]",
         "properties": {
            "api": {
               // Connector ID
               "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', parameters('LogicAppLocation'), '/managedApis/', 'office365')]"
            },
            // Template parameter reference for connection display name
            "displayName": "[parameters('office365_1_Connection_DisplayName')]"
         }
      }
   ],
   "outputs": {}
}

安全连接参数Secure connection parameters

对于处理敏感信息、密码、访问密钥或机密的连接参数,连接的资源定义包含一个 parameterValues 对象,该对象以名称-值对格式指定这些值。For a connection parameter that handles sensitive information, passwords, access keys, or secrets, the connection's resource definition includes a parameterValues object that specifies these values in name-value pair format. 若要隐藏此信息,可以使用 securestringsecureobject 参数类型声明或编辑这些值的模板参数。To hide this information, you can declare or edit the template parameters for these values by using the securestring or secureobject parameter types. 然后,可将该信息存储在 Azure Key Vault 中。You can then store that information in Azure Key Vault. 若要将这些值传递到模板参数,请在部署时模板要使用的参数文件中引用该 Key Vault。To pass those values to your template parameters, you reference that key vault in the parameters file that's used by your template at deployment.

以下示例提供 Azure Blob 存储连接的帐户名称和访问密钥:Here is an example that provides the account name and access key for an Azure Blob Storage connection:

参数文件Parameters file

{
   "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
   "contentVersion": "1.0.0.0",
   // Template parameter values
   "parameters": {
      "LogicAppName": {
         "value": "Email-Processor-Logic-App"
      },
      "LogicAppLocation": {
         "value": "chinanorth"
      },
      "azureblob_1_Connection_Name": {
         "value": "Fabrikam-Azure-Blob-Storage-Connection"
      },
      "azureblob_1_Connection_DisplayName": {
         "value": "Fabrikam-Storage"
      },
      "azureblob_1_accountName": {
         "value": "Fabrikam-Storage-Account"
      },
      "azureblob_1_accessKey": {
         "reference": {
            "keyVault": {
               "id": "/subscriptions/<Azure-subscription-ID>/resourceGroups/<Azure-resource-group-name>/Microsoft.KeyVault/vaults/fabrikam-key-vault"
            },
            "secretName": "FabrikamStorageKey"
         }
      }
   }
}

模板Template

{
   "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
   "contentVersion": "1.0.0.0",
   // Template parameters
   "parameters": {
      "LogicAppName": {<parameter-definition>},
      "LogicAppLocation": {<parameter-definition>},
      "azureblob_1_Connection_Name": {<parameter-definition>},
      "azureblob_1_Connection_DisplayName": {<parameter-definition>},
      "azureblob_1_accountName": {
         "type": "string",
         "defaultValue": "",
         "metadata": {
            "description": "Name of the storage account the connector should use."
         }
      },
      "azureblob_1_accessKey": {
         "type": "secureobject",
         "metadata": {
            "description": "Specify a valid primary/secondary storage account access key."
         }
      }
   },
   "variables": {},
   "functions": [],
   "resources": [
      {
         "properties": {
            "state": "Disabled",
            "definition": {
               "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
               "actions": {
                  // Azure Blob Storage action
                  "Create_blob": {
                     "type": "ApiConnection",
                     "inputs": {
                        "host": {
                           "connection": {
                              // Workflow definition parameter reference for values to use at runtime
                              "name": "@parameters('$connections')['azureblob']['connectionId']"
                           }
                        },
                     },
                     "method": "post",
                     "body": "@triggerBody()?['Body']",
                     "path": "/datasets/default/files",
                     "queries": {
                        "folderPath": "/emails",
                        "name": "@triggerBody()?['Subject']",
                        "queryParametersSingleEncoded": true
                     },
                     "runAfter": {},
                     "runtimeConfiguration": {
                        "contentTransfer": {
                           "transferMode": "Chunked"
                        }
                     }
                  }
               },
               "parameters": {
                  // Workflow definition parameter for values to use at runtime
                  "$connections": {
                     "defaultValue": {},
                     "type": "Object"
                  }
               },
               "triggers": {<trigger-definition>},
               "contentVersion": "1.0.0.0",
               "outputs": {}
            },
            "parameters": {
               "$connections": {
                  "value": {
                     // Template parameter references for values to use at runtime
                     "azureblob": {
                        "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', parameters('LogicAppLocation'), '/managedApis/', 'azureblob')]",
                        "connectionId": "[resourceId('Microsoft.Web/connections', parameters('azureblob_1_Connection_Name'))]",
                        "connectionName": "[parameters('azureblob_1_Connection_Name')]"
                    }
                  }
               }
            },
            "name": "[parameters('LogicAppName')]",
            "type": "Microsoft.Logic/workflows",
            "location": "[parameters('LogicAppLocation')]",
            "tags": {
               "displayName": "LogicApp"
            },
            "apiVersion": "2016-06-01",
            // Template parameter reference for value to use at deployment
            "dependsOn": [
               "[resourceId('Microsoft.Web/connections', parameters('azureblob_1_Connection_Name'))]"
            ]
         }
      },
      // Azure Blob Storage API connection resource definition
      {
         "type": "MICROSOFT.WEB/CONNECTIONS",
         "apiVersion": "2016-06-01",
         "name": "[parameters('azureblob_1_Connection_Name')]",
         "location": "[parameters('LogicAppLocation')]",
         "properties": {
            "api": {
               "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', parameters('LogicAppLocation'), '/managedApis/', 'azureblob')]"
            },
            "displayName": "[parameters('azureblob_1_Connection_DisplayName')]",
            // Template parameter reference for values to use at deployment
            "parameterValues": {
               "accountName": "[parameters('azureblob_1_accountName')]",
               "accessKey": "[parameters('azureblob_1_accessKey')]"
            }
         }
      }
   ],
   "outputs": {}
}

身份验证连接Authenticate connections

部署后,逻辑应用将使用有效参数进行端到端的运行。After deployment, your logic app works end-to-end with valid parameters. 但是,仍然必须授权任何 OAuth 连接,以生成用于对凭据进行身份验证的有效访问令牌。However, you must still authorize any OAuth connections to generate valid access tokens for authenticating your credentials. 有关详细信息,请参阅授权 OAuth 连接For more information, see Authorize OAuth connections.

某些连接支持使用 Azure Active Directory (Azure AD) 服务主体来授权已在 Azure AD 中注册的逻辑应用的连接。Some connections support using an Azure Active Directory (Azure AD) service principal to authorize connections for a logic app that's registered in Azure AD. 例如,以下 Azure Data Lake 连接资源定义显示了如何引用用于处理服务主体信息的模板参数,以及模板如何声明这些参数:For example, this Azure Data Lake connection resource definition shows how to reference the template parameters that handle the service principal's information and how the template declares these parameters:

连接资源定义Connection resource definition

{
   <other-template-objects>
   "type": "MICROSOFT.WEB/CONNECTIONS",
   "apiVersion": "2016-06-01",
   "name": "[parameters('azuredatalake_1_Connection_Name')]",
   "location": "[parameters('LogicAppLocation')]",
   "properties": {
      "api": {
         "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', 'resourceGroup().location', '/managedApis/', 'azuredatalake')]"
      },
      "displayName": "[parameters('azuredatalake_1_Connection_DisplayName')]",
      "parameterValues": {
         "token:clientId": "[parameters('azuredatalake_1_token:clientId')]",
         "token:clientSecret": "[parameters('azuredatalake_1_token:clientSecret')]",
         "token:TenantId": "[parameters('azuredatalake_1_token:TenantId')]",
         "token:grantType": "[parameters('azuredatalake_1_token:grantType')]"
      }
   }
}
属性Attribute 说明Description
token:clientId 与服务主体关联的应用程序或客户端 IDThe application or client ID associated with your service principal
token:clientSecret 与服务主体关联的密钥值The key value associated with your service principal
token:TenantId Azure AD 租户的目录 IDThe directory ID for your Azure AD tenant
token:grantType 请求的授权类型,必须为 client_credentialsThe requested grant type, which must be client_credentials. 有关详细信息,请参阅 Microsoft 标识平台和 OAuth 2.0 客户端凭据流For more information, see Microsoft identity platform and the OAuth 2.0 client credentials flow.

模板参数定义Template parameter definitions

模板的顶级 parameters 对象为示例连接声明这些参数:The template's top-level parameters object declares these parameters for the example connection:

{
   "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
   "contentVersion": "1.0.0.0",
   "parameters": {
      "azuredatalake_1_Connection_Name": {
        "type": "string",
        "defaultValue": "azuredatalake"
      },
      "azuredatalake_1_Connection_DisplayName": {
        "type": "string",
        "defaultValue": "<connection-name>"
      },
      "azuredatalake_1_token:clientId": {
        "type": "securestring",
        "metadata": {
          "description": "Client (or Application) ID of the Azure Active Directory application."
        }
      },
      "azuredatalake_1_token:clientSecret": {
        "type": "securestring",
        "metadata": {
          "description": "Client secret of the Azure Active Directory application."
        }
      },
      "azuredatalake_1_token:TenantId": {
        "type": "securestring",
        "metadata": {
          "description": "The tenant ID of for the Azure Active Directory application."
        }
      },
      "azuredatalake_1_token:resourceUri": {
        "type": "string",
        "metadata": {
          "description": "The resource you are requesting authorization to use."
        }
      },
      "azuredatalake_1_token:grantType": {
        "type": "string",
        "metadata": {
          "description": "Grant type"
        },
        "defaultValue": "client_credentials",
        "allowedValues": [
          "client_credentials"
        ]
      },
      // Other template parameters
   }
   // Other template objects
}

有关使用服务主体的详细信息,请参阅以下主题:For more information about working with service principals, see these topics:

对参数的引用References to parameters

若要引用模板参数,可以配合使用部署时评估的模板表达式和模板函数To reference template parameters, you can use template expressions with template functions, which are evaluated at deployment. 模板表达式使用方括号 ( [] ):Template expressions use square brackets ([]):

"<attribute-name>": "[parameters('<template-parameter-name>')]"

若要引用工作流定义参数,请使用在运行时评估的工作流定义语言表达式和函数To reference workflow definition parameters, you use Workflow Definition Language expressions and functions, which are evaluated at runtime. 你可能会发现,某些模板函数和工作流定义函数同名。You might notice that some template functions and workflow definition functions have the same name. 工作流定义表达式以 @ 符号开头:Workflow definition expressions start with the "at" symbol (@):

"<attribute-name>": "@parameters('<workflow-definition-parameter-name>')"

可将模板参数值传递到工作流定义,供逻辑应用在运行时使用。You can pass template parameter values to your workflow definition for your logic app to use at runtime. 但是,请避免在工作流定义中使用模板参数、表达式和语法,因为逻辑应用设计器不支持模板元素。However, avoid using template parameters, expressions, and syntax in your workflow definition because the Logic App Designer doesn't support template elements. 此外,由于表达式的评估差异,模板语法和表达式可能会使代码变得复杂。Also, template syntax and expressions can complicate your code due to differences in when expressions are evaluated.

应该遵循本文所述的一般步骤来声明和引用要在运行时使用的工作流定义参数、声明和引用要在部署时使用的模板参数,并使用参数文件指定要在部署时传入的值。Instead, follow these general steps to declare and reference the workflow definition parameters to use at runtime, declare and reference the template parameters to use at deployment, and specify the values to pass in at deployment by using a parameters file. 有关完整详细信息,请参阅本主题前面的工作流定义和参数部分。For full details, see the Workflow definition and parameters section earlier in this topic.

  1. 创建模板,并为要在部署时接受和使用的值声明模板参数。Create your template and declare the template parameters for the values to accept and use at deployment.

  2. 在工作流定义中,为要在运行时接受并使用的值声明参数。In your workflow definition, declare the parameters for the values to accept and use at runtime. 然后,可以在工作流定义中全面引用这些值。You can then reference these values throughout and within your workflow definition.

  3. 在位于工作流定义的外部、但仍位于逻辑应用资源定义的内部的 对象中,通过引用相应的模板参数来设置工作流定义参数的值。parameters In the parameters object that's outside your workflow definition but still inside your logic app's resource definition, set the values for your workflow definition parameters by referencing the corresponding template parameters. 这样,便可以将模板参数值传入工作流定义参数。That way, you can pass template parameter values into your workflow definition parameters.

  4. 在参数文件中,指定部署时要使用的模板的值。In the parameters file, specify the values for your template to use at deployment.

完整示例模板Full example template

下面是本主题中的示例使用的参数化示例模板:Here is the parameterized sample template that's used by this topic's examples:

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
   "parameters": {
      "LogicAppName": {
         "type": "string",
         "minLength": 1,
         "maxLength": 80,
         "defaultValue": "MyLogicApp",
         "metadata": {
            "description": "The resource name to use for the logic app"
         }
      },
      "LogicAppLocation": {
         "type": "string",
         "minLength": 1,
         "defaultValue": "[resourceGroup().location]",
         "metadata": {
            "description": "The resource location to use for the logic app"
         }
      },
      "office365_1_Connection_Name": {
         "type": "string",
         "defaultValue": "office365",
         "metadata": {
            "description": "The resource name to use for the Office 365 Outlook connection"
         }
      },
      "office365_1_Connection_DisplayName": {
         "type": "string",
         "defaultValue": "",
         "metadata": {
            "description": "The display name to use for the Office 365 Outlook connection"
         }
      },
      "azureblob_1_Connection_Name": {
         "type": "string",
         "defaultValue": "azureblob",
         "metadata": {
            "description": "The resource name to use for the Azure Blob storage account connection"
         }
      },
      "azureblob_1_Connection_DisplayName": {
         "type": "string",
         "defaultValue": "",
         "metadata": {
            "description": "Name of the storage account the connector should use."
         },

      },
      "azureblob_1_accountName": {
         "type": "string",
         "defaultValue": "",
         "metadata": {
            "description": "Name of the storage account the connector should use."
         }
      },
      "azureblob_1_accessKey": {
         "type": "securestring",
         "metadata": {
            "description": "Specify a valid primary/secondary storage account access key."
         }
      },
      "LogicAppIntegrationAccount": {
         "type":"string",
         "minLength": 1,
         "defaultValue": "/subscriptions/<Azure-subscription-ID>/resourceGroups/fabrikam-integration-account-rg/providers/Microsoft.Logic/integrationAccounts/fabrikam-integration-account",
         "metadata": {
            "description": "The ID to use for the integration account"
         }
      }
   },
   "variables": {},
   "resources": [
      {
         "properties": {
            "state": "Disabled",
            "integrationAccount": {
              "id": "[parameters('LogicAppIntegrationAccount')]"
            },
            "definition": {
               "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
               "actions": {
                  "Create_blob": {
                     "type": "ApiConnection",
                     "inputs": {
                        "host": {
                           "connection": {
                              "name": "@parameters('$connections')['azureblob']['connectionId']"
                           }
                        },
                     },
                     "method": "post",
                     "body": "@triggerBody()?['Body']",
                     "path": "/datasets/default/files",
                     "queries": {
                        "folderPath": "/emails",
                        "name": "@triggerBody()?['Subject']",
                        "queryParametersSingleEncoded": true
                     },
                     "runAfter": {},
                     "runtimeConfiguration": {
                        "contentTransfer": {
                           "transferMode": "Chunked"
                        }
                     }
                  }
               },
               "parameters": {
                  "$connections": {
                     "defaultValue": {},
                     "type": "Object"
                  }
               },
               "triggers": {
                  "When_a_new_email_arrives": {
                     "type": "ApiConnection",
                     "inputs": {
                        "host": {
                           "connection": {
                              "name": "@parameters('$connections')['office365']['connectionId']"
                           }
                        },
                        "method": "get",
                        "path": "/Mail/OnNewEmail",
                        "queries": {
                           "folderPath": "Inbox",
                           "importance": "Any",
                           "fetchOnlyWithAttachment": false,
                           "includeAttachments": false
                        }
                     },
                     "recurrence": {
                        "frequency": "Day",
                        "interval": 1
                     },
                     "splitOn": "@triggerBody()?['value']"
                  }
               },
               "contentVersion": "1.0.0.0",
               "outputs": {}
            },
            "parameters": {
               "$connections": {
                  "value": {
                     "azureblob": {
                        "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', parameters('LogicAppLocation'), '/managedApis/', 'azureblob')]",
                        "connectionId": "[resourceId('Microsoft.Web/connections', parameters('azureblob_1_Connection_Name'))]",
                        "connectionName": "[parameters('azureblob_1_Connection_Name')]"
                     },
                     "office365": {
                        "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', parameters('LogicAppLocation'), '/managedApis/', 'office365')]",
                        "connectionId": "[resourceId('Microsoft.Web/connections', parameters('office365_1_Connection_Name'))]",
                        "connectionName": "[parameters('office365_1_Connection_Name')]"
                     }
                  }
               }
            },
            "accessControl": {}
         },
         "name": "[parameters('LogicAppName')]",
         "type": "Microsoft.Logic/workflows",
         "location": "[parameters('LogicAppLocation')]",
         "tags": {
            "displayName": "LogicApp"
         },
         "apiVersion": "2016-06-01",
         "dependsOn": [
            "[resourceId('Microsoft.Web/connections', parameters('azureblob_1_Connection_Name'))]",
            "[resourceId('Microsoft.Web/connections', parameters('office365_1_Connection_Name'))]"
         ]
      },
      {
         "type": "MICROSOFT.WEB/CONNECTIONS",
         "apiVersion": "2016-06-01",
         "name": "[parameters('office365_1_Connection_Name')]",
         "location": "[parameters('LogicAppLocation')]",
         "properties": {
            "api": {
                "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', parameters('LogicAppLocation'), '/managedApis/', 'office365')]"
            },
            "displayName": "[parameters('office365_1_Connection_DisplayName')]"
         }
      },
      {
         "type": "MICROSOFT.WEB/CONNECTIONS",
         "apiVersion": "2016-06-01",
         "name": "[parameters('azureblob_1_Connection_Name')]",
         "location": "[parameters('LogicAppLocation')]",
         "properties": {
            "api": {
               "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', parameters('LogicAppLocation'), '/managedApis/', 'azureblob')]"
            },
            "displayName": "[parameters('azureblob_1_Connection_DisplayName')]",
            "parameterValues": {
               "accountName": "[parameters('azureblob_1_accountName')]",
               "accessKey": "[parameters('azureblob_1_accessKey')]"
            }
         }
      }
   ],
   "outputs": {}
}

后续步骤Next steps