How to deploy Logic App with o365 Connector within ARM template

落爺英雄遲暮 提交于 2021-02-20 18:50:19

问题


Im trying to deploy an ARM template with a logic app and an (unauthenticated) o365 connection. This is my template:

{
  "$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": {

  }
}

When executing i.e. running az deployment group create --resource-group my-rgroup --template-file .\arm-template.json

The workflow and api connection are created. In the Logic app code view (left panel) the logic app and connection properties look fine:

However when I open the designer the step using the connection gives me an "Connector not found" error:

And when I click "view code" (in the designer view) the parameters section looks like this:

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

I used following resources to build the arm template:

  • https://social.msdn.microsoft.com/Forums/vstudio/en-US/6a17c729-ea15-4309-bd34-aa07d0a818bc/arm-template-for-0365-connector-with-username-and-password?forum=azurelogicapps

  • https://social.msdn.microsoft.com/Forums/vstudio/en-US/6a17c729-ea15-4309-bd34-aa07d0a818bc/arm-template-for-0365-connector-with-username-and-password?forum=azurelogicapps

Solution

The problem was a wrong syntax inside the logic app. Following is a working solution. I also removed the parameterValues section of the o365 connection. In this way the arm template can be deployed repeatedly and authenticate the connection once with a user account.

{
  "$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": {

  }
}

回答1:


There is an extra inputs in your "Send_an_email_(V2)" action.

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

You need to remove one inputs from the code above.

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

After deploy it, we can get the result which expected.



来源:https://stackoverflow.com/questions/60703570/how-to-deploy-logic-app-with-o365-connector-within-arm-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!