Azure / logicapps

Azure Logic Apps labs, samples, and tools
MIT License
367 stars 302 forks source link

Incorrect handling of variable types parsed to Azure Automation #59

Closed krowlandson closed 5 years ago

krowlandson commented 5 years ago

Scenario

We're using Azure Logic Apps to trigger various Runbooks.

As a part of these Logic Apps, we need to submit a JSON object to our Runbook as a string. This is so we can then validate the JSON object using a validation test based on the following logic:

{ try { ConvertFrom-Json $_ -ErrorAction Stop; $true; } catch { $false; } }

During our testing, we've noticed that the Connector between Azure Logic Apps and Azure Automation is trying to be "too clever" by re-interpreting the object type.

This issue has also become apparent where we have a number of "switch" parameters which we've had to change to "boolean" parameters to get more predictable results, but this has brought its own challenges as listed below.

Some of the problems we've faced include:

Example

Using a specific example to illustrate this, if we take the following Logic App "Action" I'll explain the behaviors we observed:

"Trigger_Runbook": {
    "inputs": {
        "body": {
            "properties": {
                "parameters": {
                    "RunAsAccount": "\"AzureRunAsConnection\"",
                    "clzId": "@triggerBody()['clzId']",
                    "inputVariablesAsJsonString": "@{string(triggerBody())}",
                    "NoMgAssignment": 0,
                    "test": true
                }
            }
        },
        "host": {
            "connection": {
                "name": "@parameters('$connections')['azureautomation']['connectionId']"
            }
        },
        "method": "put",
        "path": "<removed>",
        "queries": {...}
    },
    "runAfter": {...},
    "type": "ApiConnection"
}

Booleans

Strings as Strings

JSON in Strings

Focus on JSON in Strings

Focusing specifically on the last issue from above, we've had to implement the following in our Logic App code to get the correct behaviour from our "JSON in a String":

In code, this looks like the following... (note the additional escaping of the characters that we're escaping, due to this being within a JSON string itself):

"inputVariablesAsJsonString": "@{concat('\"',replace(replace(string(triggerBody()),'\\','\\\\'),'\"','\\\"'),'\"')}",

As you can imagine, this is far from ideal and leaves us open to potential future problems as we're trying to manually re-factor valid JSON so it can be read by the Runbook as a String.

Summary

To remove the need to implement the workarounds described above, we would like to request an update to the connector between Azure Logic Apps and Azure Automation to allow correct handling of variable values and types from one system to the other.

joechung-msft commented 5 years ago

If you have questions about Logic Apps, please visit the MSDN forums. The Issues section here is for questions about the artifacts in this GitHub repository.