pulumi / pulumi-azure

A Microsoft Azure Pulumi resource package, providing multi-language access to Azure
Apache License 2.0
132 stars 50 forks source link

Logic Apps support #240

Closed mikhailshilkov closed 5 years ago

mikhailshilkov commented 5 years ago

I spend a couple of hours digging into Logic Apps with Pulumi, so I'm documenting my findings. My idea was to implement something like an App polling Twitter for a search term (e.g. Pulumi) and then sending notifications to a queue. These things make nice demos.

Pulumi has some support for Logic App resources, but not enough. The only strongly-typed trigger supported is Timer, and the only action is HTTP. All the REST has to come through copy-pasting large chunks of JSON from Azure Portal, e.g.

const workflow = new azure.logicapps.Workflow("myflow", {
    resourceGroupName: resourceGroup.name,
    parameters: {
        "$connections": ""
    }
});
new azure.logicapps.TriggerCustom("When_a_new_tweet_is_posted", {
    name: "When_a_new_tweet_is_posted",
    logicAppId: workflow.id,
    body: `{
        "inputs": {
            "host":{
                "connection": {
                    "name": "@parameters('$connections')['twitter']['connectionId']"
                }
            },
            "method": "get",
            "path": "/onnewtweet",
            "queries": { 
                "searchQuery": "Pulumi"
            }
        },
        "recurrence": {
            "frequency": "Minute",
            "interval":1
        },
        "splitOn": "@triggerBody()?['value']",
        "type": "ApiConnection"
    }`
});

new azure.logicapps.ActionCustom("Put_a_message_on_a_queue",{
    name: "Put_a_message_on_a_queue",
    logicAppId: workflow.id,
    body: `{
        "inputs": {
            "body": "@triggerBody()?['TweetText']",
            "host": {
                "connection": {
                    "name": "@parameters('$connections')['azurequeues']['connectionId']"
                }
            },
            "method": "post",
            "path": "/@{encodeURIComponent('MyQueue')}/messages"
        },
        "runAfter": {},
        "type": "ApiConnection"
    }`
});

The big missing piece here is the ability to define API Connector resources and corresponding parameters to link triggers/actions to connectors.

Obviously, these limitations come from Terraform. This basic sample is pretty much all you can do with Logic Apps. This issue tracks progress for API Connections. However, even if we get "custom" API Connections, I'm not sure how things like Twitter authentication/authorization will fit into this.

Two big value props of Logic Apps are connectors and visual designer. With none of these two things supported, there isn't much value in using Pulumi for Logic Apps yet. A reasonable first goal would be to support the scenario of importing Logic Apps created in the visual designer. Connectors are the main blockers here.

Upvote this issue if you need Logic Apps in Pulumi, otherwise we might park it for now.

lukehoban commented 5 years ago

Is it possible to do this 100% with ARM? Is it it not even fully supported at that layer?

mikhailshilkov commented 5 years ago

Haven't tried for real, but it looks like it's mostly supported apart from some extra moves needed for OAuth authorization

joshbwlng commented 5 years ago

I have some working ARM that creates a service bus queue, sets it up as a connection for a logic app, and then a logic app that uses that connection. Not sure about all other connection types, but was able to get it working with service bus queues.

Example code up on my blog: https://www.monc.io/posts/2019/05/example-of-logic-app-with-service-bus/

mikhailshilkov commented 5 years ago

We'll close this issue for now and will track the upstream issue for support of API connectors. When that one is done, we'll re-evaluate the whole Logic Apps story.