如何在 ARM 模板中使用 o365 连接器部署逻辑应用程序
How to deploy Logic App with o365 Connector within ARM template
我正在尝试使用逻辑应用程序和(未经身份验证的)o365 连接部署 ARM 模板。这是我的模板:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for all resources."
}
}
},
"variables": {
"LogicAppName": "MyLogicApp"
},
"resources": [
{
"type": "Microsoft.Logic/workflows",
"apiVersion": "2017-07-01",
"name": "[variables('LogicAppName')]",
"location": "[parameters('location')]",
"identity": {
"type": "SystemAssigned"
},
"properties": {
"state": "Enabled",
"definition": {
"parameters": {
"$connections": {
"defaultValue": {
},
"type": "Object"
}
},
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"contentVersion": "1.0.0.0",
"triggers": {
"manual": {
"type": "Request",
"kind": "Http",
"inputs": {
"schema": {
"properties": {
},
"type": "object"
}
}
}
},
"actions": {
"Send_an_email_(V2)": {
"type": "ApiConnection",
"inputs": {
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['office365']['connectionId']"
}
},
"body": {
"Body": "<p>@{triggerBody()?['message']}</p>",
"Subject": "@triggerBody()?['subject']",
"To": "@triggerBody()?['to']"
},
"method": "post",
"path": "/v2/Mail"
}
}
}
},
"outputs": {
}
},
"parameters": {
"$connections": {
"value": {
"office365": {
"connectionId": "[resourceId('Microsoft.Web/connections', 'office365')]",
"connectionName": "office365",
"id": "[concat(subscription().id,'/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/office365')]"
}
}
}
}
},
"dependsOn": [
"[resourceId('Microsoft.Web/connections', 'office365')]"
]
},
{
"type": "Microsoft.Web/connections",
"apiVersion": "2016-06-01",
"location": "[resourceGroup().location]",
"name": "office365",
"properties": {
"api": {
"id": "[concat(subscription().id,'/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/office365')]"
},
"displayName": "office365",
"parameterValues": {
}
}
}
],
"outputs": {
}
}
执行时 运行 az deployment group create --resource-group my-rgroup --template-file .\arm-template.json
工作流和 api 连接已创建。在 逻辑应用程序代码视图 (左面板)中,逻辑应用程序和连接属性看起来不错:
然而,当我打开 designer 时,使用连接的步骤给我一个 "Connector not found" 错误:
当我单击 "view code"(在设计器视图中)时,参数部分如下所示:
"parameters": {
"$connections": {
"value": {
"DCA9B054-C46B-4419-B0E9-FC142A864810": {
"connectionId": "",
"connectionName": "",
"id": ""
}
}
}
}
我使用了以下资源来构建 arm 模板:
解决方案
问题是逻辑应用程序内部的语法错误。以下是一个可行的解决方案。我还删除了 o365 连接的参数值部分。这样arm模板就可以重复部署,用用户账号认证连接一次。
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for all resources."
}
}
},
"variables": {
"LogicAppName": "MyLogicApp"
},
"resources": [
{
"type": "Microsoft.Logic/workflows",
"apiVersion": "2017-07-01",
"name": "[variables('LogicAppName')]",
"location": "[parameters('location')]",
"identity": {
"type": "SystemAssigned"
},
"properties": {
"state": "Enabled",
"definition": {
"parameters": {
"$connections": {
"defaultValue": {
},
"type": "Object"
}
},
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"contentVersion": "1.1.0.0",
"triggers": {
"manual": {
"type": "Request",
"kind": "Http",
"inputs": {
"schema": {
"properties": {
},
"type": "object"
}
}
}
},
"actions": {
"Send_an_email_(V2)": {
"type": "ApiConnection",
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['office365']['connectionId']"
}
},
"body": {
"Body": "<p>hello world</p>",
"Subject": "test",
"To": "example@email.com"
},
"method": "post",
"path": "/v2/Mail"
}
}
},
"outputs": {
}
},
"parameters": {
"$connections": {
"value": {
"office365": {
"connectionId": "[resourceId('Microsoft.Web/connections', 'office365')]",
"connectionName": "office365",
"id": "[concat(subscription().id,'/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/office365')]"
}
}
}
}
},
"dependsOn": [
"[resourceId('Microsoft.Web/connections', 'office365')]"
]
},
{
"type": "Microsoft.Web/connections",
"apiVersion": "2016-06-01",
"location": "[resourceGroup().location]",
"name": "office365",
"properties": {
"api": {
"id": "[concat(subscription().id,'/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/office365')]"
},
"displayName": "office365"
}
}
],
"outputs": {
}
}
您的 "Send_an_email_(V2)" 操作中有一个额外的 inputs
。
"Send_an_email_(V2)": {
"type": "ApiConnection",
"inputs": {
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['office365']['connectionId']"
}
},
"body": {
"Body": "<p>@{triggerBody()?['message']}</p>",
"Subject": "@triggerBody()?['subject']",
"To": "@triggerBody()?['to']"
},
"method": "post",
"path": "/v2/Mail"
}
}
}
您需要从上面的代码中删除一个 inputs
。
"Send_an_email_(V2)": {
"type": "ApiConnection",
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['office365']['connectionId']"
}
},
"body": {
"Body": "<p>@{triggerBody()?['message']}</p>",
"Subject": "@triggerBody()?['subject']",
"To": "@triggerBody()?['to']"
},
"method": "post",
"path": "/v2/Mail"
}
}
部署后,我们可以得到预期的结果。
我正在尝试使用逻辑应用程序和(未经身份验证的)o365 连接部署 ARM 模板。这是我的模板:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for all resources."
}
}
},
"variables": {
"LogicAppName": "MyLogicApp"
},
"resources": [
{
"type": "Microsoft.Logic/workflows",
"apiVersion": "2017-07-01",
"name": "[variables('LogicAppName')]",
"location": "[parameters('location')]",
"identity": {
"type": "SystemAssigned"
},
"properties": {
"state": "Enabled",
"definition": {
"parameters": {
"$connections": {
"defaultValue": {
},
"type": "Object"
}
},
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"contentVersion": "1.0.0.0",
"triggers": {
"manual": {
"type": "Request",
"kind": "Http",
"inputs": {
"schema": {
"properties": {
},
"type": "object"
}
}
}
},
"actions": {
"Send_an_email_(V2)": {
"type": "ApiConnection",
"inputs": {
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['office365']['connectionId']"
}
},
"body": {
"Body": "<p>@{triggerBody()?['message']}</p>",
"Subject": "@triggerBody()?['subject']",
"To": "@triggerBody()?['to']"
},
"method": "post",
"path": "/v2/Mail"
}
}
}
},
"outputs": {
}
},
"parameters": {
"$connections": {
"value": {
"office365": {
"connectionId": "[resourceId('Microsoft.Web/connections', 'office365')]",
"connectionName": "office365",
"id": "[concat(subscription().id,'/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/office365')]"
}
}
}
}
},
"dependsOn": [
"[resourceId('Microsoft.Web/connections', 'office365')]"
]
},
{
"type": "Microsoft.Web/connections",
"apiVersion": "2016-06-01",
"location": "[resourceGroup().location]",
"name": "office365",
"properties": {
"api": {
"id": "[concat(subscription().id,'/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/office365')]"
},
"displayName": "office365",
"parameterValues": {
}
}
}
],
"outputs": {
}
}
执行时 运行 az deployment group create --resource-group my-rgroup --template-file .\arm-template.json
工作流和 api 连接已创建。在 逻辑应用程序代码视图 (左面板)中,逻辑应用程序和连接属性看起来不错:
然而,当我打开 designer 时,使用连接的步骤给我一个 "Connector not found" 错误:
当我单击 "view code"(在设计器视图中)时,参数部分如下所示:
"parameters": {
"$connections": {
"value": {
"DCA9B054-C46B-4419-B0E9-FC142A864810": {
"connectionId": "",
"connectionName": "",
"id": ""
}
}
}
}
我使用了以下资源来构建 arm 模板:
解决方案
问题是逻辑应用程序内部的语法错误。以下是一个可行的解决方案。我还删除了 o365 连接的参数值部分。这样arm模板就可以重复部署,用用户账号认证连接一次。
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for all resources."
}
}
},
"variables": {
"LogicAppName": "MyLogicApp"
},
"resources": [
{
"type": "Microsoft.Logic/workflows",
"apiVersion": "2017-07-01",
"name": "[variables('LogicAppName')]",
"location": "[parameters('location')]",
"identity": {
"type": "SystemAssigned"
},
"properties": {
"state": "Enabled",
"definition": {
"parameters": {
"$connections": {
"defaultValue": {
},
"type": "Object"
}
},
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"contentVersion": "1.1.0.0",
"triggers": {
"manual": {
"type": "Request",
"kind": "Http",
"inputs": {
"schema": {
"properties": {
},
"type": "object"
}
}
}
},
"actions": {
"Send_an_email_(V2)": {
"type": "ApiConnection",
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['office365']['connectionId']"
}
},
"body": {
"Body": "<p>hello world</p>",
"Subject": "test",
"To": "example@email.com"
},
"method": "post",
"path": "/v2/Mail"
}
}
},
"outputs": {
}
},
"parameters": {
"$connections": {
"value": {
"office365": {
"connectionId": "[resourceId('Microsoft.Web/connections', 'office365')]",
"connectionName": "office365",
"id": "[concat(subscription().id,'/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/office365')]"
}
}
}
}
},
"dependsOn": [
"[resourceId('Microsoft.Web/connections', 'office365')]"
]
},
{
"type": "Microsoft.Web/connections",
"apiVersion": "2016-06-01",
"location": "[resourceGroup().location]",
"name": "office365",
"properties": {
"api": {
"id": "[concat(subscription().id,'/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/office365')]"
},
"displayName": "office365"
}
}
],
"outputs": {
}
}
您的 "Send_an_email_(V2)" 操作中有一个额外的 inputs
。
"Send_an_email_(V2)": {
"type": "ApiConnection",
"inputs": {
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['office365']['connectionId']"
}
},
"body": {
"Body": "<p>@{triggerBody()?['message']}</p>",
"Subject": "@triggerBody()?['subject']",
"To": "@triggerBody()?['to']"
},
"method": "post",
"path": "/v2/Mail"
}
}
}
您需要从上面的代码中删除一个 inputs
。
"Send_an_email_(V2)": {
"type": "ApiConnection",
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['office365']['connectionId']"
}
},
"body": {
"Body": "<p>@{triggerBody()?['message']}</p>",
"Subject": "@triggerBody()?['subject']",
"To": "@triggerBody()?['to']"
},
"method": "post",
"path": "/v2/Mail"
}
}
部署后,我们可以得到预期的结果。