我想知道如果使用事件网格,是否可以在 Azure 订阅上部署任何资源时触发逻辑应用程序。
用例是:
这里的目标是对这艘潜艇上发生的事情有一个简单和基本的直升机视图。
出于测试目的,我创建了一个逻辑应用程序,并使用 Microsoft.Resources.ResourceGroups 和这些事件类型添加了“资源事件发生时”触发器:
Microsoft.Resources.ResourceActionSuccess
Microsoft.Resources.ResourceDeleteSuccess
Microsoft.Resources.ResourceWriteSuccess
不确定我在这里探索。
然后我部署了一个storageaccount,但即使在资源实际部署之前“审查”部署时我也会收到通知。
部署后,我还会收到随机通知(即使未使用存储帐户,我猜是某种后台活动?)
根据这个官方文档:
资源事件是为发送到
的 PUT、PATCH、POST 和 DELETE 操作创建的。 GET 操作不会创建事件。management.azure.com
因此您收到多个触发器。对于最少的触发器,您可以为部署添加过滤器。以下是我正在使用的流程。
下面是我的逻辑应用程序的完整 JSON
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Send_an_email_(V2)": {
"inputs": {
"body": {
"Body": "<p>@{triggerBody()?['subject']} has been created</p>",
"Importance": "Normal",
"Subject": "xxx",
"To": "xxx"
},
"host": {
"connection": {
"name": "@parameters('$connections')['office365']['connectionId']"
}
},
"method": "post",
"path": "/v2/Mail"
},
"runAfter": {},
"type": "ApiConnection"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"When_a_resource_event_occurs": {
"conditions": [],
"inputs": {
"body": {
"properties": {
"destination": {
"endpointType": "webhook",
"properties": {
"endpointUrl": "@{listCallbackUrl()}"
}
},
"filter": {
"includedEventTypes": [
"Microsoft.Resources.ResourceDeleteSuccess",
"Microsoft.Resources.ResourceActionSuccess"
],
"subjectBeginsWith": "/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Resources/deployments"
},
"topic": "/subscriptions/xxx/resourceGroups/xxx"
}
},
"host": {
"connection": {
"name": "@parameters('$connections')['azureeventgrid']['connectionId']"
}
},
"path": "/subscriptions/@{encodeURIComponent('xxx')}/providers/@{encodeURIComponent('Microsoft.Resources.ResourceGroups')}/resource/eventSubscriptions",
"queries": {
"x-ms-api-version": "2017-09-15-preview"
}
},
"splitOn": "@triggerBody()",
"type": "ApiConnectionWebhook"
}
}
},
"parameters": {
"$connections": {
"value": {
"azureeventgrid": {
"connectionId": "/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Web/connections/azureeventgrid",
"connectionName": "azureeventgrid",
"id": "/subscriptions/xxx/providers/Microsoft.Web/locations/eastus/managedApis/azureeventgrid"
},
"office365": {
"connectionId": "/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Web/connections/office365",
"connectionName": "office365",
"id": "/subscriptions/xxx/providers/Microsoft.Web/locations/eastus/managedApis/office365"
}
}
}
}
}
结果: