0

I have the following bicep to create ADF resource:

resource dataFactory 'Microsoft.DataFactory/factories@2018-06-01' = {
  name: name
  identity: {
    type: 'SystemAssigned'
  }
  properties: {
    globalParameters: {
      environment: {
        type: 'String'
        value: environmentAbbreviation
      }
    }
  }
  location: location
}

I need to add a diagnostic setting to ADF resource as follows:

enter image description here

How do I update the bicep?

user989988
  • 3,006
  • 7
  • 44
  • 91

1 Answers1

0

I tried to create diagnostic settings in ADF using Bicep. Below is the code.

Bicep code for creating data factory

  • This code is for creating data factory. It is same as the code in question.
param settingName string='XXXXX'
param factoryName string='XXXXX'
resource datafactory 'Microsoft.DataFactory/factories@2018-06-01' = {
  name: factoryName
  location: resourceGroup().location
  identity: {
    type: 'SystemAssigned'
  }
  properties: {
  }
}

Bicep code for adding diagnostic setting

  • In order to add diagnostic setting to data factory, below code is added along with the code to create data factory.
resource factoryName_microsoft_insights_settingName 'Microsoft.DataFactory/factories/providers/diagnosticSettings@2017-05-01-preview' = {
  name: '${factoryName}/microsoft.insights/${settingName}'
  location: resourceGroup().location
  properties: {
    workspaceId: 'XXXX'
    logAnalyticsDestinationType: 'Dedicated'
    logs: [
      {
        category: 'PipelineRuns'
        enabled: true
        retentionPolicy: {
          enabled: false
          days: 0
        }
      }
      {
        category: 'TriggerRuns'
        enabled: true
        retentionPolicy: {
          enabled: false
          days: 0
        }
      }
      {
        category: 'ActivityRuns'
        enabled: true
        retentionPolicy: {
          enabled: false
          days: 0
        }
      }
    ]
    metrics: [
      {
        category: 'AllMetrics'
        timeGrain: 'PT1M'
        enabled: true
        retentionPolicy: {
          enabled: false
          days: 0
        }
      }
    ]
  }
  dependsOn: [
    datafactory
  ]
}
  • When the above both codes are combined and run, resources got deployed successfully. enter image description here

  • The above code will enable the categories - Pipeline runs log,Trigger runs log, Pipeline activity runs log. Change the code as per the requirement. enter image description here

Reference: Microsoft.Insights/diagnosticSettings - Bicep, ARM template & Terraform AzAPI reference | Microsoft Learn

Aswin
  • 4,090
  • 2
  • 4
  • 16
  • Thank you! How do I set destination table to Azure Diagnostics? – user989988 Feb 18 '23 at 16:11
  • If you want to archive in storage account, you need to use `storageAccountId: 'XXX'` in properties. Refer the [link1](https://learn.microsoft.com/en-us/azure/templates/microsoft.insights/diagnosticsettings?pivots=deployment-language-bicep). This [link2](https://learn.microsoft.com/en-us/azure/azure-monitor/essentials/resource-manager-diagnostic-settings?tabs=bicep#diagnostic-setting-for-azure-sql-database) has sample codes. – Aswin Feb 18 '23 at 16:41
  • Sorry my question is logAnalyticsDestinationType: 'Dedicated' this sets to 'Resource Specific' how do I set it to 'Azure Diagnostics'? – user989988 Feb 23 '23 at 00:47
  • Use `logAnalyticsDestinationType: 'AzureDiagnostics'` instead of `logAnalyticsDestinationType: 'Dedicated'` – Aswin Feb 23 '23 at 01:41
  • Thanks can you please answer https://stackoverflow.com/questions/75479291/log-the-status-of-the-adf-azure-data-factory-pipeline-run – user989988 Feb 23 '23 at 16:40
  • It is answered already? – Aswin Feb 23 '23 at 16:43
  • I tried the solution above. I keep getting error: The resource type '/' does not support diagnostic settings. I gave the workspaceId as resourceId('microsoft.operationalinsights/workspaces',) what am I missing? – user989988 Feb 23 '23 at 23:38
  • 1
    The full ARM resource ID of the Log Analytics workspace to which you would like to send Diagnostic Logs. – Aswin Feb 24 '23 at 01:35
  • 1
    Example: /subscriptions/4b9e8510-67ab-4e9a-95a9-e2f1e570ea9c/resourceGroups/insights-integration/providers/Microsoft.OperationalInsights/workspaces/viruela2 – Aswin Feb 24 '23 at 01:35
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/252095/discussion-between-aswin-and-user989988). – Aswin Feb 24 '23 at 01:42