Azure Template validation failure , expression is not valid - azure

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": []
}
]
}

Related

Default Values in ARM templates when using Template Specs

We have implemented Template Specs for our ARM deployments to Azure a while ago and we drastically decreased the amount of work by doing that. The next thing we're trying to achieve is to start implementing Default Values in template specs, so we do not have to specify all parameters that are the same in all our projects in the parameter files. In case we do want to override the default, we can of course specify the parameter in the parameter file.
We worked with this already in the past with templates and parameter files, but I can't get this to work with Template Specs.
As an example, I'm trying to deploy an App Service Plan like this:
Template Spec:
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"appServicePlanSettings": {
"type": "object",
"defaultValue": {
"isHypervContainerPlan": false
}
},
"resourceNameAndTagSettings": {
"type": "object"
}
},
"variables": {
"appServicePlanName": "[concat('o', parameters('appServicePlanSettings').nameAbbr, parameters('resourceNameAndTagSettings').environmentType, parameters('resourceNameAndTagSettings').resourceGroupNumber, parameters('resourceNameAndTagSettings').solutionNameAbbr, parameters('resourceNameAndTagSettings').locationAbbr)]"
},
"resources": [
{
"comments": "App Service Plans",
"condition": "[parameters('appServicePlanSettings').deploy]",
"apiVersion": "2020-09-01",
"type": "Microsoft.Web/serverfarms",
"name": "[variables('appServicePlanName')]",
"location": "[resourceGroup().location]",
"tags": {
"_Purpose": "[parameters('appServicePlanSettings').tagValuePurpose]",
"CostCenter": "[parameters('resourceNameAndTagSettings').tagValueCostCenter]",
"EnvironmentType": "[parameters('resourceNameAndTagSettings').tagValueEnvironmentType]",
"Owner": "[parameters('resourceNameAndTagSettings').tagValueOwner]"
},
"kind": "[parameters('appServicePlanSettings').kind]",
"sku": {
"name": "[parameters('appServicePlanSettings').sku]",
"size": "[parameters('appServicePlanSettings').sku]",
"tier": "[parameters('appServicePlanSettings').skuTier]"
},
"properties": {
"hyperV": "[parameters('appServicePlanSettings').isHypervContainerPlan]",
"perSiteScaling": "[parameters('appServicePlanSettings').perSiteScaling]",
"reserved": "[parameters('appServicePlanSettings').isLinuxOS]"
},
"dependsOn": []
}
],
"outputs": {}
}
Main Template:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"appServicePlanSettings": {
"type": "array"
},
"dateTime": {
"type": "string",
"defaultValue": "[utcNow()]"
},
"resourceNameAndTagSettings": {
"type": "object"
},
"templateSpecSettings": {
"type": "object"
}
},
"resources": [
{
"comments": "Apps - App Service Plans",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2020-06-01",
"name": "[concat('Deploy-', parameters('appServicePlanSettings')[copyIndex()].nameAbbr, parameters('resourceNameAndTagSettings').environmentType, parameters('resourceNameAndTagSettings').resourceGroupNumber, parameters('resourceNameAndTagSettings').solutionNameAbbr, parameters('resourceNameAndTagSettings').locationAbbr, '-', parameters('dateTime'))]",
"copy": {
"name": "appServicePlanCopy",
"count": "[length(parameters('appServicePlanSettings'))]"
},
"properties": {
"mode": "Incremental",
"templateLink": {
"id": "[concat('/subscriptions/', parameters('templateSpecSettings').templateSpecSubscriptionId, '/resourceGroups/', parameters('templateSpecSettings').templateSpecResourceGroupName, '/providers/Microsoft.Resources/TemplateSpecs/', parameters('templateSpecSettings').appServicePlan.name, '/versions/', parameters('templateSpecSettings').appServicePlan.version)]"
},
"parameters": {
"appServicePlanSettings": {
"value": "[parameters('appServicePlanSettings')[copyIndex()]]"
},
"resourceNameAndTagSettings": {
"value": "[parameters('resourceNameAndTagSettings')]"
}
}
},
"dependsOn": []
}
],
"outputs": {}
}
Parameter File:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"appServicePlanSettings": {
"value": [
{
"comments": "App Service Plan 1",
"deploy": true,
"nameAbbr": "Asp",
"isLinuxOS": false,
"isHypervContainerPlan": false,
"perSiteScaling": false,
"tagValuePurpose": "Test",
"kind": "app",
"sku": "P1v2",
"skuTier": "PremiumV2"
}
]
},
"resourceNameAndTagSettings": {
"value": {
"environmentType": "dev",
"locationAbbr": "europe",
"resourceGroupNumber": "001",
"solutionNameAbbr": "test",
"tagValueCostCenter": "123",
"tagValueEnvironmentType": "Development",
"tagValueOwner": "me"
}
},
"templateSpecSettings": {
"value": {
"templateSpecResourceGroupName": "XXX",
"templateSpecSubscriptionId": "XXX",
"appServicePlan": {
"name": "appServicePlanTest",
"version": "1.2"
}
}
}
}
}
This deploys just fine.
But if I leave out:
"isHypervContainerPlan": false,
in the parameter file, the deployment will fail with this message:
Unable to process template language expressions for resource '...' at
line '24' and column '9'. 'The language expression property
'isHypervContainerPlan' doesn't exist, available properties are
'comments, deploy, nameAbbr, isLinuxOS, perSiteScaling,
tagValuePurpose, kind, sku, skuTier'.
Why would it fail on this error if the defaultValue is set in the Template Spec parameters section?
What am I missing here or are defaultValues not supported with Template Specs?
A defaultValue on a parameter is only used if no value is supplied. Put another way, you can you either use the defaultValue for a parameter or supply a value, not both, nor any combination of the two.
Your templateSpec expects a complex object for the appServicePlanSettings parameter. That object needs to have all of the properties referenced by the serverFarm resource being deployed. You're supplying a value for that param, but you're also omitting one of the properties from that parameter, and that's the property that's being flagged in the error message.
To see this in action in another way, put that property back into your param file and remove a different one, you'll see a similar error... or you could just not supply a param value at all for the ``appServicePlanSettings``` and then the defaultValue will be used.
I've been testing with the 'defaultValue'.
I have also tested with this setup:
Template:
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"appServicePlanSettings": {
"type": "object",
"defaultValue": {
"isHypervContainerPlan": false,
"isLinuxOS": false,
"perSiteScaling": false
}
},
"resourceNameAndTagSettings": {
"type": "object"
}
},
"variables": {
"appServicePlanName": "[concat('o', parameters('appServicePlanSettings').nameAbbr, parameters('resourceNameAndTagSettings').environmentType, parameters('resourceNameAndTagSettings').resourceGroupNumber, parameters('resourceNameAndTagSettings').solutionNameAbbr, parameters('resourceNameAndTagSettings').locationAbbr)]"
},
"resources": [
{
"comments": "App Service Plans",
"condition": "[parameters('appServicePlanSettings').deploy]",
"apiVersion": "2020-09-01",
"type": "Microsoft.Web/serverfarms",
"name": "[variables('appServicePlanName')]",
"location": "[resourceGroup().location]",
"tags": {
"_Purpose": "[parameters('appServicePlanSettings').tagValuePurpose]",
"CostCenter": "[parameters('resourceNameAndTagSettings').tagValueCostCenter]",
"EnvironmentType": "[parameters('resourceNameAndTagSettings').tagValueEnvironmentType]",
"Owner": "[parameters('resourceNameAndTagSettings').tagValueOwner]"
},
"kind": "[parameters('appServicePlanSettings').kind]",
"sku": {
"name": "[parameters('appServicePlanSettings').sku]",
"size": "[parameters('appServicePlanSettings').sku]",
"tier": "[parameters('appServicePlanSettings').skuTier]"
},
"properties": {
"hyperV": "[parameters('appServicePlanSettings').isHypervContainerPlan]",
"perSiteScaling": "[parameters('appServicePlanSettings').perSiteScaling]",
"reserved": "[parameters('appServicePlanSettings').isLinuxOS]"
},
"dependsOn": []
}
],
"outputs": {}
}
Parameters:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"appServicePlanSettings": {
"value": {
"comments": "App Service Plan 1",
"deploy": true,
"nameAbbr": "Asp",
"isLinuxOS": "",
"isHypervContainerPlan": "",
"perSiteScaling": "",
"tagValuePurpose": "Test",
"kind": "app",
"sku": "P1v2",
"skuTier": "PremiumV2"
}
},
"resourceNameAndTagSettings": {
"value": {
"environmentType": "dev",
"locationAbbr": "europe",
"resourceGroupNumber": "001",
"solutionNameAbbr": "test",
"tagValueCostCenter": "123",
"tagValueEnvironmentType": "Development",
"tagValueOwner": "me"
}
},
"templateSpecSettings": {
"value": {
"templateSpecResourceGroupName": "oGen1Weu1PrdMng001",
"templateSpecSubscriptionId": "130176f8-513a-4869-9db3-7c46d0e25159",
"appServicePlan": {
"name": "appServicePlanTest",
"version": "1.2"
}
}
}
}
}
Which also doesn't work when I do not specify "isHypervContainerPlan" in the parameter file, I thought we tested this, but apparently not good enough...
The only thing that works is defining:
"isHypervContainerPlan": "",
in the parameter file, thus not specifying a value. Which is not desirable, because then still all parameters have to be defined, even when I do not want to override the defaults.
So, the solution in the end has become the following (the main template remains the same):
Template Spec:
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"appServicePlanSettings": {
"type": "object"
},
"resourceNameAndTagSettings": {
"type": "object"
}
},
"variables": {
"appServicePlanName": "[concat('o', parameters('appServicePlanSettings').nameAbbr, parameters('resourceNameAndTagSettings').environmentType, parameters('resourceNameAndTagSettings').resourceGroupNumber, parameters('resourceNameAndTagSettings').solutionNameAbbr, parameters('resourceNameAndTagSettings').locationAbbr)]",
"appServicePlanSettings": {
"isHypervContainerPlan": false,
"isLinuxOS": false,
"kind": "app",
"nameAbbr": "Asp",
"perSiteScaling": false
}
},
"resources": [
{
"comments": "App Service Plans",
"condition": "[parameters('appServicePlanSettings').deploy]",
"apiVersion": "2020-09-01",
"type": "Microsoft.Web/serverfarms",
"name": "[variables('appServicePlanName')]",
"location": "[resourceGroup().location]",
"tags": {
"_Purpose": "[parameters('appServicePlanSettings').tagValuePurpose]",
"CostCenter": "[parameters('resourceNameAndTagSettings').tagValueCostCenter]",
"EnvironmentType": "[parameters('resourceNameAndTagSettings').tagValueEnvironmentType]",
"Owner": "[parameters('resourceNameAndTagSettings').tagValueOwner]"
},
"kind": "[if(contains(parameters('appServicePlanSettings'), 'kind'), parameters('appServicePlanSettings').kind, variables('appServicePlanSettings').kind)]",
"sku": {
"name": "[parameters('appServicePlanSettings').sku]",
"size": "[parameters('appServicePlanSettings').sku]",
"tier": "[parameters('appServicePlanSettings').skuTier]"
},
"properties": {
"hyperV": "[if(contains(parameters('appServicePlanSettings'), 'isHypervContainerPlan'), parameters('appServicePlanSettings').isHypervContainerPlan, variables('appServicePlanSettings').isHypervContainerPlan)]",
"perSiteScaling": "[if(contains(parameters('appServicePlanSettings'), 'perSiteScaling'), parameters('appServicePlanSettings').perSiteScaling, variables('appServicePlanSettings').perSiteScaling)]",
"reserved": "[if(contains(parameters('appServicePlanSettings'), 'isLinuxOS'), parameters('appServicePlanSettings').isLinuxOS, variables('appServicePlanSettings').isLinuxOS)]"
},
"dependsOn": []
}
],
"outputs": {}
}
And if I don't specify these values now in the parameter file, the value configured in the variable section will be used:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"appServicePlanSettings": {
"value": [
{
"comments": "App Service Plan 1",
"deploy": true,
"nameAbbr": "Asp",
"tagValuePurpose": "Test",
"kind": "app",
"sku": "P1v2",
"skuTier": "PremiumV2"
}
]
},
"resourceNameAndTagSettings": {
"value": {
"environmentType": "dev",
"locationAbbr": "europe",
"resourceGroupNumber": "001",
"solutionNameAbbr": "test",
"tagValueCostCenter": "123",
"tagValueEnvironmentType": "Development",
"tagValueOwner": "me"
}
},
"templateSpecSettings": {
"value": {
"templateSpecResourceGroupName": "XXX",
"templateSpecSubscriptionId": "XXX",
"appServicePlan": {
"name": "appServicePlanTest",
"version": "1.2"
}
}
}
}
}

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?

What is the difference between LogicApp.json and LogicApp.definition.json templates?

I have created same Logic App locally on visual studio code and visual code community. I found that both created different template files i.e. LogicApp.json on VS Community and LogicApp.definition.json on VS Code. What make these template files different from each other?
Json from VS Community (LogicApp.json):-
{
"$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": "[resourceGroup().location]",
"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",
"uaenorth",
"southafricanorth",
"southafricawest",
"switzerlandnorth",
"switzerlandwest",
"germanynorth",
"germanywestcentral",
"norwayeast",
"brazilsoutheast"
],
"metadata": {
"description": "Location of the Logic App."
}
}
},
"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": {
"Response": {
"type": "Response",
"kind": "http",
"inputs": {
"statusCode": 200,
"body": "hello user!"
},
"runAfter": {}
}
},
"parameters": {},
"triggers": {
"manual": {
"type": "Request",
"kind": "Http",
"inputs": {
"schema": {},
"method": "GET"
}
}
},
"contentVersion": "1.0.0.0",
"outputs": {}
},
"parameters": {}
}
}
],
"outputs": {}
}
Json from VS Code (LoginApp.definition.json):-
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"workflows_logic_vscode_name": {
"defaultValue": "logic-vscode",
"type": "string"
}
},
"resources": [
{
"apiVersion": "2017-07-01",
"dependsOn": [],
"location": "eastus",
"name": "[parameters('workflows_logic_vscode_name')]",
"properties": {
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"triggers": {
"Request": {
"type": "Request",
"kind": "Http",
"inputs": {
"method": "GET",
"schema": {}
}
}
},
"actions": {
"Response": {
"runAfter": {},
"type": "Response",
"inputs": {
"body": "Hello user",
"statusCode": 200
}
}
},
"outputs": {}
},
"parameters": {},
"state": "Enabled"
},
"scale": null,
"tags": {},
"type": "Microsoft.Logic/workflows"
}
],
"variables": {}
}
Both are workflow definitions, when you check in details the workflow looks similar but the format is different.
Formats will get differs when the creation done in VS-Code/Visual Studio/Portal/etc..
Below is the sample definition how it looks when we create it from Azure Portal:
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/XXXX-06-01/workflowdefinition.json#",
"actions": {},
"contentVersion": "X.0.0.0",
"outputs": {},
"triggers": {
"manual": {
"inputs": {},
"kind": "Http",
"type": "Request"
}
}
},
"kind": "Stateful"
}
Have a look on the difference in creation of logic app in VSCode and VisualStudio and its workflow from Microsoft documentation.

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

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

How to tag Current time as a Tag for an ARM Deployment

I am trying to create a Log Analytics Workspace using an ARM template and a parameter files. I am also thinking to tag currrent time as CreatedOn tag for the resource.
Below is my ARM template-
{
"$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"LAWName": {
"type": "string"
},
"LocationName": {
"type": "string"
},
"SKUName": {
"type": "string"
},
"Tags": {
"type": "object"
}
},
"resources": [
{
"apiVersion": "2017-03-15-preview",
"name": "[parameters('LAWName')]",
"location": "[parameters('LocationName')]",
"tags": "[parameters('Tags')]",
"type": "Microsoft.OperationalInsights/workspaces",
"properties": {
"sku": {
"name": "[parameters('SKUName')]"
}
}
}
]
}
and here is my param file-
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"LAWName": {
"value": "atifmtest1"
},
"LocationName": {
"value": "westeurope"
},
"SKUName": {
"value": "pergb2018"
}
"Tags": {
"value": {
"CreatedBy": "Atif",
"CreatedOn": "[utcNow()]",
"Purpose": "Monitoring"
}
}
}
}
I read here https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/template-functions-date#utcnow that there is utcNow() function for ARM template but that is being considered as a string here and the current time does not appear as a tag for the resource.
What is the other way using which this can be achieved ?
Thanks in advance !!
Here is a working example:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"utcShort": {
"type": "string",
"defaultValue": "[utcNow('d')]"
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]"
}
},
"resources": [
{
"apiVersion": "2019-04-01",
"type": "Microsoft.Storage/storageAccounts",
"name": "[concat('storage', uniqueString(resourceGroup().id))]",
"location": "[parameters('location')]",
"tags": {
"Dept": "Finance",
"Environment": "Production",
"LastDeployed": "[parameters('utcShort')]"
},
"sku": {
"name": "Standard_LRS"
},
"kind": "Storage",
"properties": {}
}
]
}
Source.
Please follow the below steps for better results.
Add the utcShort in parameters and give a default value "[utcNow()]", Its not work from the parameters file. add utcShort into variables to make an object type. Follow the below steps.
"utcShort ": {
"type": "string",
"defaultValue": "[utcNow()]"
},
"resourceTags": {
"type": "object"
}
},
"variables":{
"createdDate": {
"createdDate": "[parameters('utcShort ')]"
}
},
Use this variable in Tags like below..
"tags": "[union(parameters('resourceTags'), variables('createdDate'))]"

Resources