Azure / Azure/Azure-Verified-Modules

[Module Proposal]: `Data Collection Rule Association`

Open
#2,884 0 comments 0 reactions 0 assignees View on GitHub
Needs: Triage :mag: Type: New Module Proposal :bulb:
Dominant language
PowerShell
Stars
580
Forks
161
Avg merge
11h 3m
Merged PRs (30d)
15

Description

### Check for previous/existing GitHub issues/module proposals

- [x] I have checked for previous/existing GitHub issues/module proposals.

### Check this module doesn't already exist in the module indexes

- [x] I have checked for that this module doesn't already exist in the module indexes.

### Bicep or Terraform?

Bicep

### Module Classification?

Resource Module

### Module Name

Data Collection Rule Association

### Module Details

Please create a new AVM module for Microsoft.Insights/dataCollectionRuleAssociations, based on the below main.bicep implementation. (I have tested this module myself with the e2e test and it does work, feel free to reuse)

```
targetScope = 'resourceGroup'

metadata name = 'Data Collection Rule Association'
metadata description = 'This module deploys a Data Collection Rule Association (DCRA) and/or Data Collection Endpoint Association as extension resource(s) of a supported target resource.'

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

@description('Required. The name of the Data Collection Rule Association.')
param name string

@description('Required. The type of the resource to which the association is deployed.')
@allowed([
'Microsoft.ContainerService/managedClusters'
'Microsoft.Compute/virtualMachines'
'Microsoft.HybridCompute/machines'
])
param targetResourceType string

@description('Required. The name of the resource to which the association is deployed. The resource must exist in the deployment resource group.')
param targetResourceName string

@description('Optional. Resource ID of the Data Collection Rule to associate with the target resource.')
param dataCollectionRuleId string?

@description('Optional. Resource ID of the Data Collection Endpoint to associate with the target resource.')
param dataCollectionEndpointId string?

@description('Optional. Description of the Data Collection Rule Association.')
param dataCollectionRuleAssociationDescription string?

@description('Optional. Enable or disable usage telemetry for the module.')
param enableTelemetry bool = false

// ============= //
// Variables //
// ============= //

var normalizedTargetResourceType = toLower(targetResourceType)

#disable-next-line no-deployments-resources
resource avmTelemetry 'Microsoft.Resources/deployments@2024-07-01' = if (enableTelemetry) {
name: take(
'46d3xbcp.res.insights-dcra.${replace('-..--..-', '.', '-')}.${substring(uniqueString(deployment().name), 0, 4)}',
64
)
properties: {
mode: 'Incremental'
template: {
'$schema': 'https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#'
contentVersion: '1.0.0.0'
resources: []
outputs: {
telemetry: {
type: 'String'
value: 'For more information, see https://aka.ms/avm/TelemetryInfo'
}
}
}
}
}

// =============== //
// Deployments //
// =============== //

// Target resource references
resource aksTarget 'Microsoft.ContainerService/managedClusters@2023-08-01' existing = if (normalizedTargetResourceType == 'microsoft.containerservice/managedclusters') {
name: targetResourceName
}

resource vmTarget 'Microsoft.Compute/virtualMachines@2023-09-01' existing = if (normalizedTargetResourceType == 'microsoft.compute/virtualmachines') {
name: targetResourceName
}

#disable-next-line BCP081
resource arcTarget 'Microsoft.HybridCompute/machines@2022-12-27' existing = if (normalizedTargetResourceType == 'microsoft.hybridcompute/machines') {
name: targetResourceName
}

// --------------------------------------------------------------------------------
// Data Collection Endpoint (DCE) Associations
// Azure requires DCE associations to be named 'configurationAccessEndpoint'
// and contain ONLY dataCollectionEndpointId.
// --------------------------------------------------------------------------------
resource dcraAksDce 'Microsoft.Insights/dataCollectionRuleAssociations@2023-03-11' = if (normalizedTargetResourceType == 'microsoft.containerservice/managedclusters' && !empty(dataCollectionEndpointId)) {
name: 'configurationAccessEndpoint'
scope: aksTarget
properties: {
dataCollectionEndpointId: dataCollectionEndpointId
description: dataCollectionRuleAssociationDescription
}
}

resource dcraVmDce 'Microsoft.Insights/dataCollectionRuleAssociations@2023-03-11' = if (normalizedTargetResourceType == 'microsoft.compute/virtualmachines' && !empty(dataCollectionEndpointId)) {
name: 'configurationAccessEndpoint'
scope: vmTarget
properties: {
dataCollectionEndpointId: dataCollectionEndpointId
description: dataCollectionRuleAssociationDescription
}
}

resource dcraArcDce 'Microsoft.Insights/dataCollectionRuleAssociations@2023-03-11' = if (normalizedTargetResourceType == 'microsoft.hybridcompute/machines' && !empty(dataCollectionEndpointId)) {
name: 'configurationAccessEndpoint'
scope: arcTarget
properties: {
dataCollectionEndpointId: dataCollectionEndpointId
description: dataCollectionRuleAssociationDescription
}
}

// --------------------------------------------------------------------------------
// Data Collection Rule (DCR) Associations
// Uses parameter 'name' and contains ONLY dataCollectionRuleId.
// --------------------------------------------------------------------------------
resource dcraAksDcr 'Microsoft.Insights/dataCollectionRuleAssociations@2023-03-11' = if (normalizedTargetResourceType == 'microsoft.containerservice/managedclusters' && !empty(dataCollectionRuleId)) {
name: name
scope: aksTarget
properties: {
dataCollectionRuleId: dataCollectionRuleId
description: dataCollectionRuleAssociationDescription
}
}

resource dcraVmDcr 'Microsoft.Insights/dataCollectionRuleAssociations@2023-03-11' = if (normalizedTargetResourceType == 'microsoft.compute/virtualmachines' && !empty(dataCollectionRuleId)) {
name: name
scope: vmTarget
properties: {
dataCollectionRuleId: dataCollectionRuleId
description: dataCollectionRuleAssociationDescription
}
}

resource dcraArcDcr 'Microsoft.Insights/dataCollectionRuleAssociations@2023-03-11' = if (normalizedTargetResourceType == 'microsoft.hybridcompute/machines' && !empty(dataCollectionRuleId)) {
name: name
scope: arcTarget
properties: {
dataCollectionRuleId: dataCollectionRuleId
description: dataCollectionRuleAssociationDescription
}
}

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

@description('The name of the Data Collection Rule Association.')
output name string = !empty(dataCollectionRuleId)
? (normalizedTargetResourceType == 'microsoft.containerservice/managedclusters'
? dcraAksDcr.name
: (normalizedTargetResourceType == 'microsoft.compute/virtualmachines' ? dcraVmDcr.name : dcraArcDcr.name))
: (normalizedTargetResourceType == 'microsoft.containerservice/managedclusters'
? dcraAksDce.name
: (normalizedTargetResourceType == 'microsoft.compute/virtualmachines' ? dcraVmDce.name : dcraArcDce.name))

@description('The resource ID of the Data Collection Rule Association.')
output resourceId string = !empty(dataCollectionRuleId)
? (normalizedTargetResourceType == 'microsoft.containerservice/managedclusters'
? dcraAksDcr.id
: (normalizedTargetResourceType == 'microsoft.compute/virtualmachines' ? dcraVmDcr.id : dcraArcDcr.id))
: (normalizedTargetResourceType == 'microsoft.containerservice/managedclusters'
? dcraAksDce.id
: (normalizedTargetResourceType == 'microsoft.compute/virtualmachines' ? dcraVmDce.id : dcraArcDce.id))

@description('The name of the resource group containing the Data Collection Rule Association target.')
output resourceGroupName string = resourceGroup().name

// =============== //
// Definitions //
// =============== //

@export()
@description('The supported resource types for the Data Collection Rule Association target.')
type dataCollectionRuleAssociationTargetResourceType = (
| 'Microsoft.ContainerService/managedClusters'
| 'Microsoft.Compute/virtualMachines'
| 'Microsoft.HybridCompute/machines')

@export()
@description('The type for the Data Collection Rule Association module parameters.')
type dataCollectionRuleAssociationType = {
@description('Required. The name of the Data Collection Rule Association. When a Data Collection Endpoint is supplied, the endpoint association is created separately using the required name configurationAccessEndpoint.')
name: string

@description('Required. The type of the resource to which the association is deployed.')
targetResourceType: dataCollectionRuleAssociationTargetResourceType

@description('Required. The name of the resource to which the association is deployed. The resource must exist in the deployment resource group.')
targetResourceName: string

@description('Optional. Resource ID of the Data Collection Rule to associate with the target resource.')
dataCollectionRuleId: string?

@description('Optional. Resource ID of the Data Collection Endpoint to associate with the target resource. The corresponding endpoint association is automatically named configurationAccessEndpoint.')
dataCollectionEndpointId: string?

@description('Optional. Description of the Data Collection Rule Association.')
dataCollectionRuleAssociationDescription: string?

@description('Optional. Enable or disable usage telemetry for the module.')
enableTelemetry: bool?
}

```

### Do you want to be the owner of this module?

No

### Module Owner's GitHub Username (handle)

_No response_

### (Optional) Secondary Module Owner's GitHub Username (handle)

_No response_

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the provided main.bicep implementation and compare it with the existing module indexes and AVM Bicep resource-module conventions. Use the referenced end-to-end test while implementing the Microsoft.Insights/dataCollectionRuleAssociations module for the three supported target resource types. Done means the new module follows repository standards and its end-to-end test passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure
Domain
cloud, infrastructure
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.