Home > OS >  Create a child resource by ARM connector in Logic App
Create a child resource by ARM connector in Logic App

Time:02-09

How can you create a child resource (e.g. container for Blob Storage, or consumer group for Eventhub) using Logic App?

To create a resource with the ARM connector in Logic App, you need to specify provider and short resource id which are used to construct the path to the new service. However, they do not correspond to the "type" and "name" parameters from ARM template (which would be in the example "Microsoft.Eventhub/namespaces" and "vvtesteventhub").

example resource Logic App

"inputs": {
    "body": {...},
    "host": {
        "connection": {
            "name": "@parameters('$connections')['arm']['connectionId']"
        }
    },
    "method": "put",
    "path": "/subscriptions/@{variables('subscriptionId')}/resourcegroups/@{variables('resourceGroup')}/providers/Microsoft.EventHub/namespaces/vvtesteventhub",
    "queries": {
        "x-ms-api-version": "2021-06-01-preview"
    }
}

For a child resource, it is necessary to somehow construct the full path including the parent resource name. However, I am not able to construct it even when editing the directly through the code view (see below). The run fails with error message "Resource not found", despite the fact that it includes the correct path to the existing eventhub where I want to create the consumer group.

{
    "inputs": {
        "host": {
            "connection": {
                "name": "@parameters('$connections')['arm']['connectionId']"
            }
        },
        "method": "put",
        "path": "/subscriptions/@{variables('subscriptionId')}/resourcegroups/@{variables('resourceGroup')}/providers/Microsoft.EventHub/namespaces/eventhubs/@{variables('eventhubNamespacesName')}/@{variables('eventhubName')}/consumergroups/@{variables('platformName')}",
        "queries": {
            "x-ms-api-version": "2021-06-01-preview"
        }
    }
}

CodePudding user response:

We have tested this in our local environment it is working fine, Below statements are based on the analysis.

In our local environment, we have created an event hub Namespace & a logic app.

Using logic app Azure resource Manager connector actions Create or Update a Resource we are able to create EventHub & followed it by a consumer group in it.

Here is the logic app :

enter image description here

Here is the code view of the logic app:

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Compose": {
                "inputs": "Microsoft.EventHub/namespaces",
                "runAfter": {},
                "type": "Compose"
            },
            "Create_a_ConsumerGroup_to_existing_EventHub": {
                "inputs": {
                    "body": {
                        "location": "westus"
                    },
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['arm']['connectionId']"
                        }
                    },
                    "method": "put",
                    "path": "/subscriptions/@{encodeURIComponent('<sub-id>')}/resourcegroups/@{encodeURIComponent('<rgName>')}/providers/@{encodeURIComponent(outputs('Compose'))}/@{encodeURIComponent('/<EventHubNamespacesName>/eventhubs/<EventHubName>/consumergroups/<ConsumerGroupName>')}",
                    "queries": {
                        "x-ms-api-version": "2021-11-01"
                    }
                },
                "runAfter": {
                    "Creates_a_EventHub_to_existing_EventHubNamespaces_": [
                        "Succeeded"
                    ]
                },
                "type": "ApiConnection"
            },
            "Creates_a_EventHub_to_existing_EventHubNamespaces_": {
                "inputs": {
                    "body": {
                        "location": "westus"
                    },
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['arm']['connectionId']"
                        }
                    },
                    "method": "put",
                    "path": "/subscriptions/@{encodeURIComponent('<sub-id>')}/resourcegroups/@{encodeURIComponent('<rgName>')}/providers/@{encodeURIComponent(outputs('Compose'))}/@{encodeURIComponent('/<EventHubNamespacesName>/eventhubs/<EventHubName>')}",
                    "queries": {
                        "x-ms-api-version": "2021-11-01"
                    }
                },
                "runAfter": {
                    "Compose": [
                        "Succeeded"
                    ]
                },
                "type": "ApiConnection"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {
            "$connections": {
                "defaultValue": {},
                "type": "Object"
            }
        },
        "triggers": {
            "Recurrence": {
                "recurrence": {
                    "frequency": "Hour",
                    "interval": 3
                },
                "type": "Recurrence"
            }
        }
    },
    "parameters": {
        "$connections": {
            "value": {
                "arm": {
                    "connectionId": "/subscriptions/<sub-id>/resourceGroups/<rgName>/providers/Microsoft.Web/connections/arm",
                    "connectionName": "arm",
                    "id": "/subscriptions/<sub-id>/providers/Microsoft.Web/locations/eastus/managedApis/arm"
                }
            }
        }
    }
}

Here is the sample output for reference:

enter image description here

Note:

In order to create a consumer group to EventHub you need to have an existing EventHub or you Need to create a New Event Hub.

  •  Tags:  
  • Related