繁体   English   中英

通过逻辑应用中的 ARM 连接器创建子资源

[英]Create a child resource by ARM connector in Logic App

如何使用 Logic App 创建子资源(例如 Blob 存储的容器或 Eventhub 的使用者组)?

要在 Logic App 中使用 ARM 连接器创建资源,您需要指定用于构建新服务路径的提供程序和短资源 ID。 但是,它们不对应于 ARM 模板中的“type”和“name”参数(在示例“Microsoft.Eventhub/namespaces”和“vvtesteventhub”中)。

示例资源逻辑应用程序

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

对于子资源,有必要以某种方式构造包括父资源名称的完整路径。 但是,即使直接通过代码视图编辑,我也无法构建它(见下文)。 运行失败并显示错误消息“未找到资源”,尽管它包含指向我要在其中创建使用者组的现有事件中心的正确路径。

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

我们已经在本地环境中对此进行了测试,它工作正常,以下陈述基于分析。

在我们的本地环境中,我们创建了一个事件中心命名空间和一个逻辑应用程序。

使用逻辑应用程序Azure resource Manager connector操作创建或更新资源,我们能够创建 EventHub 并在其中跟随一个消费者组。

这是逻辑应用程序:

在此处输入图像描述

这是逻辑应用程序的代码视图:

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

下面是样本output供参考:

在此处输入图像描述

笔记:

为了创建 EventHub 的消费者组,您需要有一个现有的 EventHub,或者您需要创建一个新的 Event Hub。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM