-
Notifications
You must be signed in to change notification settings - Fork 1
/
rg_add_eventgrid.bicep
72 lines (62 loc) · 2.17 KB
/
rg_add_eventgrid.bicep
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// This file adds an event grid subscription to a storage account that triggers
// when a blob is added
targetScope = 'resourceGroup'
@description('Unique suffix')
param suffix string = uniqueString(resourceGroup().id)
@description('The location of the resources')
param location string = resourceGroup().location
@description('The name of the function app to use')
param appName string = 'rpmfnapp${suffix}'
@description('The name of the storage account to use')
param storage_account_name string = 'rpmrepo${suffix}'
var package_container_name = 'packages'
// Define all existing resources
resource storageAccount 'Microsoft.Storage/storageAccounts@2023-01-01' existing = {
name: storage_account_name
}
resource defBlobServices 'Microsoft.Storage/storageAccounts/blobServices@2023-01-01' existing = {
parent: storageAccount
name: 'default'
}
resource packageContainer 'Microsoft.Storage/storageAccounts/blobServices/containers@2023-01-01' existing = {
parent: defBlobServices
name: package_container_name
}
resource functionApp 'Microsoft.Web/sites@2023-01-01' existing = {
name: appName
}
// Now create an event grid subscription so that when a blob is created,
// it triggers the function app
resource systemTopic 'Microsoft.EventGrid/systemTopics@2021-12-01' = {
name: 'blobscreated${suffix}'
location: location
properties: {
source: storageAccount.id
topicType: 'Microsoft.Storage.StorageAccounts'
}
}
// Construct the resource ID to use for the event subscription
var functionId = '${functionApp.id}/functions/eventGridTrigger'
resource eventSubscription 'Microsoft.EventGrid/systemTopics/eventSubscriptions@2023-12-15-preview' = {
parent: systemTopic
name: 'blobscreated${suffix}'
properties: {
destination: {
endpointType: 'AzureFunction'
properties: {
resourceId: functionId
maxEventsPerBatch: 1
}
}
filter: {
includedEventTypes: [
'Microsoft.Storage.BlobCreated'
]
// Filter in RPM files only
subjectBeginsWith: '/blobServices/default/containers/${packageContainer.name}/'
subjectEndsWith: '.rpm'
}
}
}