Bicep template to deploy Logic App with CosmosDB action and Inline JS action

Angelo Peca 75 Reputation points
2023-05-17T01:34:11.61+00:00

Hello,

I'm trying to create a Bicep template to deploy a simple Logic App infrastructure containing an HTTP request trigger and 2 actions: an inline Javascript code execution and an insertion into a CosmosDB instance.

This is the Bicep template I have at the moment:


@description('The name of the logic app to create.')
param logicAppName string

@description('Location for all resources.')
param location string = resourceGroup().location

resource logicApp 'Microsoft.Logic/workflows@2019-05-01' = {
    name: logicAppName
    location: location
    tags: {
        displayName: logicAppName
    }
    properties: {
        definition: {
            '$schema': 'https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#'
            actions: {
                Execute_JavaScript_Code: {
                    type: 'JavaScriptCode'
                    inputs: {
                        code: 'let jsonObj = workflowContext.trigger.outputs.body;\r\njsonObj.id = String(jsonObj.id);\r\nreturn jsonObj;'
                    }
                    runAfter: {}
                    trackedProperties: {}
                }
                Create_or_update_item: {
                    type: 'ServiceProvider'
                    inputs: {
                        parameters: {
                            databaseId: 'stateless-example-db-id'
                            containerId: 'stateless-example-db-container'
                            item: '@outputs(\'Execute_JavaScript_Code\')'
                            isUpsert: false
                        }
                        serviceProviderConfiguration: {
                            connectionName: 'AzureCosmosDB'
                            operationId: 'CreateOrUpdateDocument'
                            serviceProviderId: '/serviceProviders/AzureCosmosDB'
                        }
                    }
                    runAfter: {
                        Execute_JavaScript_Code: [
                            'Succeeded'
                        ]
                    }
                    trackedProperties: {}
                }
            }
            contentVersion: '1.0.0.0'
            outputs: {}
            triggers: {
                When_a_HTTP_request_is_received: {
                    type: 'Request'
                    kind: 'Http'
                    inputs: {
                        method: 'POST'
                    }
                }
            }
        }
    }
}

And this is the Azure CLI command I'm using:

az deployment group create --resource-group logic-app-stateless-workflow-portal-RG --template-file .\deployment\main.bicep --parameters logicAppName=StatelessExampleDeployment

I'm getting two different errors. The first one is related to the inline Javascript code execution:


{
  "status": "Failed",
  "error": {
    "code": "DeploymentFailed",
    "target": "/subscriptions/fa2331f2-0bbd-4a74-96a6-2ee23cf7ba25/resourceGroups/logic-app-stateless-workflow-portal-RG/providers/Microsoft.Resources/deployments/main",
    "message": "At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-deployment-operations for usage details.",
    "details": [
      {
        "code": "IntegrationAccountAssociationRequired",
        "message": "The workflow must be associated with an integration account to use the workflow run action 'Execute_JavaScript_Code' of type 'JavaScriptCode'."
      }
    ]
  }
}

The second one is related to the CosmosDB action:


{
  "status": "Failed",
  "error": {
    "code": "DeploymentFailed",
    "target": "/subscriptions/fa2331f2-0bbd-4a74-96a6-2ee23cf7ba25/resourceGroups/logic-app-stateless-workflow-portal-RG/providers/Microsoft.Resources/deployments/main",
    "message": "At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-deployment-operations for usage details.",
    "details": [
      {
        "code": "WorkflowRunActionTypeUnsupported",
        "message": "The workflow run action 'Create_or_update_item' has type 'ServiceProvider' that is not supported."
      }
    ]
  }
}

Do you have any advice on how to solve these issues?

Thanks in advance for your help,

Angelo

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
2,838 questions
Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,439 questions
0 comments No comments
{count} votes

Accepted answer
  1. VenkateshDodda-MSFT 18,081 Reputation points Microsoft Employee
    2023-05-17T07:55:18.2233333+00:00

    @Angelo Peca Thanks for reaching out to Microsoft Q&A, apologize for any inconvenience caused on this.

    Looking at the error messages, that you have shared in the above has clearly called out that your bicep deployment is failing with the below reasons.

    • We see that you are deploying consumption-based logic app which is having Execute JavaScript Code as one of the actions in your workflow. you need to integrate your logic app with Integration account to run the Execute JavaScript Code as mentioned here.

    You can add the integration account in your bicep file by referring to this bicep schema of Microsoft.Logic/IntegrationAccounts from here and also to link the logic app with integration account add the below block in properties of Microsoft.Logic/workflows@2019-05-01.

    integrationAccount: {
          id: 'string'
        }
    
    • You need to use Api connection instead of Service provider connection to create a connection to cosmos database account and to use Create_or_update_document(V3) action.

    Refer to this bicep schema here and add API connection block in your above bicep to establish a connection cosmos db.

    Feel free to reach back to me if you have any further questions on this.


0 additional answers

Sort by: Most helpful