Skip to content

Commit

Permalink
feat: Add support for AgentSettings DCR in `avm/res/insights/data-col…
Browse files Browse the repository at this point in the history
…lection-rule` (#3120)

## Description

Adding support for Data Collection Rules of the kind `AgentSettings`

Closes #2864 
Closes #1973 

## Pipeline Reference

| Pipeline |
| -------- |
|
[![avm.res.insights.data-collection-rule](https://github.com/krbar/bicep-registry-modules/actions/workflows/avm.res.insights.data-collection-rule.yml/badge.svg?branch=users%2Fkrbar%2FdcrAgentSettings&event=workflow_dispatch)](https://github.com/krbar/bicep-registry-modules/actions/workflows/avm.res.insights.data-collection-rule.yml)
|

## Type of Change

<!-- Use the checkboxes [x] on the options that are relevant. -->

- [ ] Update to CI Environment or utilities (Non-module affecting
changes)
- [x] Azure Verified Module updates:
- [ ] Bugfix containing backwards-compatible bug fixes, and I have NOT
bumped the MAJOR or MINOR version in `version.json`:
- [x] Someone has opened a bug report issue, and I have included "Closes
#{bug_report_issue_number}" in the PR description.
- [ ] The bug was found by the module author, and no one has opened an
issue to report it yet.
- [ ] Feature update backwards compatible feature updates, and I have
bumped the MINOR version in `version.json`.
- [x] Breaking changes and I have bumped the MAJOR version in
`version.json`.
  - [ ] Update to documentation

## Checklist

- [x] I'm sure there are no other open Pull Requests for the same
update/change
- [x] I have run `Set-AVMModule` locally to generate the supporting
module files.
- [x] My corresponding pipelines / checks run clean and green without
any errors or warnings

<!-- Please keep up to date with the contribution guide at
https://aka.ms/avm/contribute/bicep -->
  • Loading branch information
krbar authored Aug 30, 2024
1 parent 615b260 commit c804d3a
Show file tree
Hide file tree
Showing 13 changed files with 2,095 additions and 1,846 deletions.
2,413 changes: 1,194 additions & 1,219 deletions avm/res/insights/data-collection-rule/README.md

Large diffs are not rendered by default.

173 changes: 119 additions & 54 deletions avm/res/insights/data-collection-rule/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,25 @@ metadata owner = 'Azure/module-maintainers'
// Parameters //
// ============== //

@sys.description('Required. The name of the data collection rule. The name is case insensitive.')
@description('Required. The name of the data collection rule. The name is case insensitive.')
param name string

@sys.description('Optional. The resource ID of the data collection endpoint that this rule can be used with.')
param dataCollectionEndpointId string?
@description('Required. The kind of data collection rule.')
param dataCollectionRuleProperties dataCollectionRulePropertiesType

@sys.description('Required. The specification of data flows.')
param dataFlows array

@sys.description('Required. Specification of data sources that will be collected.')
param dataSources object

@sys.description('Optional. Description of the data collection rule.')
param description string?

@sys.description('Required. Specification of destinations that can be used in data flows.')
param destinations object

@sys.description('Optional. Enable/Disable usage telemetry for module.')
@description('Optional. Enable/Disable usage telemetry for module.')
param enableTelemetry bool = true

@sys.description('Optional. The kind of the resource.')
@allowed([
'Linux'
'Windows'
])
param kind string = 'Linux'

@sys.description('Optional. Location for all Resources.')
@description('Optional. Location for all Resources.')
param location string = resourceGroup().location

@sys.description('Optional. The lock settings of the service.')
@description('Optional. The lock settings of the service.')
param lock lockType

@sys.description('Optional. Array of role assignments to create.')
@description('Optional. Array of role assignments to create.')
param roleAssignments roleAssignmentType

@sys.description('Optional. Declaration of custom streams used in this rule.')
param streamDeclarations object?

@sys.description('Optional. Resource tags.')
@description('Optional. Resource tags.')
param tags object?

// =============== //
Expand Down Expand Up @@ -97,19 +75,30 @@ resource avmTelemetry 'Microsoft.Resources/deployments@2024-03-01' = if (enableT
}
}

resource dataCollectionRule 'Microsoft.Insights/dataCollectionRules@2021-09-01-preview' = {
kind: kind
resource dataCollectionRule 'Microsoft.Insights/dataCollectionRules@2023-03-11' = {
kind: dataCollectionRuleProperties.kind
location: location
name: name
tags: tags
properties: {
dataSources: dataSources
destinations: destinations
dataFlows: dataFlows
dataCollectionEndpointId: dataCollectionEndpointId
streamDeclarations: streamDeclarations
description: description
}
properties: union(
{
description: dataCollectionRuleProperties.?description
},
dataCollectionRuleProperties.kind == 'Linux' || dataCollectionRuleProperties.kind == 'Windows'
? {
dataSources: dataCollectionRuleProperties.dataSources
dataFlows: dataCollectionRuleProperties.dataFlows
destinations: dataCollectionRuleProperties.destinations
dataCollectionEndpointId: dataCollectionRuleProperties.?dataCollectionEndpointResourceId
streamDeclarations: dataCollectionRuleProperties.?streamDeclarations
}
: {},
dataCollectionRuleProperties.kind == 'AgentSettings'
? {
agentSettings: dataCollectionRuleProperties.agentSettings
}
: {}
)
}

resource dataCollectionRule_lock 'Microsoft.Authorization/locks@2020-05-01' = if (!empty(lock ?? {}) && lock.?kind != 'None') {
Expand Down Expand Up @@ -147,52 +136,128 @@ resource dataCollectionRule_roleAssignments 'Microsoft.Authorization/roleAssignm
// Outputs //
// =========== //

@sys.description('The name of the dataCollectionRule.')
@description('The name of the dataCollectionRule.')
output name string = dataCollectionRule.name

@sys.description('The resource ID of the dataCollectionRule.')
@description('The resource ID of the dataCollectionRule.')
output resourceId string = dataCollectionRule.id

@sys.description('The name of the resource group the dataCollectionRule was created in.')
@description('The name of the resource group the dataCollectionRule was created in.')
output resourceGroupName string = resourceGroup().name

@sys.description('The location the resource was deployed into.')
@description('The location the resource was deployed into.')
output location string = dataCollectionRule.location

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

type lockType = {
@sys.description('Optional. Specify the name of lock.')
@description('Optional. Specify the name of lock.')
name: string?

@sys.description('Optional. Specify the type of lock.')
@description('Optional. Specify the type of lock.')
kind: ('CanNotDelete' | 'ReadOnly' | 'None')?
}?

type roleAssignmentType = {
@sys.description('Optional. The name (as GUID) of the role assignment. If not provided, a GUID will be generated.')
@description('Optional. The name (as GUID) of the role assignment. If not provided, a GUID will be generated.')
name: string?

@sys.description('Required. The role to assign. You can provide either the display name of the role definition, the role definition GUID, or its fully qualified ID in the following format: \'/providers/Microsoft.Authorization/roleDefinitions/c2f4ef07-c644-48eb-af81-4b1b4947fb11\'.')
@description('Required. The role to assign. You can provide either the display name of the role definition, the role definition GUID, or its fully qualified ID in the following format: \'/providers/Microsoft.Authorization/roleDefinitions/c2f4ef07-c644-48eb-af81-4b1b4947fb11\'.')
roleDefinitionIdOrName: string

@sys.description('Required. The principal ID of the principal (user/group/identity) to assign the role to.')
@description('Required. The principal ID of the principal (user/group/identity) to assign the role to.')
principalId: string

@sys.description('Optional. The principal type of the assigned principal ID.')
@description('Optional. The principal type of the assigned principal ID.')
principalType: ('ServicePrincipal' | 'Group' | 'User' | 'ForeignGroup' | 'Device')?

@sys.description('Optional. The description of the role assignment.')
@description('Optional. The description of the role assignment.')
description: string?

@sys.description('Optional. The conditions on the role assignment. This limits the resources it can be assigned to. e.g.: @Resource[Microsoft.Storage/storageAccounts/blobServices/containers:ContainerName] StringEqualsIgnoreCase "foo_storage_container".')
@description('Optional. The conditions on the role assignment. This limits the resources it can be assigned to. e.g.: @Resource[Microsoft.Storage/storageAccounts/blobServices/containers:ContainerName] StringEqualsIgnoreCase "foo_storage_container".')
condition: string?

@sys.description('Optional. Version of the condition.')
@description('Optional. Version of the condition.')
conditionVersion: '2.0'?

@sys.description('Optional. The Resource Id of the delegated managed identity resource.')
@description('Optional. The Resource Id of the delegated managed identity resource.')
delegatedManagedIdentityResourceId: string?
}[]?

@discriminator('kind')
type dataCollectionRulePropertiesType =
| linuxDcrPropertiesType
| windowsDcrPropertiesType
| agentSettingsDcrPropertiesType

type linuxDcrPropertiesType = {
@description('Required. The platform type specifies the type of resources this rule can apply to.')
kind: 'Linux'

@description('Required. Specification of data sources that will be collected.')
dataSources: object

@description('Required. The specification of data flows.')
dataFlows: array

@description('Required. Specification of destinations that can be used in data flows.')
destinations: object

@description('Optional. The resource ID of the data collection endpoint that this rule can be used with.')
dataCollectionEndpointResourceId: string?

@description('Optional. Declaration of custom streams used in this rule.')
streamDeclarations: object?

@description('Optional. Description of the data collection rule.')
description: string?
}

type windowsDcrPropertiesType = {
@description('Required. The platform type specifies the type of resources this rule can apply to.')
kind: 'Windows'

@description('Required. Specification of data sources that will be collected.')
dataSources: object

@description('Required. The specification of data flows.')
dataFlows: array

@description('Required. Specification of destinations that can be used in data flows.')
destinations: object

@description('Optional. The resource ID of the data collection endpoint that this rule can be used with.')
dataCollectionEndpointResourceId: string?

@description('Optional. Declaration of custom streams used in this rule.')
streamDeclarations: object?

@description('Optional. Description of the data collection rule.')
description: string?
}

type agentSettingsDcrPropertiesType = {
@description('Required. The platform type specifies the type of resources this rule can apply to.')
kind: 'AgentSettings'

@description('Optional. Description of the data collection rule.')
description: string?

@description('Required. Agent settings used to modify agent behavior on a given host.')
agentSettings: agentSettingsType
}

type agentSettingsType = {
@description('Required. All the settings that are applicable to the logs agent (AMA).')
logs: agentSettingType[]
}

type agentSettingType = {
@description('Required. The name of the agent setting.')
name: ('MaxDiskQuotaInMB' | 'UseTimeReceivedForForwardedEvents')

@description('Required. The value of the agent setting.')
value: string
}
Loading

0 comments on commit c804d3a

Please sign in to comment.