0

I am trying to add Diagnostic Settings for Machine Learning Online Deployments, which is a child of a given Machine Learning Online Endpoint, but since I have an array for each of these services, I am not being able to reference them.

This is my current working template:

@description('Subscription ID where the resources are located.')
param subscriptionId string

@description('Name of the resource group containing the resources.')
param resourceGroupName string

@description('The name of the existing Operational Insights (Log Analytics) workspace.')
param logWorkspaceName string

@description('The name of the existing Azure Machine Learning workspace.')
param machineLearningWorkspaceName string

@description('The name of the existing Azure Machine Learning Workspace Online Endpoints.')
param onlineEndpoints array

@description('Reference to the existing Operational Insights workspace.')
resource operationalInsightsWorkspace 'Microsoft.OperationalInsights/workspaces@2023-09-01' existing = {
  name: logWorkspaceName
  scope: resourceGroup(subscriptionId, resourceGroupName)
}

@description('Reference to the existing Azure Machine Learning Workspace resource.')
resource machineLearningWorkspace 'Microsoft.MachineLearningServices/workspaces@2024-10-01' existing = {
  name: machineLearningWorkspaceName
}

resource machineLearningWorkspaceOnlineEndpoints 'Microsoft.MachineLearningServices/workspaces/onlineEndpoints@2024-10-01' existing = [
  for onlineEndpoint in onlineEndpoints: {
    #disable-next-line use-parent-property
    name: '${machineLearningWorkspace.name}/${onlineEndpoint}'
  }
]

@description('Diagnostic settings for Machine Learning Workspace Online Endpoints')
resource diagnosticsOnlineEndpoints 'Microsoft.Insights/diagnosticSettings@2021-05-01-preview' = [
  for (onlineEndpoint, i) in onlineEndpoints: {
    name: '${onlineEndpoint}diag'
    scope: machineLearningWorkspaceOnlineEndpoints[i]
    properties: {
      logAnalyticsDestinationType: 'Dedicated'
      workspaceId: operationalInsightsWorkspace.id
      logs: [
        {
          category: null
          categoryGroup: 'allLogs'
          enabled: true
          retentionPolicy: {
            days: 0
            enabled: false
          }
        }
      ]
      metrics: [
        {
          category: 'Traffic'
          timeGrain: null
          enabled: true
          retentionPolicy: {
            days: 0
            enabled: false
          }
        }
      ]
    }
  }
]

I would like to create a new param called `param onlineDeployments array, but how can I create a resource definition for deployment if depends on online endpoints that is also an array?

If I try this I get an error:

resource machineLearningWorkspaceOnlineDeployments 'Microsoft.MachineLearningServices/workspaces/onlineEndpoints/deployments@2024-10-01' existing = [
  for onlineDeployment in onlineDeployments: {
    #disable-next-line use-parent-property
    name: '${machineLearningWorkspace.name}/${onlineEndpoint}/${onlineDeployment}'
  }
]

1 Answer 1

0

Diagnostic settings are not child resource of online endpoints and online deployments. They are extension resource that is available for different type of resources thus why they use scope rather parent for reference. Nevertheless what you are trying to achieve can be achieved by using modules. Here is modified file for your example + adding a module to achieve this. Note that I have changed the array structure of onlineDeployments array and you can see example in it. This is so you can achieve this. I do not know the available logs and metrics for online deployments so please adjust those accordingly.

main.bicep

@description('Subscription ID where the resources are located.')
param subscriptionId string

@description('Name of the resource group containing the resources.')
param resourceGroupName string

@description('The name of the existing Operational Insights (Log Analytics) workspace.')
param logWorkspaceName string

@description('The name of the existing Azure Machine Learning workspace.')
param machineLearningWorkspaceName string

@description('The name of the existing Azure Machine Learning Workspace Online Endpoints.')
param onlineEndpoints array = [
  {
    name: 'onlineEndpoint1'
    onlineDeployments: [
      'onlineDeployment1'
    ]
  }
  {
    name: 'onlineEndpoint2'
    onlineDeployments: [
      'onlineDeployment2'
    ]
  }
]

@description('Reference to the existing Operational Insights workspace.')
resource operationalInsightsWorkspace 'Microsoft.OperationalInsights/workspaces@2023-09-01' existing = {
  name: logWorkspaceName
  scope: resourceGroup(subscriptionId, resourceGroupName)
}

@description('Reference to the existing Azure Machine Learning Workspace resource.')
resource machineLearningWorkspace 'Microsoft.MachineLearningServices/workspaces@2024-10-01' existing = {
  name: machineLearningWorkspaceName
}

resource machineLearningWorkspaceOnlineEndpoints 'Microsoft.MachineLearningServices/workspaces/onlineEndpoints@2024-10-01' existing = [
  for onlineEndpoint in onlineEndpoints: {
    #disable-next-line use-parent-property
    name: '${machineLearningWorkspace.name}/${onlineEndpoint.name}'
  }
]

module onlineDeployments 'online-deployments.bicep' = [for (onlineEndpoint, i) in onlineEndpoints: {
  name: '${onlineEndpoint}Deployments'
  params: {
    onlineEndpoint: onlineEndpoint.name
    onlineDeployments: onlineEndpoint.onlineDeployments
    machineLearningWorkspaceName: machineLearningWorkspaceName
    logWorkspaceName: logWorkspaceName
    resourceGroupName: resourceGroupName
    subscriptionId: subscriptionId
  }
}]

@description('Diagnostic settings for Machine Learning Workspace Online Endpoints')
resource diagnosticsOnlineEndpoints 'Microsoft.Insights/diagnosticSettings@2021-05-01-preview' = [
  for (onlineEndpoint, i) in onlineEndpoints: {
    name: '${onlineEndpoint.name}diag'
    scope: machineLearningWorkspaceOnlineEndpoints[i]
    properties: {
      logAnalyticsDestinationType: 'Dedicated'
      workspaceId: operationalInsightsWorkspace.id
      logs: [
        {
          category: null
          categoryGroup: 'allLogs'
          enabled: true
          retentionPolicy: {
            days: 0
            enabled: false
          }
        }
      ]
      metrics: [
        {
          category: 'Traffic'
          timeGrain: null
          enabled: true
          retentionPolicy: {
            days: 0
            enabled: false
          }
        }
      ]
    }
  }
]

online-deployments.bicep

param onlineEndpoint string
param machineLearningWorkspaceName string
param logWorkspaceName string
param resourceGroupName string
param subscriptionId string
param onlineDeployments array

resource operationalInsightsWorkspace 'Microsoft.OperationalInsights/workspaces@2023-09-01' existing = {
  name: logWorkspaceName
  scope: resourceGroup(subscriptionId, resourceGroupName)
}

resource machineLearningWorkspace 'Microsoft.MachineLearningServices/workspaces@2024-10-01' existing = {
  name: machineLearningWorkspaceName
}

resource machineLearningWorkspaceOnlineEndpoints 'Microsoft.MachineLearningServices/workspaces/onlineEndpoints@2024-10-01' existing = {
  name: onlineEndpoint
  parent: machineLearningWorkspace
}

resource onlineDeploymentsRes 'Microsoft.MachineLearningServices/workspaces/onlineEndpoints/deployments@2024-10-01' existing = [for onlineDeployment in onlineDeployments: {
  name: onlineDeployment
  parent: machineLearningWorkspaceOnlineEndpoints
}]

resource diagnosticsOnlineEndpoints 'Microsoft.Insights/diagnosticSettings@2021-05-01-preview' = [for (onlineDeployment, i) in onlineDeployments: {
  name: '${onlineDeployments}diag'
  scope: onlineDeploymentsRes[i]
  properties: {
    logAnalyticsDestinationType: 'Dedicated'
    workspaceId: operationalInsightsWorkspace.id
    logs: [
      {
        category: null
        categoryGroup: 'allLogs'
        enabled: true
        retentionPolicy: {
          days: 0
          enabled: false
        }
      }
    ]
    metrics: [
      {
        category: 'Traffic'
        timeGrain: null
        enabled: true
        retentionPolicy: {
          days: 0
          enabled: false
        }
      }
    ]
  }
}]

Sign up to request clarification or add additional context in comments.

3 Comments

I might have used a wrong example here regarding child, that's true. Soon I will create a MLW Model -> Model Version -> Online Endpoint Deployment, so I thought I could use the same example. But is it possible to achieve not using module (just out of curiosity)? Also, in your online-deployments.bicep, don't we need to reference the parent[i] in onlineDeploymentsRes? Because we also have a list of machineLearningWorkspaceOnlineEndpoints.
It is not possible without using modules. Reference to parent is not required only if the resource does not have parent. Microsoft.MachineLearningServices/workspaces is resource without parent. Microsoft.MachineLearningServices/workspaces/onlineEndpoints has parent Microsoft.MachineLearningServices/workspaces. Microsoft.MachineLearningServices/workspaces has parent Microsoft.MachineLearningServices/workspaces/onlineEndpoints. Using parent is the recommend way to define existing resources that have parents (are child resources).
You could just define the last resource without parent but that would mean you have to define the names of the parent resources in the resource name ``` name: 'machineLearningWorkspaceName/${onlineEndpoint}/${onlineDeployment}' ```

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.