Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logic Apps: support for connections #1691

Closed
Kekedev opened this issue Jul 31, 2018 · 30 comments · Fixed by #15797
Closed

Logic Apps: support for connections #1691

Kekedev opened this issue Jul 31, 2018 · 30 comments · Fixed by #15797

Comments

@Kekedev
Copy link

Kekedev commented Jul 31, 2018

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)

@tombuildsstuff
Copy link
Contributor

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!

@tombuildsstuff tombuildsstuff changed the title Api Connection resource creation automation New Resource: azurerm_logic_app_api_connection Aug 1, 2018
@tombuildsstuff tombuildsstuff changed the title Api Connection resource creation automation New Resource: azurerm_logic_app_api_connection Aug 1, 2018
@Kekedev
Copy link
Author

Kekedev commented Aug 1, 2018

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"
            }
        }
    }
}

@tombuildsstuff
Copy link
Contributor

@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 :)

@tombuildsstuff tombuildsstuff changed the title New Resource: azurerm_logic_app_api_connection Logic Apps: support for connections Aug 1, 2018
@Kekedev
Copy link
Author

Kekedev commented Aug 1, 2018

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.

@scottambroseio
Copy link

scottambroseio commented Aug 1, 2018

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.

@tombuildsstuff
Copy link
Contributor

@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 :)

@guitarrapc
Copy link

guitarrapc commented Oct 30, 2018

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
}

@RadekCap
Copy link

+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?

@krysickij1
Copy link

@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?

@guitarrapc
Copy link

@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.

@krysickij1
Copy link

@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?

@eXXL
Copy link

eXXL commented Aug 16, 2019

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.

@mikebollandajw

This comment has been minimized.

@JoshuaPHolden

This comment has been minimized.

@rkralston
Copy link

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

@brandonh-msft
Copy link

brandonh-msft commented Mar 3, 2020

@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.

@mregni
Copy link

mregni commented Jul 24, 2020

@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
Copy link

brandonh-msft commented Jul 24, 2020

@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.

@JoshuaPHolden
Copy link

JoshuaPHolden commented Jul 25, 2020 via email

@grgouveia
Copy link

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.

@rkralston
Copy link

rkralston commented Sep 3, 2020 via email

@grgouveia
Copy link

grgouveia commented Sep 3, 2020

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.

@ahmddp

This comment has been minimized.

@avineshwar
Copy link

avineshwar commented Feb 4, 2021

Encountered this problem for the second time today. Looking at the documentation, there is a schema mentioned for "Microsoft.Web/connections". So, are their plans to do this?

@favoretti
Copy link
Collaborator

Started looking into this today, stumbled on Azure/azure-sdk-for-go#9393. Let's see whether something changed there. Without SDK support we can't do much here either unfortunately :(

@marc-gmail-towersap
Copy link

marc-gmail-towersap commented May 12, 2021

Seems this is still an issue, at least for me.
ran a terraform import of an existing logic app I'm trying to terraform.

I see
"parameters": {
"$connections": ""
},

in my terraform, I addind the workflow_schema and version (using the values found in terraform import. added $connections as a parameter following the 'map' syntax with that value "".
terraform validate happy. plan? happy.
apply, crash.
The only declared parameters for this definition are ''.'

seems native terraform support for azurerm_logic_app_action_custom only works for fairly simplistic actions that don't reach out and connect to anything.

found this thread among others. tried azurerm_logic_app_connection_custom. failed, provider.azurerm doesn't support it.

Looked at #7241. been open for almost a year now.

It looks like the only way around this is the idea of embedding an ARM template within terraform, and doing the work to pass in parameters via terraform variables. It does work, but is ugly, purely because ARM is ugly.

You can see https://shervyna.medium.com/deploying-logic-app-in-terraform-with-arm-template-ci-cd-e45295244872 for one solution. I've implemented a variant of this, only using (note the name attribute in that resource block doesn't seem to be used, the name of the logic app is really defined within the ARM template).

resource "azurerm_template_deployment" "logicapp" {
name = "${var.prefix}-${var.environment}-la"
resource_group_name = azurerm_resource_group.thisrg.name
deployment_mode = "Incremental"
parameters_body = jsonencode(local.parameters_body)
template_body = <<DEPLOY
{
paste in contents of ARM template file, then modified it like below. this is just an example, I am doing more, but you should get the idea.

}
DEPLOY
}
For the parameter in the ARM template, it looks like
"subscriptionId": {
"type": "String"
},
"LogicApp_Name": {
"type": "String"
},

I also modified the resource section for the "Microsoft.Logic/workflows", with "name": "[parameters('LogicApp_Name')]",
and I also modified a connection parameter (really, I should move it to be a variable, but oh well
"sites_blahblah_externalid": {
"defaultValue": "[concat('/subscriptions/', parameters('SubscriptionId'), '/resourceGroups/my-rg/providers/Microsoft.Web/sites/mywebsite')]",
"type": "String"
},

As for the local.parameters_body?
it looks something like
locals {
department = "Mydepartment"
environment = var.environment
tags = {
department = local.department
environment = local.environment
}
parameters_body = {
subscriptionId = {
value = data.azurerm_client_config.current.subscription_id
},
LogicApp_Name = {
value = "${var.prefix}-${var.environment}-la"
}
}
}

FYI, I created variables named prefix and environment with values I can overwrite in terraform via -var environment=qa

It works, but again, as ugly as ARM templates, since it literally is ARM templates plus the terraform locals.

@khadirbaaoua
Copy link

Thanks to all the inputs above, I managed to terraform a few logic apps that connect to an sftp server and a blob storage.
Though I had one issue that's really confusing:

"parameters": {
      "connections_azureblob_name": {
        "type": "string"
      },

That's part of the generated ARM template for a blob connection (in case of a logic app) from Azure. Notice the string parameter type in lowercase. (also validated by the schema per https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#)
When terraforming such API connections, we didn't understand why TF would destroy/create until we understood that string parameters type should be in pascal case String instead of string.
Hopes this will be of use to anyone struggling with logic app with api connections terraforming

@abhinavssingh
Copy link

Hi, i am trying to create api connection through parameter options as per here but unable to do so and getting different error

parameters = { "office365" = "resource id from Azure" } Getting Office365 is not defined
"parameters": { "<office365>": { "type": "String", "defaultValue": "resource id from Azure", } }, getting Inappropriate value for attribute "parameters": element "office365": string required.

Have tried multiple combinations but still getting these two error. Could you please help me out how to create API connection and associate with action?

@github-actions
Copy link

This functionality has been released in v3.0.0 of the Terraform Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.