How to create ARM template for logic App with API connection to Gmail? - azure

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"logicAppName": {
"type": "string",
"defaultValue": "la-send-mail",
"metadata": {
"description": "Name of the Logic App."
}
},
"logicAppLocation": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location of the Logic App."
}
},
"gmail_name": {
"type": "string",
"defaultValue": "gmail"
},
"gmail_displayName": {
"type": "string",
"defaultValue": "roman.dovhanyk#gmail.com"
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.Logic/workflows",
"apiVersion": "2016-06-01",
"name": "[parameters('logicAppName')]",
"location": "[parameters('logicAppLocation')]",
"dependsOn": [
"[resourceId('Microsoft.Web/connections', parameters('gmail_name'))]"
],
"properties": {
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"manual": {
"type": "Request",
"kind": "Http",
"inputs": {
"schema": {
"properties": {
"body": {
"type": "string"
},
"bodyHTML": {
"type": "string"
},
"ccAddress": {
"type": "string"
},
"color": {
"type": "string"
},
"datafactoryName": {
"type": "string"
},
"pipelineName": {
"type": "string"
},
"pipelineRunId": {
"type": "string"
},
"time": {
"type": "string"
},
"title": {
"type": "string"
},
"toAddress": {
"type": "string"
}
},
"type": "object"
}
}
}
},
"actions": {
"Initialize_variable": {
"runAfter": {},
"type": "InitializeVariable",
"inputs": {
"variables": [
{
"name": "HTMLBody",
"type": "string",
"value": "<div>\n<h1 style=\"Color:#{triggerBody()?['color']};\"> Executed successfully </h1>\n<hr/>\nData Factory Name: <b>#{triggerBody()?['datafactoryName']}</b><br/>\nPipeline Name: <b>#{triggerBody()?['pipelineName']}</b><br/>\nPipeline Run Id<b>#{triggerBody()?['pipelineRunId']}</b><br/>\nTime: <b>#{triggerBody()?['time']}</b><br/>\n<hr/>\n<p>#{triggerBody()?['body']}</p>\n<div>#{triggerBody()?['bodyHTML']}</div>\n</div>"
}
]
}
},
"Send_email_(V2)": {
"runAfter": {
"Initialize_variable": [
"Succeeded"
]
},
"type": "ApiConnection",
"inputs": {
"body": {
"Body": "<p>#{variables('HTMLBody')}</p>",
"Cc": "#triggerBody()?['ccAddress']",
"Subject": "#triggerBody()?['title']",
"To": "#triggerBody()?['toAddress']"
},
"host": {
"connection": {
"name": "#parameters('$connections')['gmail']['connectionId']"
}
},
"method": "post",
"path": "/v2/Mail"
}
}
},
"outputs": {}
},
"parameters": {
"$connections": {
"value": {
"gmail": {
"id": "[concat('/subscriptions/',subscription().subscriptionId,'/providers/Microsoft.Web/locations/',parameters('logicAppLocation'),'/managedApis/gmail')]",
"connectionId": "[resourceId('Microsoft.Web/connections', parameters('gmail_name'))]",
"connectionName": "[parameters('gmail_name')]"
}
}
}
}
}
},
{
"type": "Microsoft.Web/connections",
"apiVersion": "2016-06-01",
"location": "[parameters('logicAppLocation')]",
"name": "[parameters('gmail_name')]",
"properties": {
"api": {
"id": "[concat('/subscriptions/',subscription().subscriptionId,'/providers/Microsoft.Web/locations/',parameters('logicAppLocation'),'/managedApis/gmail')]"
},
"displayName": "[parameters('gmail_displayName')]"
}
}
],
"outputs": {}
}
This is the template I use, it always gives the
"The deployment 'la-send-mail-1_2' failed with error(s). Showing 1 out of 1 error(s). Status Message: The operation on workflow 'la-send-mail' cannot be completed because it contains connections to 'gmail' connector which are not valid. Please re-authorize the connections and try again. (Code:GmailConnectorPolicyViolation)" error
I am run deployment from simple PowerShell script.
Could someone help me to fix this issue

Thank you Thomas. Posting your suggestions as an answer to help other community members.
The Authorize document will help you in authorizing the OAuth connections.
Manually authorize OAuth connections by opening your logic app in Logic App Designer, either in the Azure portal or in Visual Studio. When you authorize your connection, a confirmation page might appear for you to allow access.
For Oauth connection to ARM template you need to script it. But the easiest way is to create manually these connection then deploy ARM.
Refer Logic App Connection Auth Document for further information.
This script will retrieve a consent link for a connection (and can also create the connection at the same time) for an OAuth Logic Apps connector. It will then open the consent link and complete authorization to enable a connection. This can be used after deployment of connections to make sure a Logic App is working end-to-end.

Related

Send Azure created workflow trigger URL after deployment to my application

I have an Azure deploy button for a logic app with this template:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"logic_app_name": {
"defaultValue": "logic_app_name",
"type": "String"
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.Logic/workflows",
"apiVersion": "2017-07-01",
"name": "[parameters('logic_app_name')]",
"location": "[resourceGroup().location]",
"properties": {
"state": "Enabled",
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"manual": {
"type": "Request",
"kind": "Http",
"inputs": {
"schema": {
"properties": {
"data": {
"type": "string"
}
},
"type": "object"
}
}
}
},
"actions": {
"Initialize_variables": {
"inputs": {
"variables": [
{
"name": "var-1",
"type": "object",
"value": {
"alert_id": "#{triggerOutputs()['headers']['var-1']}"
}
}
]
},
"runAfter": {},
"type": "InitializeVariable"
}
},
"outputs": {}
}
}
}
]
}
After deployment, access Logic app/ Logic app designer in the UI, I can get the trigger Http request URL which will use for sending data to that webhook.
My question is how can I make a callback request to my application (let say I have /azurecallback route) with created trigger URL as parameter after deployment so I can set it automatically?

Logic app tracked properties are not getting logged in log analytic workspace

Tracked properties are not getting logged in log analytic workspace. I have configured the required settings in diagnostic settings section of logic app.
**Below is logic app code-**
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Initialize_variable": {
"inputs": {
"variables": [
{
"name": "test",
"type": "string",
"value": "#triggerBody()?['uid']"
}
]
},
"runAfter": {},
"type": "InitializeVariable"
},
"Response": {
"inputs": {
"body": "#variables('test')",
"statusCode": 200
},
"kind": "Http",
"runAfter": {
"Initialize_variable": [
"Succeeded"
]
},
"trackedProperties": {
"OutputBlobName": "#triggerBody()?['uid']"
},
"type": "Response"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"manual": {
"inputs": {
"schema": {
"properties": {
"uid": {
"type": "string"
}
},
"type": "object"
}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {}
}
Is there any configuration at workspace level that I ma missing.
I believe you need to modify your code a bit. I am sharing an example which might help:
Image 1:
changing this ( Image 1) to the this (Image 2) did the trick :
Image 2:
Reference : https://www.connected-pawns.com/2018/06/19/cant-see-tracked-properties-logic-app/
Also you can check : https://peterrombouts.nl/2019/04/01/logicapps-monitoring-with-log-analytics/
Late to the party here, but since you've already got the property you want to track stored in a variable, you can attach tracked properties to that action:
"Initialize_variable": {
"inputs": {
"variables": [
{"name": "test",
"type": "string",
"value": "#triggerBody()?['uid']" }
] },
"runAfter": {},
"type": "InitializeVariable",
"trackedProperties": {
"OutputBlobName": "#action().inputs.variables[0].value"
}
}

InvalidResourceNamespace error when attempting to deploy Event Grid Subscription for Azure Function

I have an existing Event Grid Topic and want to add an Event Subscription to it, with an existing Azure Function endpoint.
To achieve this I am using Linked Templates. ARM Template validation passes, but deployment fails, with quite a peculiar error:
"InvalidResourceNamespace: "The resource namespace 'subscriptions' is invalid. (Code: InvalidResourceNamespace)"
Here's the raw error:
{
"code": "DeploymentFailed",
"message": "At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.",
"details": [
{
"code": "InvalidContentLink",
"message": "Unable to download deployment content from 'https://storagearmtpl.blob.core.windows.net/arm-tpl-service-cd-11111-artifacts/nestedtemplates/eventGridSubscriptionTemplate.json?sv=sasartifactsstring'. The tracking Id is '11111111'. Please see https://aka.ms/arm-deploy for usage details."
},
{
"code": "InvalidResourceNamespace",
"message": "The resource namespace 'subscriptions' is invalid."
}
]
}
Where sasartifactsstring is a valid artifacts locations sas token. (I'm assuming, it looks correct)
I understand that this error stems from the "type" of the resource in the template being invalid, but as you can see below, it's simply Microsoft.EventGrid/topics/providers/eventSubscriptions.
/nestedtemplates/eventGridSubscriptionTemplate.json
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"subscriptionName": {
"type": "string",
"metadata": {
"description": "Name of the event grid subscription"
}
},
"topicName": {
"type": "string",
"metadata": {
"description": "Event grid Topic Name to Subscribe."
}
},
"functionResourceGroupName": {
"type": "string",
"metadata": {
"description": "Resource group name for functionapp"
}
},
"functionAppName": {
"type": "string",
"metadata": {
"description": "function app name"
}
},
"subscriptionId": {
"type": "string",
"metadata": {
"description": "The id string of the Azure subscription"
}
},
"topicResourceGroupName": {
"type": "string",
"metadata": {
"description": "The name of the topic resource group"
}
}
},
"variables": {},
"resources": [
{
"name": "[concat(parameters('topicName'), '/Microsoft.EventGrid/', parameters('subscriptionName'))]",
"type": "Microsoft.EventGrid/topics/providers/eventSubscriptions",
"location": "[resourceGroup().location]",
"apiVersion": "2020-06-01",
"properties": {
"topic": "[concat('/subscriptions/', parameters('subscriptionId'), '/resourceGroups/', parameters('topicResourceGroupName'), 'providers/Microsoft.EventGrid/topics/', parameters('topicName'))]",
"destination": {
"endpointType": "AzureFunction",
"properties": {
"resourceId": "[concat('/subscriptions/', parameters('subscriptionId'), '/resourceGroups/', parameters('functionResourceGroupName'), '/providers/Microsoft.Web/sites/', parameters('functionAppName'), '/functions/HelloWorld')]",
"maxEventsPerBatch": 1,
"preferredBatchSizeInKilobytes": 64
}
},
}
},
"dependsOn": [
]
}
],
"outputs": {}
}
/azuredeploy.json
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"_artifactsLocation": {
"type": "string"
},
"_artifactsLocationSasToken": {
"type": "securestring"
},
"functionResourceGroupName": {
"type": "string"
},
"functionAppName": {
"type": "string"
},
"topicName": {
"type": "string"
},
"topicResourceGroupName": {
"type": "string"
},
"subscriptionId": {
"type": "string"
}
},
"variables": {
"templateFolder": "nestedtemplates",
"subscriptionTemplateFileName": "eventGridSubscriptionTemplate.json"
},
"resources": [
{
"name": "functionsubscription"
"type": "Microsoft.Resources/deployments",
"apiVersion": "2017-05-10"
"resourceGroup": "[parameters('topicResourceGroupName')]",
"dependsOn": [ ],
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[concat(parameters('_artifactsLocation'), '/', variables('templateFolder'), '/', variables('subscriptionTemplateFileName'), parameters('_artifactsLocationSasToken'))]",
"contentVersion": "1.0.0.0"
},
"parameters": {
"subscriptionName": {
"value": "FunctionSubscription"
},
"topicName": {
"value": "[parameters('topicName')]"
},
"functionResourceGroupName": {
"value": "[parameters('functionResourceGroupName')]"
},
"functionAppName": {
"value": "[parameters('functionAppName')]"
},
"topicResourceGroupName": {
"value": "[parameters('topicResourceGroupName')]"
},
"subscriptionId": {
"value": "[parameters('subscriptionId')]"
}
}
}
}
]
}
azure deploy parameters file
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
,
"functionResourceGroupName": {
"value": "functionResourceGroup"
},
"functionAppName": {
"value": "functionAppName"
},
"subscriptionId": {
"value": "1111111111"
},
"topicName": {
"value": "topicName"
},
"topicResourceGroupName": {
"value": "topicResourceGroup"
}
}
Really not sure what I'm doing wrong here. Worth noting that the first error is annoying as well and I'm not sure why it can't download the deployment content...
update/edit:
It's worth noting that the release is using Classic Azure Release Pipelines. And the error comes up during the release.
Looking into the deployment logs for the resource group, I was able to see that the deployment was trying to deploy an invalid resource, with the type starting "subscriptions/.....", so at least I know where the error is coming from. Still investigating what is causing this misread...
The cause of the odd 'subscriptions' error was due to the fact that I inserted a new resource into my resources list in my deployment (parent) ARM template, but not at the end of the list.
Once I put the deployment resource that references the new event grid subscription at the end of the resources list, the error did not show up.
azuredeploy.json
resources: [
{all other existing deployment resources ....},
{
"name": "functionsubscription"
"type": "Microsoft.Resources/deployments",
"apiVersion": "2017-05-10"
"resourceGroup": "[parameters('topicResourceGroupName')]",
"dependsOn": [ ],
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[concat(parameters('_artifactsLocation'), '/', variables('templateFolder'), '/', variables('subscriptionTemplateFileName'), parameters('_artifactsLocationSasToken'))]",
"contentVersion": "1.0.0.0"
},
"parameters": {
"subscriptionName": {
"value": "FunctionSubscription"
},
"topicName": {
"value": "[parameters('topicName')]"
},
"functionResourceGroupName": {
"value": "[parameters('functionResourceGroupName')]"
},
"functionAppName": {
"value": "[parameters('functionAppName')]"
},
"topicResourceGroupName": {
"value": "[parameters('topicResourceGroupName')]"
},
"subscriptionId": {
"value": "[parameters('subscriptionId')]"
}
}
}
}
]
However, I am still dealing with the InvalidContentLink error, the main problem of the question has been resolved.

How do you configure Logic Apps to log to Log Analytics in an ARM template?

I am trying to deploy a solution with Logic Apps whose log data I would like to go to a Log Analytics workspace. This is easy to configure in the portal via Diagnostic Settings > Add Diagnostic Setting > check 'Send to Log Analytics' and select a pre-existing workspace.
However I can't see from looking at the exported templates for the Logic App, for the workspace, or for the whole resource group, how you configure this link in an ARM template. The documentation doesn't seem to mention this setting at all either.
here's an example to stream to event hub\storage account\log analytics:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"logicAppName": {
"type": "string",
"metadata": {
"description": "Name of the Logic App that will be created."
}
},
"testUri": {
"type": "string",
"defaultValue": "https://azure.microsoft.com/status/feed/"
},
"settingName": {
"type": "string",
"metadata": {
"description": "Name of the setting. Name for the diagnostic setting resource. Eg. 'archiveToStorage' or 'forSecurityTeam'."
}
},
"storageAccountName": {
"type": "string",
"metadata": {
"description": "Name of the Storage Account in which Diagnostic Logs should be saved."
}
},
"eventHubAuthorizationRuleId": {
"type": "string",
"metadata": {
"description": "Resource ID of the event hub authorization rule for the Event Hubs namespace in which the event hub should be created or streamed to."
}
},
"eventHubName": {
"type": "string",
"metadata": {
"description": "Optional. Name of the event hub within the namespace to which logs are streamed. Without this, an event hub is created for each log category."
}
},
"workspaceId": {
"type": "string",
"metadata": {
"description": "Log Analytics workspace ID for the Log Analytics workspace to which logs will be sent."
}
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.Logic/workflows",
"name": "[parameters('logicAppName')]",
"apiVersion": "2016-06-01",
"location": "[resourceGroup().location]",
"properties": {
"definition": {
"$schema": "https://schema.management.azure.com/schemas/2016-06-01/Microsoft.Logic.json",
"contentVersion": "1.0.0.0",
"parameters": {
"testURI": {
"type": "string",
"defaultValue": "[parameters('testUri')]"
}
},
"triggers": {
"recurrence": {
"type": "recurrence",
"recurrence": {
"frequency": "Hour",
"interval": 1
}
}
},
"actions": {
"http": {
"type": "Http",
"inputs": {
"method": "GET",
"uri": "#parameters('testUri')"
},
"runAfter": {}
}
},
"outputs": {}
},
"parameters": {}
},
"resources": [
{
"type": "providers/diagnosticSettings",
"name": "[concat('Microsoft.Insights/', parameters('settingName'))]",
"dependsOn": [
"[resourceId('Microsoft.Logic/workflows', parameters('logicAppName'))]"
],
"apiVersion": "2017-05-01-preview",
"properties": {
"name": "[parameters('settingName')]",
"storageAccountId": "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]",
"eventHubAuthorizationRuleId": "[parameters('eventHubAuthorizationRuleId')]",
"eventHubName": "[parameters('eventHubName')]",
"workspaceId": "[parameters('workspaceId')]",
"logs": [
{
"category": "WorkflowRuntime",
"enabled": true,
"retentionPolicy": {
"days": 0,
"enabled": false
}
}
],
"metrics": [
{
"timeGrain": "PT1M",
"enabled": true,
"retentionPolicy": {
"enabled": false,
"days": 0
}
}
]
}
}
]
}
]
}
https://learn.microsoft.com/en-us/azure/azure-monitor/platform/diagnostic-logs-stream-template

Azure Template validation failure , expression is not valid

I've exported a resource group that contains some Logic apps that I want to use in Visual Studio but one Logic App is unable to be opened using the designer-view in VS.
I get this error even thou I haven’t modified the code in any way:
The template validation failed: 'The property 'expression' '[concat('#equals(toLower(triggerBody()?['', parameters('workflows_Booking_name'),'s']?['Event']), 'create')')]'
of template action 'Condition_-_Create_or_UpdateBookings' at line '1' and column '1827' is not a valid template language expression.'.
This is what the Logic App looks like in the portal for better understanding.
As Szymon Wylezol mentioned that it seems that it is wrong with the template itself. From the error message we know that expression [concat('#equals(toLower(triggerBody()?['', parameters('workflows_Booking_name'),'s']?['Event']), 'create')')] is incorrect. More detail about expressions please refer to document.
According to your supplied screenshot that we can get the expression as following in the code view:
"actions": {
"Condition_-_Create_or_UpdateBookings": {
"type": "If",
"expression": "#equals(toLower(triggerBody()?['Bookings']?['Event']), 'create')",
"actions": {},
"runAfter": {}
}
}
Please compare the code view in the VS with code view in the Azure portal.
Then it should be ready for view in the Visual Studio. More details about Design, build, and deploy Azure Logic Apps in Visual Studio please refer to the document
Demo code.
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"workflows_testlogic_name": {
"defaultValue": "testlogic",
"type": "string"
},
"workflows_tomtestLogicApp_name": {
"defaultValue": "tomtestLogicApp",
"type": "string"
}
},
"variables": {},
"resources": [
{
"comments": "Generalized from resource: '/subscriptions/ed0caab7-c6d4-45e9-9289-c7e5997c9241/resourceGroups/tomtestlogicApp/providers/Microsoft.Logic/workflows/testlogic'.",
"type": "Microsoft.Logic/workflows",
"name": "[parameters('workflows_testlogic_name')]",
"apiVersion": "2016-06-01",
"location": "eastasia",
"properties": {
"state": "Enabled",
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"triggers": {
"manual": {
"type": "Request",
"kind": "Http",
"inputs": {
"schema": {
"properties": {
"event": {
"type": "string",
"value": ""
},
"name": {
"type": "string",
"value": ""
},
"participants": {
"type": "integer",
"value": ""
}
},
"type": "object"
}
}
}
},
"actions": {
"Condition": {
"actions": {},
"runAfter": {},
"expression": "#equals(toLower(triggerBody()?['name']), 'test')",
"type": "If"
}
},
"outputs": {}
},
"parameters": {}
},
"dependsOn": []
},
{
"comments": "Generalized from resource: '/subscriptions/ed0caab7-c6d4-45e9-9289-c7e5997c9241/resourceGroups/tomtestlogicApp/providers/Microsoft.Logic/workflows/tomtestLogicApp'.",
"type": "Microsoft.Logic/workflows",
"name": "[parameters('workflows_tomtestLogicApp_name')]",
"apiVersion": "2016-06-01",
"location": "eastasia",
"tags": {
"displayName": "LogicApp"
},
"properties": {
"state": "Enabled",
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"triggers": {
"manual": {
"type": "Request",
"kind": "Http",
"inputs": {
"schema": {
"properties": {
"Bookings": {
"properties": {
"BookedByEmail": {
"type": "string"
},
"Event": {
"type": "string"
}
}
}
}
}
}
}
},
"actions": {
"Condition_-_Create_or_UpdateBookings": {
"actions": {},
"runAfter": {},
"expression": "#equals(toLower(triggerBody()?['Bookings']?['Event']), 'create')",
"type": "If"
}
},
"outputs": {}
},
"parameters": {}
},
"dependsOn": []
}
]
}

Resources