首页 > 解决方案 > 如何在 ARM 模板中使用 o365 连接器部署逻辑应用程序

问题描述

我正在尝试使用逻辑应用程序和(未经身份验证的)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 连接已创建。在逻辑应用代码视图(左面板)中,逻辑应用和连接属性看起来不错: 在此处输入图像描述

但是,当我打开设计器时,使用连接的步骤会给我一个“找不到连接器”错误: 在此处输入图像描述

当我单击“查看代码”(在设计器视图中)时,参数部分如下所示:

    "parameters": {
        "$connections": {
            "value": {
                "DCA9B054-C46B-4419-B0E9-FC142A864810": {
                    "connectionId": "",
                    "connectionName": "",
                    "id": ""
                }
            }
        }
    }

我使用以下资源来构建 arm 模板:

解决方案

问题是逻辑应用程序中的语法错误。以下是一个可行的解决方案。我还删除了 o365 连接的 parameterValues 部分。通过这种方式,可以重复部署 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": {

  }
}

标签: azureazure-logic-appsarm-template

解决方案


inputs您的“Send_an_email_(V2)”操作中有一个额外的内容。

"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"
  }
}

部署后,我们可以得到预期的结果。 在此处输入图像描述


推荐阅读