Terraform-provider-azurerm: Logic Apps: support for connections

Created on 31 Jul 2018  ยท  23Comments  ยท  Source: terraform-providers/terraform-provider-azurerm

Community Note

  • Please vote on this issue by adding a ๐Ÿ‘ reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

Add into Logic App Resource a resource that handles api connection creation and edition.

New or Affected Resource(s)

azurerm_logic_app_api_connection
(suggestion)

enhancement new-resource serviclogic

Most helpful comment

I'm also facing missing connection enforce me to run terraform twice to complete logic app settings.
Is the logic app connection resource schema will be like this?

original schema.

"$connections": {
    "value": {
        "slack" : {
            "connectionId": "/subscriptions/XXX-XXXresourceGroups/test/providers/Microsoft.Web/connections/slack-1",
            "connectionName": "slack-1",
            "id": "/subscriptions/XXX-XXX/providers/Microsoft.Web/locations/useast/managedApis/slack"
        }
    }
}

terraform schema.

resource "azurerm_logic_app_connection_custom" "slack" {
  name         = "slack"
  logic_app_id = "${azurerm_logic_app_workflow.test.id}"

  schema = <<SCHEMA
{
    "connectionId": "/subscriptions/XXX-XXXresourceGroups/test/providers/Microsoft.Web/connections/slack-1",
    "connectionName": "slack-1",
    "id": "/subscriptions/XXX-XXX/providers/Microsoft.Web/locations/useast/managedApis/slack"
}
SCHEMA
}

All 23 comments

hey @Kekedev

Thanks for opening this issue :)

So that we could understand the scope of this feature, do you have an example of the kind of fields available for a Logic App API Connection, such as an existing ARM Template?

Thanks!

Hi, thanks for the quick reply. ๐Ÿ‘
Sure, the basic concept of it is to "synchronize" a ftp server and a blob container by first listing files and both and if there is any difference download one file from the ftp to the blob. The whole thing is set with a recurrence of a few hours.
I can almost write every action and trigger except for the ftp and blob action, that should use api connection but i didn't find out how to automate them.

Here is the template of my existing logic app that I want to automatize:

{
    "$connections": {
        "value": {
            "azureblob": {
                "connectionId": "/subscriptions/XXX-XXX/resourceGroups/rg/providers/Microsoft.Web/connections/azureblob-1",
                "connectionName": "azureblob-1",
                "id": "/subscriptions/XXX-XXX/providers/Microsoft.Web/locations/southeastasia/managedApis/azureblob"
            },
            "ftp": {
                "connectionId": "/subscriptions/XXX-XXX/resourceGroups/rg/providers/Microsoft.Web/connections/ftp-1",
                "connectionName": "ftp-1",
                "id": "/subscriptions/XXX-XXX/providers/Microsoft.Web/locations/location/managedApis/ftp"
            }
        }
    },
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Condition": {
                "actions": {
                    "Create_blob": {
                        "inputs": {
                            "body": "@body('Get_file_content')",
                            "host": {
                                "connection": {
                                    "name": "@parameters('$connections')['azureblob']['connectionId']"
                                }
                            },
                            "method": "post",
                            "path": "/datasets/default/files",
                            "queries": {
                                "folderPath": "/dlglogs",
                                "name": "@{first(body('Filter_array'))['Name']}",
                                "queryParametersSingleEncoded": true
                            }
                        },
                        "runAfter": {
                            "Get_file_content": [
                                "Succeeded"
                            ]
                        },
                        "runtimeConfiguration": {
                            "contentTransfer": {
                                "transferMode": "Chunked"
                            }
                        },
                        "type": "ApiConnection"
                    },
                    "Get_file_content": {
                        "inputs": {
                            "host": {
                                "connection": {
                                    "name": "@parameters('$connections')['ftp']['connectionId']"
                                }
                            },
                            "method": "get",
                            "path": "/datasets/default/files/@{encodeURIComponent(encodeURIComponent(concat(variables('PATH_FTP'), string('/'), first(body('Filter_array'))['Name'])))}/content",
                            "queries": {
                                "inferContentType": true
                            }
                        },
                        "limit": {
                            "timeout": "P1D"
                        },
                        "operationOptions": "DisableAsyncPattern, DisableAutomaticDecompression",
                        "runAfter": {},
                        "type": "ApiConnection"
                    }
                },
                "expression": {
                    "and": [
                        {
                            "greater": [
                                "@length(body('Filter_array'))",
                                0
                            ]
                        }
                    ]
                },
                "runAfter": {
                    "Filter_array": [
                        "Succeeded"
                    ]
                },
                "type": "If"
            },
            "Filter_array": {
                "inputs": {
                    "from": "@body('Select_2')",
                    "where": "@not(contains(body('Select'), item()))"
                },
                "runAfter": {
                    "Select_2": [
                        "Succeeded"
                    ]
                },
                "type": "Query"
            },
            "Initialize_variable": {
                "inputs": {
                    "variables": [
                        {
                            "name": "PATH_FTP",
                            "type": "String",
                            "value": "path_in_ftp"
                        }
                    ]
                },
                "runAfter": {},
                "type": "InitializeVariable"
            },
            "List_blobs_2": {
                "inputs": {
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['azureblob']['connectionId']"
                        }
                    },
                    "method": "get",
                    "path": "/datasets/default/foldersV2/@{encodeURIComponent(encodeURIComponent('JTJmZGxnbG9ncw=='))}",
                    "queries": {
                        "useFlatListing": false
                    }
                },
                "metadata": {
                    "JTJmZGxnbG9ncw==": "/blob_folder"
                },
                "runAfter": {
                    "Initialize_variable": [
                        "Succeeded"
                    ]
                },
                "type": "ApiConnection"
            },
            "List_files_in_folder_2": {
                "inputs": {
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['ftp']['connectionId']"
                        }
                    },
                    "method": "get",
                    "path": "/datasets/default/folders/@{encodeURIComponent(encodeURIComponent('LzAyIExvZ3MvMDAgUkVWRU5VRS8wMyBETEdCQUNLVVBTL1Byb2Nlc3NlZA=='))}"
                },
                "metadata": {
                    "LzAyIExvZ3MvMDAgUkVWRU5VRS8wMyBETEdCQUNLVVBTL1Byb2Nlc3NlZA==": "path_in_ftp"
                },
                "runAfter": {
                    "Select": [
                        "Succeeded"
                    ]
                },
                "type": "ApiConnection"
            },
            "Select": {
                "inputs": {
                    "from": "@body('List_blobs_2')?['value']",
                    "select": {
                        "Name": "@item()['Name']"
                    }
                },
                "runAfter": {
                    "List_blobs_2": [
                        "Succeeded"
                    ]
                },
                "type": "Select"
            },
            "Select_2": {
                "inputs": {
                    "from": "@body('List_files_in_folder_2')",
                    "select": {
                        "Name": "@item()['Name']"
                    }
                },
                "runAfter": {
                    "List_files_in_folder_2": [
                        "Succeeded"
                    ]
                },
                "type": "Select"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {
            "$connections": {
                "defaultValue": {},
                "type": "Object"
            }
        },
        "triggers": {
            "Recurrence": {
                "recurrence": {
                    "frequency": "Hour",
                    "interval": 6
                },
                "type": "Recurrence"
            }
        }
    }
}

@Kekedev awesome thanks for confirming that. From the look of it this'd be an extension of the azurerm_logic_app_workspace resource since these connections appear to be scoped globally as such I've re-tagged this as an enhancement :)

Yes, actually when you create those through Azure portal, new resources object appear in my resource group. And within the schema of the app workflow it is only possible to find reference to those resource, and not the details of the resource creation themselves. Maybe that's also something that needs to be done on Azure side.

From the looks of it, there will also need to be a new resource as I can't see an existing resource for the ARM side of things.

Here's some examples I've used at work which creates the connections to be used by a logic app

        {
            "type": "Microsoft.Web/connections",
            "name": "[parameters('connections_servicebus_name')]",
            "apiVersion": "2016-06-01",
            "location": "northeurope",
            "scale": null,
            "properties": {
                "displayName": "ServiceBus",
                "api": {
                    "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/',resourceGroup().location, '/managedApis/servicebus')]"
                },
                "parameterValues": {
                    "connectionString": "[listkeys(resourceId('Microsoft.ServiceBus/namespaces/AuthorizationRules', parameters('serviceBusNamespace_name'), 'Listen'), '2017-04-01').primaryConnectionString]"
                }
            },
            "dependsOn": []
        }
 {
            "type": "Microsoft.Web/connections",
            "name": "[parameters('connections_documentdb_name')]",
            "apiVersion": "2016-06-01",
            "location": "northeurope",
            "scale": null,
            "properties": {
                "displayName": "CosmosDB",
                "api": {
                    "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/',resourceGroup().location, '/managedApis/documentdb')]"
                },
                "parameterValues": {
                    "databaseAccount": "[parameters('databaseAccountsCache_name')]",
                    "accessKey": "[listKeys(resourceId('Microsoft.DocumentDb/databaseAccounts', parameters('databaseAccountsCache_name')), '2015-04-08').primaryMasterKey]"
                }
            },
            "dependsOn": []
        }
{
    "type": "Microsoft.Web/connections",
    "name": "[variables('LogicApp_BlobStorageConnectionName')]",
    "apiVersion": "2016-06-01",
    "location": "[resourceGroup().location]",
    "scale": null,
    "properties": {
        "displayName": "BlobStorage",
        "customParameterValues": {},
        "parameterValues": {
            "accountName": "[parameters('BlobStorageAccountName')]",
            "accessKey": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('BlobStorageAccountName')), providers('Microsoft.Storage', 'storageAccounts').apiVersions[0]).keys[0].value]"
        },
        "api": {
            "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/', 'azureblob')]"
        }
    },
    "dependsOn": [
        "[resourceId('Microsoft.Storage/storageAccounts', parameters('BlobStorageAccountName'))]"
    ]
}

One of the main gotchas is the valid parameterValues entries depend on the type on connection, service bus, cosmos db etc. Thing's may have changed, but when I created a template a little while ago I had a hard time finding documentation for the valid entries.

@scottrangerio @Kekedev thanks for that; given there's a bunch of different API connections we're probably best doing the same as we've done with the Logic App Actions/Triggers and having a type for the common ones, and then a "custom" one to allow folks to specify others - but it needs further investigation for sure :)

What's the status on this? This feature would be very helpful! ๐Ÿ‘

I'm also facing missing connection enforce me to run terraform twice to complete logic app settings.
Is the logic app connection resource schema will be like this?

original schema.

"$connections": {
    "value": {
        "slack" : {
            "connectionId": "/subscriptions/XXX-XXXresourceGroups/test/providers/Microsoft.Web/connections/slack-1",
            "connectionName": "slack-1",
            "id": "/subscriptions/XXX-XXX/providers/Microsoft.Web/locations/useast/managedApis/slack"
        }
    }
}

terraform schema.

resource "azurerm_logic_app_connection_custom" "slack" {
  name         = "slack"
  logic_app_id = "${azurerm_logic_app_workflow.test.id}"

  schema = <<SCHEMA
{
    "connectionId": "/subscriptions/XXX-XXXresourceGroups/test/providers/Microsoft.Web/connections/slack-1",
    "connectionName": "slack-1",
    "id": "/subscriptions/XXX-XXX/providers/Microsoft.Web/locations/useast/managedApis/slack"
}
SCHEMA
}

+1
It would be fine to have support for api connection (Microsoft.Web/connections) creation.

Currently only fallback to arm template is possible. I'm I wrong?

@guitarrapc I'm currently trying to configure a connection with slack in order to send alert notifications there in the future. Can you share, how did you eventually configure that connection? Why do you need to run terraform twice?

@krysickij1 Because you cannnot run azurerm_logic_app_action_custom without prerequisite slack connection. So if you want to make any logic_app, create Slack API via az, then run terraform with

  1. create slack connection with azurerm_logic_app_connection_custom, make sure dependent resource azurerm_logic_app_action_custom is comment out.
  2. now you can run azurerm_logic_app_action_custom.

@guitarrapc Thank you for a quick response. I have additional questions:

create Slack API via az

Do you mean by az portal or az cli? If the second is true - can you provide me with any documentation on how to do that?

create slack connection with azurerm_logic_app_connection_custom

I couldn't find any documentation on that topic here https://www.terraform.io/docs/providers/azurerm. Do you mean using the script posted by you above?

I also would like to see support for API Connections in Logic Apps.
It is possible to deploy the API Connection using "azurerm_template_deployment" but I cannot reference it within the workflow or actions.

When will azurerm_logic_app_api_connection be available?

I'm also looking for this functionality. Any ETA on when it will be available? For now I think my solution will need to switch to a function app with the equivalent connection strings.

Our company is adopting Terraform as the standard for Azure scripting. I have a logic app that needs an ACI connection. Have you made any progress on this issue?

It appears you need to be able to create the actual connection prior to referencing it in parameters.$connections.

I don't see a function in azurerm for creating an ACI connection.
I don't see a way to reference a connection in azurerm_logic_app_workflow

@rkralston have a look at the Azure Sample here. Specifically this area of the terraform file. Hopefully that helps and gets you moving forward in lieu of this being fixed by Hashicorp.

@brandonh-msft, just to be sure, there is no way with plain terraform script to deploy a Logic App Connection?
Asking because the link you gave in your last post points to an ARM template that is included in a terraform schript.

@brandonh-msft, just to be sure, there is no way with plain terraform script to deploy a Logic App Connection?

None of which I'm aware. But it's _a_ way of doing it until it's available in a more first-class fashion in terraform.

We actually abandoned Logic apps over this and went with Functions. Logic
apps are over complicated when it comes to real world scenarios, they
should just retire them.

On Fri, Jul 24, 2020, 11:03 AM Brandon H notifications@github.com wrote:

@brandonh-msft https://github.com/brandonh-msft, just to be sure, there
is no way with plain terraform script to deploy a Logic App Connection?

correct. But it's a way of doing it until it's available in a more
first-class fashion in terraform.

โ€”
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/terraform-providers/terraform-provider-azurerm/issues/1691#issuecomment-663611087,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ABNCRHWUNUKBXA36EH6A7DDR5GWDPANCNFSM4FNBWJVA
.

We actually abandoned Logic apps over this and went with Functions. Logic apps are over complicated when it comes to real world scenarios, they should just retire them.
โ€ฆ
On Fri, Jul 24, 2020, 11:03 AM Brandon H @.*> wrote: @brandonh-msft https://github.com/brandonh-msft, just to be sure, there is no way with plain terraform script to deploy a Logic App Connection? correct. But it's a way of doing it until it's available in a more first-class fashion in terraform. โ€” You are receiving this because you commented. Reply to this email directly, view it on GitHub <#1691 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABNCRHWUNUKBXA36EH6A7DDR5GWDPANCNFSM4FNBWJVA .

That's really frustrating.
Definetely needed to map this resource into my terraform structure as my team already created it via portal and we are using it extensively.

We can deploy connections using ARM templates. It stinks, but it works.
Just calling APIs from a function is 100% easier.

On Thu, Sep 3, 2020, 10:46 AM Guilherme Ramos Gouveia <
[email protected]> wrote:

We actually abandoned Logic apps over this and went with Functions. Logic
apps are over complicated when it comes to real world scenarios, they
should just retire them.
โ€ฆ <#m_-1751850287361344604_>
On Fri, Jul 24, 2020, 11:03 AM Brandon H @.*> wrote: @brandonh-msft
https://github.com/brandonh-msft https://github.com/brandonh-msft, just
to be sure, there is no way with plain terraform script to deploy a Logic
App Connection? correct. But it's a way of doing it until it's
available in a more first-class fashion in terraform. โ€” You are receiving
this because you commented. Reply to this email directly, view it on GitHub
<#1691 (comment)
https://github.com/terraform-providers/terraform-provider-azurerm/issues/1691#issuecomment-663611087>,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ABNCRHWUNUKBXA36EH6A7DDR5GWDPANCNFSM4FNBWJVA
.

That's really frustrating.
Definetely needed to map this resource into my terraform structure as my
team already created it via portal and we are using it extensively.

โ€”
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/terraform-providers/terraform-provider-azurerm/issues/1691#issuecomment-686581728,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAHZELGSXPFQDD4UUST6W3DSD624RANCNFSM4FNBWJVA
.

We can deploy connections using ARM templates. It stinks, but it works. Just calling APIs from a function is 100% easier. On Thu, Sep 3, 2020, 10:46 AM Guilherme Ramos Gouveia < [email protected]> wrote:
โ€ฆ
We actually abandoned Logic apps over this and went with Functions. Logic apps are over complicated when it comes to real world scenarios, they should just retire them. โ€ฆ <#m_-1751850287361344604_> On Fri, Jul 24, 2020, 11:03 AM Brandon H @.*> wrote: @brandonh-msft https://github.com/brandonh-msft https://github.com/brandonh-msft, just to be sure, there is no way with plain terraform script to deploy a Logic App Connection? correct. But it's a way of doing it until it's available in a more first-class fashion in terraform. โ€” You are receiving this because you commented. Reply to this email directly, view it on GitHub <#1691 (comment) <#1691 (comment)>>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABNCRHWUNUKBXA36EH6A7DDR5GWDPANCNFSM4FNBWJVA . That's really frustrating. Definetely needed to map this resource into my terraform structure as my team already created it via portal and we are using it extensively. โ€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#1691 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHZELGSXPFQDD4UUST6W3DSD624RANCNFSM4FNBWJVA .

@rkralston Did that, but I'm now having some trouble with the authorization of this connection.
Somehow the Logic App says it couldn't find the connector I created through ARM Template, and when I try to connect it manually it says it's not authorized, though I authorized it manually.

Was this page helpful?
0 / 5 - 0 ratings