Skip to content

[Hub apps] Create the hub-event-trigger module for creating ADF triggers #1493

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs-mslearn/toolkit/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ The following section lists features and enhancements that are currently in deve
- Created a new bicep modules to support extensibility:
- The **hub-app** module tracks telemetry when an app is deployed.
- The **hub-storage** module creates containers in the hub storage account.
- The **hub-event-trigger** module creates a trigger in the hub Data Factory instance.
- The **hub-vault** module adds secrets to the hub vault.

**Fixed**
Expand Down
121 changes: 47 additions & 74 deletions src/templates/finops-hub/modules/dataFactory.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ resource stopTriggers 'Microsoft.Resources/deploymentScripts@2020-10-01' = {
//------------------------------------------------------------------------------

// cSpell:ignore linkedservices
// TODO: Move to the hub-app module
resource linkedService_keyVault 'Microsoft.DataFactory/factories/linkedservices@2018-06-01' = if (!empty(remoteHubStorageUri)) {
name: keyVault.name
parent: dataFactory
Expand All @@ -443,6 +444,7 @@ resource linkedService_keyVault 'Microsoft.DataFactory/factories/linkedservices@
}
}

// TODO: Move to the hub-app module
resource linkedService_storageAccount 'Microsoft.DataFactory/factories/linkedservices@2018-06-01' = {
name: storageAccount.name
parent: dataFactory
Expand Down Expand Up @@ -812,97 +814,68 @@ resource dataset_ftkReleaseFile 'Microsoft.DataFactory/factories/datasets@2018-0
// Triggers
//------------------------------------------------------------------------------

resource trigger_ExportManifestAdded 'Microsoft.DataFactory/factories/triggers@2018-06-01' = {
name: exportManifestAddedTriggerName
parent: dataFactory
// TODO: Create apps_PublishEvent pipeline { event, properties }

module trigger_ExportManifestAdded 'hub-event-trigger.bicep' = {
name: 'trigger_ExportManifestAdded'
dependsOn: [
stopTriggers
]
properties: {
annotations: []
pipelines: [
{
pipelineReference: {
referenceName: pipeline_ExecuteExportsETL.name
type: 'PipelineReference'
}
parameters: {
folderPath: '@triggerBody().folderPath'
fileName: '@triggerBody().fileName'
}
}
]
type: 'BlobEventsTrigger'
typeProperties: {
blobPathBeginsWith: '/${exportContainerName}/blobs/'
blobPathEndsWith: 'manifest.json'
ignoreEmptyBlobs: true
scope: storageAccount.id
events: [
'Microsoft.Storage.BlobCreated'
]
params: {
dataFactoryName: dataFactory.name
triggerName: exportManifestAddedTriggerName

// TODO: Replace pipeline with event: 'Microsoft.FinOpsToolkit.CostManagement.ExportManifestAdded'
pipelineName: pipeline_ExecuteExportsETL.name
pipelineParameters: {
folderPath: '@triggerBody().folderPath'
fileName: '@triggerBody().fileName'
}

storageAccountName: storageAccount.name
storageContainer: exportContainerName
storagePathEndsWith: 'manifest.json'
}
}

resource trigger_IngestionManifestAdded 'Microsoft.DataFactory/factories/triggers@2018-06-01' = if (deployDataExplorer) {
name: ingestionManifestAddedTriggerName
parent: dataFactory
module trigger_IngestionManifestAdded 'hub-event-trigger.bicep' = {
name: 'trigger_IngestionManifestAdded'
dependsOn: [
stopTriggers
]
properties: {
annotations: []
pipelines: [
{
pipelineReference: {
referenceName: pipeline_ExecuteIngestionETL.name
type: 'PipelineReference'
}
parameters: {
folderPath: '@triggerBody().folderPath'
}
}
]
type: 'BlobEventsTrigger'
typeProperties: {
blobPathBeginsWith: '/${ingestionContainerName}/blobs/'
blobPathEndsWith: 'manifest.json'
ignoreEmptyBlobs: true
scope: storageAccount.id
events: [
'Microsoft.Storage.BlobCreated'
]
params: {
dataFactoryName: dataFactory.name
triggerName: ingestionManifestAddedTriggerName

// TODO: Replace pipeline with event: 'Microsoft.FinOpsToolkit.Hubs.IngestionManifestAdded'
pipelineName: pipeline_ExecuteIngestionETL.name
pipelineParameters: {
folderPath: '@triggerBody().folderPath'
}

storageAccountName: storageAccount.name
storageContainer: ingestionContainerName
storagePathEndsWith: 'manifest.json'
}
}

resource trigger_SettingsUpdated 'Microsoft.DataFactory/factories/triggers@2018-06-01' = {
name: updateConfigTriggerName
parent: dataFactory
module trigger_SettingsUpdated 'hub-event-trigger.bicep' = {
name: 'trigger_SettingsUpdated'
dependsOn: [
stopTriggers
]
properties: {
annotations: []
pipelines: [
{
pipelineReference: {
referenceName: pipeline_ConfigureExports.name
type: 'PipelineReference'
}
}
]
type: 'BlobEventsTrigger'
typeProperties: {
blobPathBeginsWith: '/${configContainerName}/blobs/'
blobPathEndsWith: 'settings.json'
ignoreEmptyBlobs: true
scope: storageAccount.id
events: [
'Microsoft.Storage.BlobCreated'
]
}
params: {
dataFactoryName: dataFactory.name
triggerName: updateConfigTriggerName

// TODO: Replace pipeline with event: 'Microsoft.FinOpsToolkit.Hubs.SettingsUpdated'
pipelineName: pipeline_ConfigureExports.name
pipelineParameters: {}

storageAccountName: storageAccount.name
storageContainer: configContainerName
// TODO: Change this to startswith
storagePathEndsWith: 'settings.json'
}
}

Expand Down
95 changes: 95 additions & 0 deletions src/templates/finops-hub/modules/hub-event-trigger.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

//==============================================================================
// Parameters
//==============================================================================

@description('Required. Name of the publisher-specific Data Factory instance.')
param dataFactoryName string

@description('Required. Name of the Data Factory trigger to create or update.')
param triggerName string

// Storage details
@description('Optional. Azure storage container to monitor for updates and trigger events for.')
param storageAccountName string = ''
@description('Optional. Azure storage container to monitor for updates and trigger events for.')
param storageContainer string = ''
@description('Optional. Beginning of the storage path within the specified storageContainer to monitor for updates and trigger events for.')
param storagePathStartsWith string = ''
@description('Optional. End of the storage path to monitor for updates and trigger events for.')
param storagePathEndsWith string = ''

// Target pipeline details
@description('Required. Name of the Data Factory pipeline to execute when the trigger is executed.')
param pipelineName string
@description('Required. Parameters to pass to the pipeline when the trigger is executed.')
param pipelineParameters object
// @description('Required. Fully-qualified identifier of the event to publish.')
// param event string


//==============================================================================
// Resources
//==============================================================================

//------------------------------------------------------------------------------
// Get references to existing resources
//------------------------------------------------------------------------------

resource storageAccount 'Microsoft.Storage/storageAccounts@2024-01-01' existing = {
name: storageAccountName
}

//------------------------------------------------------------------------------
// Create trigger
//------------------------------------------------------------------------------

resource dataFactory 'Microsoft.DataFactory/factories@2018-06-01' existing = {
name: dataFactoryName

resource storageTrigger 'triggers' = if (!empty(storageAccountName)) {
name: triggerName
properties: {
annotations: []
pipelines: [
{
// TODO: Replace with apps_PublishEvent pipeline when event publishing is enabled
pipelineReference: {
referenceName: pipelineName
type: 'PipelineReference'
}
parameters: pipelineParameters

// pipelineReference: {
// referenceName: 'apps_PublishEvent'
// type: 'PipelineReference'
// }
// parameters: {
// event: event
// properties: '@triggerBody()' // pass all trigger properties to the pipeline
// }
}
]
type: 'BlobEventsTrigger'
typeProperties: {
blobPathBeginsWith: '/${storageContainer}/blobs/${storagePathStartsWith}'
blobPathEndsWith: storagePathEndsWith
ignoreEmptyBlobs: true
scope: storageAccount.id
events: [
'Microsoft.Storage.BlobCreated'
]
}
}
}
}


//==============================================================================
// Outputs
//==============================================================================

// @description('Fully-qualified event that is triggered when the configured event occurs.')
// output event string = event