0
votes

I'm trying to deploy a logic app which includes an office 365 connector and a storage account. Is it better to include the storage account and office365 connector in the ARM template or create the connectors in the resource group before deployment? In this case, I'm finding that the blob actions are saying they can't find the account. If I deploy everything together, I need to manually go through all the actions and reset the connector when I deploy to a new resource group. I can't expect an operations team to do this. What's the best practice?

1

1 Answers

0
votes

For this problem, we can solve the issue of blob by modify our arm template but we can't solve the issue of o365 in arm template.

To connect to your blob storage after deploy the arm template, you can refer to my logic and arm template and edit your arm template. My logic app shown as below: enter image description here

And my arm template show as below:

{
  "$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,
      "metadata": {
        "description": "Name of the Logic App."
      }
    },
    "logicAppLocation": {
      "type": "string",
      "defaultValue": "eastasia",
      "allowedValues": [
        "[resourceGroup().location]",
        "eastasia",
        "southeastasia",
        "centralus",
        "eastus",
        "eastus2",
        "westus",
        "northcentralus",
        "southcentralus",
        "northeurope",
        "westeurope",
        "japanwest",
        "japaneast",
        "brazilsouth",
        "australiaeast",
        "australiasoutheast",
        "southindia",
        "centralindia",
        "westindia",
        "canadacentral",
        "canadaeast",
        "uksouth",
        "ukwest",
        "westcentralus",
        "westus2",
        "koreacentral",
        "koreasouth",
        "francecentral",
        "francesouth",
        "uaecentral",
        "southafricanorth",
        "southafricawest"
      ],
      "metadata": {
        "description": "Location of the Logic App."
      }
    },
    "azureblob_1_Connection_Name": {
      "type": "string",
      "defaultValue": "azureblob"
    },
    "azureblob_1_Connection_DisplayName": {
      "type": "string",
      "defaultValue": "blobConnection"
    },
    "azureblob_1_accountName": {
      "type": "string",
      "metadata": {
        "description": "Name of the storage account the connector should use."
      },
      "defaultValue": "hurystorage"
    },
    "azureblob_1_accessKey": {
      "type": "securestring",
      "metadata": {
        "description": "Specify a valid primary/secondary storage account access key."
      }
    },
    "office365_1_Connection_Name": {
      "type": "string",
      "defaultValue": "office365"
    },
    "office365_1_Connection_DisplayName": {
      "type": "string",
      "defaultValue": "[email protected]"
    }
  },
  "variables": {},
  "resources": [
    {
      "name": "[parameters('logicAppName')]",
      "type": "Microsoft.Logic/workflows",
      "location": "[parameters('logicAppLocation')]",
      "tags": {
        "displayName": "LogicApp"
      },
      "apiVersion": "2016-06-01",
      "properties": {
        "definition": {
          "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
          "actions": {
            "Get_blob_content": {
              "type": "ApiConnection",
              "inputs": {
                "host": {
                  "connection": {
                    "name": "@parameters('$connections')['azureblob']['connectionId']"
                  }
                },
                "method": "get",
                "path": "/datasets/default/files/@{encodeURIComponent(encodeURIComponent('JTJmdGVzdGNvbnRhaW5lciUyZmZpbGUxLmNzdg=='))}/content",
                "queries": {
                  "inferContentType": true
                }
              },
              "runAfter": {},
              "metadata": {
                "JTJmdGVzdGNvbnRhaW5lciUyZmZpbGUxLmNzdg==": "/testcontainer/file1.csv"
              }
            },
            "Send_an_email_(V2)": {
              "type": "ApiConnection",
              "inputs": {
                "host": {
                  "connection": {
                    "name": "@parameters('$connections')['office365']['connectionId']"
                  }
                },
                "method": "post",
                "body": {
                  "To": "[email protected]",
                  "Subject": "test",
                  "Body": "<p>test</p>"
                },
                "path": "/v2/Mail"
              },
              "runAfter": {
                "Get_blob_content": [
                  "Succeeded"
                ]
              }
            }
          },
          "parameters": {
            "$connections": {
              "defaultValue": {},
              "type": "Object"
            }
          },
          "triggers": {
            "Recurrence": {
              "type": "recurrence",
              "recurrence": {
                "frequency": "Month",
                "interval": 1
              }
            }
          },
          "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')]"
              }
            }
          }
        }
      },
      "dependsOn": [
        "[resourceId('Microsoft.Web/connections', parameters('azureblob_1_Connection_Name'))]",
        "[resourceId('Microsoft.Web/connections', parameters('office365_1_Connection_Name'))]"
      ]
    },
    {
      "type": "MICROSOFT.WEB/CONNECTIONS",
      "apiVersion": "2018-07-01-preview",
      "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')]"
        }
      }
    },
    {
      "type": "MICROSOFT.WEB/CONNECTIONS",
      "apiVersion": "2018-07-01-preview",
      "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')]"
      }
    }
  ],
  "outputs": {}
}

Please pay attention to this part in screenshot in my template.

enter image description here

In my arm template, I just change the code from the screenshot above to:

"azureblob_1_accessKey": {
  "type": "securestring",
  "metadata": {
    "description": "Specify a valid primary/secondary storage account access key."
  },
  "defaultValue": "<your storage access key>"
},

Then deploy the arm template, it will connect to your blob storage.

For the problem of o365 connector deployment by arm template, there isn't a good solution to implement it. But you can refer to this post, it provides a solution of powershell to do the authencation for the o365 connector.