Skip to content

Commit

Permalink
Upgrading bicep templates #886
Browse files Browse the repository at this point in the history
  • Loading branch information
raafatzarka committed Dec 16, 2024
1 parent 1440dc5 commit b69ffee
Show file tree
Hide file tree
Showing 12 changed files with 249 additions and 122 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
//https://learn.microsoft.com/en-us/azure/templates/microsoft.insights/actiongroups
// Parameters
@description('The project name.')
param project string
@description('The environment for the deployment.')
@allowed([
'dev'
'stg'
'prod'
])
param env string
@description('The unique identifier for this deployment.')
param deployment_id string
@description('The email address for the alert action group.')
param email_id string

resource actiongroup 'Microsoft.Insights/actionGroups@2021-09-01' = {
// Resource: Action Group
resource actiongroup 'Microsoft.Insights/actionGroups@2024-10-01-preview' = {
name: '${project}-emailactiongroup-${env}-${deployment_id}'
location: 'global'
tags: {
DisplayName: 'Action Group'
Environment: env
Project: project
DeploymentId: deployment_id
}
identity: {
type: 'SystemAssigned' // Optional: Adjust based on your managed identity requirements
}
properties: {
groupShortName: 'emailgroup'
Expand All @@ -25,7 +36,9 @@ resource actiongroup 'Microsoft.Insights/actionGroups@2021-09-01' = {
}
]
enabled: true
// Additional receivers can be added here if needed
}
}

// Outputs
@description('The ID of the created action group.')
output actiongroup_id string = actiongroup.id
62 changes: 39 additions & 23 deletions e2e_samples/parking_sensors/infrastructure/modules/alerts.bicep
Original file line number Diff line number Diff line change
@@ -1,52 +1,68 @@
//https://learn.microsoft.com/en-us/azure/templates/microsoft.insights/metricalerts?pivots=deployment-language-bicep
// Parameters
@description('The project name.')
param project string
@description('The environment for the deployment.')
@allowed([
'dev'
'stg'
'prod'
])
param env string
@description('The location of the resource.')
param location string = resourceGroup().location
@description('The unique identifier for this deployment.')
param deployment_id string
@description('The name of the Data Factory.')
param datafactory_name string
@description('The ID of the action group.')
param action_group_id string

// Resource: Metric Alert
resource adpipelinefailed 'Microsoft.Insights/metricAlerts@2018-03-01' = {
name: '${project}-adffailedalert-${env}-${deployment_id}'
location: 'global'
tags: {
DisplayName: 'ADF Pipeline Failed'
Environment: env
Project: project
DeploymentId: deployment_id
}
properties: {
actions: [
{
actionGroupId: action_group_id
}
description: 'ADF pipeline failed'
enabled: true
severity: 1
evaluationFrequency: 'PT1M'
windowSize: 'PT5M'
scopes: [
'${subscription().id}/resourceGroups/${resourceGroup().name}/providers/Microsoft.DataFactory/factories/${datafactory_name}'
]
autoMitigate: false
targetResourceType: 'Microsoft.DataFactory/factories'
targetResourceRegion: location
criteria: {
'odata.type': 'Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria'
allOf: [
{
threshold : 1
name : 'Metric1'
metricNamespace: 'Microsoft.DataFactory/factories'
metricName: 'PipelineFailedRuns'
operator: 'GreaterThan'
timeAggregation: 'Total'
criterionType: 'StaticThresholdCriterion'
name: 'PipelineFailedRunsCriteria'
metricName: 'PipelineFailedRuns'
metricNamespace: 'Microsoft.DataFactory/factories'
operator: 'GreaterThan'
threshold: 1
timeAggregation: 'Total'
criterionType: 'StaticThresholdCriterion'
}
]
]
}
description: 'ADF pipeline failed'
enabled: true
evaluationFrequency: 'PT1M'
scopes: [
'${subscription().id}/resourceGroups/${resourceGroup().name}/providers/Microsoft.DataFactory/factories/${datafactory_name}'
actions: [
{
actionGroupId: action_group_id
webHookProperties: {
exampleProperty: 'exampleValue'
}
}
]
severity: 1
targetResourceRegion: location
targetResourceType: 'Microsoft.DataFactory/factories'
windowSize: 'PT5M'
autoMitigate: false
}
}
// Outputs
@description('The ID of the created metric alert.')
output adpipelinefailed_id string = adpipelinefailed.id
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
//https://learn.microsoft.com/en-us/azure/templates/microsoft.insights/components
// Parameters
@description('The project name.')
param project string
@description('The environment for the deployment.')
@allowed([
'dev'
'stg'
'prod'
])
param env string
@description('The location of the resource.')
param location string = resourceGroup().location
@description('The unique identifier for this deployment.')
param deployment_id string


resource appinsights 'Microsoft.Insights/components@2020-02-02-preview' = {
// Resource: Application Insights
resource appinsights 'Microsoft.Insights/components@2020-02-02' = {
name: '${project}-appi-${env}-${deployment_id}'
location: location
tags: {
DisplayName: 'Application Insights'
Environment: env
Project: project
DeploymentId: deployment_id
}
kind: 'other'
properties: {
Application_Type: 'other'
}
}

// Output: Application Insights Name
@description('The name of the created Application Insights resource.')
output appinsights_name string = appinsights.name
15 changes: 13 additions & 2 deletions e2e_samples/parking_sensors/infrastructure/modules/dashboard.bicep
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
//https://learn.microsoft.com/en-us/azure/templates/microsoft.portal/dashboards
// Parameters
@description('The project name.')
param project string
@description('The environment for the deployment.')
@allowed([
'dev'
'stg'
'prod'
])
param env string
@description('The location of the resource.')
param location string = resourceGroup().location
@description('The unique identifier for this deployment.')
param deployment_id string
@description('The name of the Data Factory.')
param datafactory_name string
@description('The name of the SQL server.')
param sql_server_name string
@description('The name of the SQL database.')
param sql_database_name string

resource dashboard 'Microsoft.Portal/dashboards@2020-09-01-preview' = {
// Resource: Azure Portal Dashboard
resource dashboard 'Microsoft.Portal/dashboards@2022-12-01-preview' = {
name: '${project}-dashboard-${env}-${deployment_id}'
location: location
tags: {
DisplayName: 'Azure Dashboard'
Environment: env
Project: project
DeploymentId: deployment_id
}
properties: {
lenses: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
//https://learn.microsoft.com/en-us/azure/templates/microsoft.insights/workbooks
// Parameters
@description('The display name of the workbook.')
param workbookDisplayName string = 'DQ Report'
@description('The category/type of the workbook.')
param workbookType string = 'workbook'
@description('The name of the Application Insights resource.')
param appinsights_name string
@description('The location of the resource.')
param location string = resourceGroup().location
// Variables
var workbookSourceId = subscriptionResourceId('microsoft.insights/components', '${appinsights_name}')
var workbookId = guid(workbookSourceId)
var serializedData = '{"version":"Notebook/1.0","items":[{"type":3,"content":{"version":"KqlItem/1.0","query":"traces\\r\\n| where message==\\"verifychecks\\"\\r\\n| where customDimensions.check_name==\\"Parkingbay Data DQ\\" or customDimensions.check_name==\\"Transformed Data\\" \\r\\n| where severityLevel==\\"1\\" or severityLevel==\\"3\\"\\r\\n| where notempty(customDimensions.pipelinerunid)\\r\\n| project Status = iif(severityLevel==\\"1\\", \\"success\\", \\"failed\\"),CheckName=customDimensions.check_name,RunID = customDimensions.pipelinerunid, Details=customDimensions,Timestamp=timestamp","size":0,"aggregation":3,"timeContext":{"durationMs":604800000},"queryType":0,"resourceType":"microsoft.insights/components","visualization":"table","gridSettings":{"formatters":[{"columnMatch":"Status","formatter":11},{"columnMatch":"status","formatter":11}]}},"name":"query - 0"},{"type":3,"content":{"version":"KqlItem/1.0","query":"traces\\r\\n| where message==\\"verifychecks\\"\\r\\n| where customDimensions.check_name==\\"DQ checks\\"\\r\\n| where severityLevel==\\"1\\" or severityLevel==\\"3\\"\\r\\n| where notempty(customDimensions.pipelinerunid)\\r\\n| project Status = iif(severityLevel==\\"1\\", \\"Success\\", \\"Failed\\"),CheckName=customDimensions.check_name,RunID = customDimensions.pipelinerunid, Details=customDimensions,Timestamp=timestamp\\r\\n| summarize count() by Status \\r\\n| render piechart","size":0,"timeContext":{"durationMs":604800000},"queryType":0,"resourceType":"microsoft.insights/components","visualization":"piechart","tileSettings":{"showBorder":false,"titleContent":{"columnMatch":"Status","formatter":1},"leftContent":{"columnMatch":"count_","formatter":12,"formatOptions":{"palette":"auto"},"numberFormat":{"unit":17,"options":{"maximumSignificantDigits":3,"maximumFractionDigits":2}}}},"graphSettings":{"type":0,"topContent":{"columnMatch":"Status","formatter":1},"centerContent":{"columnMatch":"count_","formatter":1,"numberFormat":{"unit":17,"options":{"maximumSignificantDigits":3,"maximumFractionDigits":2}}}},"chartSettings":{"seriesLabelSettings":[{"seriesName":"success","label":"","color":"greenDark"},{"seriesName":"failed","color":"red"}]},"mapSettings":{"locInfo":"LatLong","sizeSettings":"count_","sizeAggregation":"Sum","legendMetric":"count_","legendAggregation":"Sum","itemColorSettings":{"type":"heatmap","colorAggregation":"Sum","nodeColorField":"count_","heatmapPalette":"greenRed"}}},"name":"query - 1"}],"fallbackResourceIds":["/subscriptions/XXX-XXX-XXX-XX-XXX/resourceGroups/XXXX/providers/microsoft.insights/components/XXXX"],"$schema":"https://github.com/Microsoft/Application-Insights-Workbooks/blob/master/schema/workbook.json"}'
Expand All @@ -14,8 +21,8 @@ var updatedWorkbookData = {
]
}
var reserializedData = string(updatedWorkbookData)

resource data_quality_workbook_resource 'microsoft.insights/workbooks@2022-04-01' = {
// Resource: Data Quality Workbook
resource data_quality_workbook_resource 'microsoft.insights/workbooks@2023-06-01' = {
name: workbookId
location: location
kind: 'shared'
Expand All @@ -25,8 +32,18 @@ resource data_quality_workbook_resource 'microsoft.insights/workbooks@2022-04-01
version: '1.0'
sourceId: workbookSourceId
category: workbookType
description: 'Data Quality Report Workbook'
tags: [
'DataQuality'
'Monitoring'
]
}
tags: {
Environment: 'Production'
Project: 'DataQualityMonitoring'
}
dependsOn: []
}

// Output: Workbook ID
@description('The ID of the created workbook resource.')
output workbookId string = data_quality_workbook_resource.id
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
//https://learn.microsoft.com/en-us/azure/templates/microsoft.databricks/workspaces
//https://learn.microsoft.com/en-us/azure/templates/microsoft.authorization/roleassignments
//Parameters
@description('The project name.')
param project string
@description('The environment for the deployment.')
@allowed([
'dev'
'stg'
'prod'
])
param env string
@description('The location of the resource.')
param location string = resourceGroup().location
@description('The unique identifier for this deployment.')
param deployment_id string
@description('The principal ID of the contributor.')
param contributor_principal_id string

//https://docs.microsoft.com/en-us/azure/role-based-access-control/built-in-roles
// Variables
@description('Role definition ID for Contributor.')
var contributor = subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'b24988ac-6180-42a0-ab88-20f7382dd24c')

resource databricks 'Microsoft.Databricks/workspaces@2018-04-01' = {
// Databricks Workspace Resource
resource databricks 'Microsoft.Databricks/workspaces@2024-09-01-preview' = {
name: '${project}-dbw-${env}-${deployment_id}'
location: location
tags: {
Expand All @@ -21,22 +29,27 @@ resource databricks 'Microsoft.Databricks/workspaces@2018-04-01' = {
}
sku: {
name: 'premium'
tier: 'Premium'
}
properties: {
managedResourceGroupId: subscriptionResourceId('Microsoft.Resources/resourceGroups', '${project}-${deployment_id}-dbw-${env}-rg')
}
}

resource databricks_roleassignment 'Microsoft.Authorization/roleAssignments@2020-08-01-preview' = {
// Role Assignment Resource
resource databricks_roleassignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
name: guid(databricks.id)
scope: databricks
properties: {
roleDefinitionId: contributor
principalId: contributor_principal_id
principalType: 'ServicePrincipal'
description: 'Contributor access for Databricks workspace.'
}
}

// Outputs
@description('Databricks workspace details.')
output databricks_output object = databricks
@description('Databricks workspace ID.')
output databricks_id string = databricks.id
@description('Databricks workspace URL.')
output databricks_workspace_url string = databricks.properties.workspaceUrl
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
//https://learn.microsoft.com/en-us/azure/templates/microsoft.datafactory/factories
// Parameters
@description('The project name.')
param project string
@description('The environment for the deployment.')
@allowed([
'dev'
'stg'
'prod'
])
param env string
@description('The location of the resource.')
param location string = resourceGroup().location
@description('The unique identifier for this deployment.')
param deployment_id string

// param account_name string = ''
// param repository_name string = ''
// param collaboration_branch string = 'main'
// param root_folder string = '/e2e_samples/parking_sensors/adf'

// Data Factory Resource
resource datafactory 'Microsoft.DataFactory/factories@2018-06-01' = {
name: '${project}-adf-${env}-${deployment_id}'
location: location
Expand All @@ -24,29 +25,9 @@ resource datafactory 'Microsoft.DataFactory/factories@2018-06-01' = {
type: 'SystemAssigned'
}
}

// resource datafactory 'Microsoft.DataFactory/factories@2018-06-01' = if (env == 'dev') {
// name: adf_name
// location: location
// tags: {
// DisplayName: 'Data Factory'
// Environment: env
// }
// identity: {
// type: 'SystemAssigned'
// }
// properties: {
// repoConfiguration: {
// accountName: account_name
// repositoryName: repository_name
// collaborationBranch: collaboration_branch
// rootFolder: root_folder
// type: 'FactoryGitHubConfiguration'
// }
// }
// }


// Outputs
@description('The principal ID of the Data Factory identity.')
output datafactory_principal_id string = datafactory.identity.principalId
output datafactory_id string = datafactory.id
@description('The name of the Data Factory.')
output datafactory_name string = datafactory.name
Loading

0 comments on commit b69ffee

Please sign in to comment.