Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Missing Diagnostic Settings to Modules #765

Merged
merged 18 commits into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,21 @@
},
"useResourcePermissions": {
"value": true
},
"diagnosticLogsRetentionInDays": {
"value": 7
},
"diagnosticStorageAccountId": {
"value": "/subscriptions/<<subscriptionId>>/resourceGroups/validation-rg/providers/Microsoft.Storage/storageAccounts/adpsxxazsaweux001"
},
"workspaceId": {
"value": "/subscriptions/<<subscriptionId>>/resourcegroups/validation-rg/providers/microsoft.operationalinsights/workspaces/adp-sxx-az-law-x-001"
},
"eventHubAuthorizationRuleId": {
"value": "/subscriptions/<<subscriptionId>>/resourceGroups/validation-rg/providers/Microsoft.EventHub/namespaces/adp-sxx-az-evhns-x-001/AuthorizationRules/RootManageSharedAccessKey"
},
"eventHubName": {
"value": "adp-sxx-az-evh-x-001"
}
}
}
65 changes: 65 additions & 0 deletions arm/Microsoft.OperationalInsights/workspaces/deploy.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,23 @@ param publicNetworkAccessForQuery string = 'Enabled'
@description('Optional. Set to \'true\' to use resource or workspace permissions and \'false\' (or leave empty) to require workspace permissions.')
param useResourcePermissions bool = false

@description('Optional. Specifies the number of days that logs will be kept for; a value of 0 will retain data indefinitely.')
@minValue(0)
@maxValue(365)
param diagnosticLogsRetentionInDays int = 365

@description('Optional. Resource ID of the diagnostic storage account.')
param diagnosticStorageAccountId string = ''

@description('Optional. Resource ID of a log analytics workspace.')
param workspaceId string = ''

@description('Optional. Resource ID of the event hub authorization rule for the Event Hubs namespace in which the event hub should be created or streamed to.')
param eventHubAuthorizationRuleId string = ''

@description('Optional. Name of the event hub within the namespace to which logs are streamed. Without this, an event hub is created for each log category.')
param eventHubName string = ''

@allowed([
'CanNotDelete'
'NotSpecified'
Expand All @@ -71,6 +88,41 @@ param tags object = {}
@description('Optional. Customer Usage Attribution ID (GUID). This GUID must be previously registered')
param cuaId string = ''

@description('Optional. The name of logs that will be streamed.')
@allowed([
'Audit'
])
param logsToEnable array = [
'Audit'
]

@description('Optional. The name of metrics that will be streamed.')
@allowed([
'AllMetrics'
])
param metricsToEnable array = [
'AllMetrics'
]

var diagnosticsLogs = [for log in logsToEnable: {
category: log
enabled: true
retentionPolicy: {
enabled: true
days: diagnosticLogsRetentionInDays
}
}]

var diagnosticsMetrics = [for metric in metricsToEnable: {
category: metric
timeGrain: null
enabled: true
retentionPolicy: {
enabled: true
days: diagnosticLogsRetentionInDays
}
}]

var logAnalyticsSearchVersion = 1

module pid_cuaId '.bicep/nested_cuaId.bicep' = if (!empty(cuaId)) {
Expand Down Expand Up @@ -99,6 +151,19 @@ resource logAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2020-08
}
}

resource logAnalyticsWorkspace_diagnosticSettings 'Microsoft.Insights/diagnosticSettings@2021-05-01-preview' = if ((!empty(diagnosticStorageAccountId)) || (!empty(workspaceId)) || (!empty(eventHubAuthorizationRuleId)) || (!empty(eventHubName))) {
name: '${logAnalyticsWorkspace.name}-diagnosticSettings'
properties: {
storageAccountId: !empty(diagnosticStorageAccountId) ? diagnosticStorageAccountId : null
workspaceId: !empty(workspaceId) ? workspaceId : null
eventHubAuthorizationRuleId: !empty(eventHubAuthorizationRuleId) ? eventHubAuthorizationRuleId : null
eventHubName: !empty(eventHubName) ? eventHubName : null
metrics: diagnosticsMetrics
logs: diagnosticsLogs
}
scope: logAnalyticsWorkspace
}

module logAnalyticsWorkspace_storageInsightConfigs 'storageInsightConfigs/deploy.bicep' = [for (storageInsightsConfig, index) in storageInsightsConfigs: {
name: '${uniqueString(deployment().name, location)}-LAW-StorageInsightsConfig-${index}'
params: {
Expand Down
9 changes: 9 additions & 0 deletions arm/Microsoft.OperationalInsights/workspaces/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This template deploys a log analytics workspace.
| :-- | :-- |
| `Microsoft.Authorization/locks` | 2016-09-01 |
| `Microsoft.Authorization/roleAssignments` | 2020-04-01-preview |
| `Microsoft.Insights/diagnosticSettings` | 2021-05-01-preview |
| `Microsoft.OperationalInsights/workspaces` | 2020-08-01 |
| `Microsoft.OperationalInsights/workspaces/dataSources` | 2020-08-01 |
| `Microsoft.OperationalInsights/workspaces/linkedServices` | 2020-08-01 |
Expand All @@ -23,10 +24,16 @@ This template deploys a log analytics workspace.
| `dailyQuotaGb` | int | `-1` | | Optional. The workspace daily quota for ingestion. |
| `dataRetention` | int | `365` | | Required. Number of days data will be retained for |
| `dataSources` | _[dataSources](dataSources/readme.md)_ array | `[]` | | Optional. LAW data sources to configure. |
| `diagnosticLogsRetentionInDays` | int | `365` | | Optional. Specifies the number of days that logs will be kept for; a value of 0 will retain data indefinitely. |
| `diagnosticStorageAccountId` | string | | | Optional. Resource ID of the diagnostic storage account. |
| `eventHubAuthorizationRuleId` | string | | | Optional. Resource ID of the event hub authorization rule for the Event Hubs namespace in which the event hub should be created or streamed to. |
| `eventHubName` | string | | | Optional. Name of the event hub within the namespace to which logs are streamed. Without this, an event hub is created for each log category. |
| `gallerySolutions` | array | `[]` | | Optional. LAW gallerySolutions from the gallery. |
| `linkedServices` | _[linkedServices](linkedServices/readme.md)_ array | `[]` | | Optional. List of services to be linked. |
| `location` | string | `[resourceGroup().location]` | | Optional. Location for all resources. |
| `lock` | string | `NotSpecified` | `[CanNotDelete, NotSpecified, ReadOnly]` | Optional. Specify the type of lock. |
| `logsToEnable` | array | `[Audit]` | `[Audit]` | Optional. The name of logs that will be streamed. |
| `metricsToEnable` | array | `[AllMetrics]` | `[AllMetrics]` | Optional. The name of metrics that will be streamed. |
| `name` | string | | | Required. Name of the Log Analytics workspace |
| `publicNetworkAccessForIngestion` | string | `Enabled` | `[Enabled, Disabled]` | Optional. The network access type for accessing Log Analytics ingestion. |
| `publicNetworkAccessForQuery` | string | `Enabled` | `[Enabled, Disabled]` | Optional. The network access type for accessing Log Analytics query. |
Expand All @@ -36,6 +43,7 @@ This template deploys a log analytics workspace.
| `storageInsightsConfigs` | array | `[]` | | Optional. List of storage accounts to be read by the workspace. |
| `tags` | object | `{object}` | | Optional. Tags of the resource. |
| `useResourcePermissions` | bool | | | Optional. Set to 'true' to use resource or workspace permissions and 'false' (or leave empty) to require workspace permissions. |
| `workspaceId` | string | | | Optional. Resource ID of a log analytics workspace. |

### Parameter Usage: `gallerySolutions`

Expand Down Expand Up @@ -123,6 +131,7 @@ Tag names and tag values can be provided as needed. A tag can be left without a

- [Locks](https://docs.microsoft.com/en-us/azure/templates/Microsoft.Authorization/2016-09-01/locks)
- [Roleassignments](https://docs.microsoft.com/en-us/azure/templates/Microsoft.Authorization/2020-04-01-preview/roleAssignments)
- [Diagnosticsettings](https://docs.microsoft.com/en-us/azure/templates/Microsoft.Insights/2021-05-01-preview/diagnosticSettings)
- [Workspaces](https://docs.microsoft.com/en-us/azure/templates/Microsoft.OperationalInsights/2020-08-01/workspaces)
- [Workspaces/Datasources](https://docs.microsoft.com/en-us/azure/templates/Microsoft.OperationalInsights/2020-08-01/workspaces/dataSources)
- [Workspaces/Linkedservices](https://docs.microsoft.com/en-us/azure/templates/Microsoft.OperationalInsights/2020-08-01/workspaces/linkedServices)
Expand Down
7 changes: 6 additions & 1 deletion arm/Microsoft.Sql/servers/.parameters/parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@
"tier": "GeneralPurpose",
"skuName": "GP_Gen5_2",
"maxSizeBytes": 34359738368,
"licenseType": "LicenseIncluded"
"licenseType": "LicenseIncluded",
"diagnosticLogsRetentionInDays": 7,
"diagnosticStorageAccountId": "/subscriptions/<<subscriptionId>>/resourceGroups/validation-rg/providers/Microsoft.Storage/storageAccounts/adpsxxazsaweux001",
"workspaceId": "/subscriptions/<<subscriptionId>>/resourcegroups/validation-rg/providers/microsoft.operationalinsights/workspaces/adp-sxx-az-law-x-001",
"eventHubAuthorizationRuleId": "/subscriptions/<<subscriptionId>>/resourceGroups/validation-rg/providers/Microsoft.EventHub/namespaces/adp-sxx-az-evhns-x-001/AuthorizationRules/RootManageSharedAccessKey",
"eventHubName": "adp-sxx-az-evh-x-001"
}
]
},
Expand Down
81 changes: 81 additions & 0 deletions arm/Microsoft.Sql/servers/databases/deploy.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,74 @@ param location string = resourceGroup().location
@description('Optional. Customer Usage Attribution ID (GUID). This GUID must be previously registered')
param cuaId string = ''

@description('Optional. Specifies the number of days that logs will be kept for; a value of 0 will retain data indefinitely.')
@minValue(0)
@maxValue(365)
param diagnosticLogsRetentionInDays int = 365

@description('Optional. Resource ID of the diagnostic storage account.')
param diagnosticStorageAccountId string = ''

@description('Optional. Resource ID of log analytics.')
param workspaceId string = ''

@description('Optional. Resource ID of the event hub authorization rule for the Event Hubs namespace in which the event hub should be created or streamed to.')
param eventHubAuthorizationRuleId string = ''

@description('Optional. Name of the event hub within the namespace to which logs are streamed. Without this, an event hub is created for each log category.')
param eventHubName string = ''

@description('Optional. The name of logs that will be streamed.')
@allowed([
'SQLInsights'
'AutomaticTuning'
'QueryStoreRuntimeStatistics'
'QueryStoreWaitStatistics'
'Errors'
'DatabaseWaitStatistics'
'Timouts'
'Blocks'
'Deadlocks'
])
param logsToEnable array = [
'SQLInsights'
'AutomaticTuning'
'QueryStoreRuntimeStatistics'
'QueryStoreWaitStatistics'
'Errors'
'DatabaseWaitStatistics'
'Timouts'
'Blocks'
'Deadlocks'
]

@description('Optional. The name of metrics that will be streamed.')
@allowed([
'Basic'
])
param metricsToEnable array = [
'Basic'
]

var diagnosticsLogs = [for log in logsToEnable: {
category: log
enabled: true
retentionPolicy: {
enabled: true
days: diagnosticLogsRetentionInDays
}
}]

var diagnosticsMetrics = [for metric in metricsToEnable: {
category: metric
timeGrain: null
enabled: true
retentionPolicy: {
enabled: true
days: diagnosticLogsRetentionInDays
}
}]

@description('Optional. The storage account type to be used to store backups for this database.')
@allowed([
'Geo'
Expand Down Expand Up @@ -99,6 +167,19 @@ resource database 'Microsoft.Sql/servers/databases@2021-02-01-preview' = {
}
}

resource database_diagnosticSettings 'Microsoft.Insights/diagnosticSettings@2021-05-01-preview' = if ((!empty(diagnosticStorageAccountId)) || (!empty(workspaceId)) || (!empty(eventHubAuthorizationRuleId)) || (!empty(eventHubName))) {
name: '${last(split(database.name, '/'))}-diagnosticSettings'
properties: {
storageAccountId: !empty(diagnosticStorageAccountId) ? diagnosticStorageAccountId : null
workspaceId: !empty(workspaceId) ? workspaceId : null
eventHubAuthorizationRuleId: !empty(eventHubAuthorizationRuleId) ? eventHubAuthorizationRuleId : null
eventHubName: !empty(eventHubName) ? eventHubName : null
metrics: diagnosticsMetrics
logs: diagnosticsLogs
}
scope: database
}

@description('The name of the deployed database')
output databaseName string = database.name

Expand Down
9 changes: 9 additions & 0 deletions arm/Microsoft.Sql/servers/databases/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This module deploys an Azure SQL Server.

| Resource Type | API Version |
| :-- | :-- |
| `Microsoft.Insights/diagnosticSettings` | 2021-05-01-preview |
| `Microsoft.Sql/servers/databases` | 2021-02-01-preview |

## Parameters
Expand All @@ -15,12 +16,18 @@ This module deploys an Azure SQL Server.
| `autoPauseDelay` | string | | | Optional. Time in minutes after which database is automatically paused. |
| `collation` | string | | | Optional. The collation of the database. |
| `cuaId` | string | | | Optional. Customer Usage Attribution ID (GUID). This GUID must be previously registered |
| `diagnosticLogsRetentionInDays` | int | `365` | | Optional. Specifies the number of days that logs will be kept for; a value of 0 will retain data indefinitely. |
| `diagnosticStorageAccountId` | string | | | Optional. Resource ID of the diagnostic storage account. |
| `eventHubAuthorizationRuleId` | string | | | Optional. Resource ID of the event hub authorization rule for the Event Hubs namespace in which the event hub should be created or streamed to. |
| `eventHubName` | string | | | Optional. Name of the event hub within the namespace to which logs are streamed. Without this, an event hub is created for each log category. |
| `highAvailabilityReplicaCount` | int | | | Optional. The number of readonly secondary replicas associated with the database. |
| `isLedgerOn` | bool | | | Optional. Whether or not this database is a ledger database, which means all tables in the database are ledger tables. Note: the value of this property cannot be changed after the database has been created. |
| `licenseType` | string | | | Optional. The license type to apply for this database. |
| `location` | string | `[resourceGroup().location]` | | Optional. Location for all resources. |
| `logsToEnable` | array | `[SQLInsights, AutomaticTuning, QueryStoreRuntimeStatistics, QueryStoreWaitStatistics, Errors, DatabaseWaitStatistics, Timouts, Blocks, Deadlocks]` | `[SQLInsights, AutomaticTuning, QueryStoreRuntimeStatistics, QueryStoreWaitStatistics, Errors, DatabaseWaitStatistics, Timouts, Blocks, Deadlocks]` | Optional. The name of logs that will be streamed. |
| `maintenanceConfigurationId` | string | | | Optional. Maintenance configuration ID assigned to the database. This configuration defines the period when the maintenance updates will occur. |
| `maxSizeBytes` | int | | | Optional. The max size of the database expressed in bytes. |
| `metricsToEnable` | array | `[Basic]` | `[Basic]` | Optional. The name of metrics that will be streamed. |
| `minCapacity` | string | | | Optional. Minimal capacity that database will always have allocated. |
| `name` | string | | | Required. The name of the database. |
| `readScale` | string | `Disabled` | `[Enabled, Disabled]` | Optional. The state of read-only routing. |
Expand All @@ -30,6 +37,7 @@ This module deploys an Azure SQL Server.
| `skuName` | string | | | Required. The name of the SKU. |
| `tags` | object | `{object}` | | Optional. Tags of the resource. |
| `tier` | string | | | Optional. The tier or edition of the particular SKU. |
| `workspaceId` | string | | | Optional. Resource ID of log analytics. |
| `zoneRedundant` | bool | | | Optional. Whether or not this database is zone redundant. |

### Parameter Usage: `tags`
Expand Down Expand Up @@ -59,4 +67,5 @@ Tag names and tag values can be provided as needed. A tag can be left without a

## Template references

- [Diagnosticsettings](https://docs.microsoft.com/en-us/azure/templates/Microsoft.Insights/2021-05-01-preview/diagnosticSettings)
- [Servers/Databases](https://docs.microsoft.com/en-us/azure/templates/Microsoft.Sql/2021-02-01-preview/servers/databases)
7 changes: 7 additions & 0 deletions arm/Microsoft.Sql/servers/deploy.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,23 @@ module server_databases 'databases/deploy.bicep' = [for (database, index) in dat
skuName: database.skuName
collation: database.collation
autoPauseDelay: contains(database, 'autoPauseDelay') ? database.autoPauseDelay : ''
diagnosticLogsRetentionInDays: contains(database, 'diagnosticLogsRetentionInDays') ? database.diagnosticLogsRetentionInDays : 365
diagnosticStorageAccountId: contains(database, 'diagnosticStorageAccountId') ? database.diagnosticStorageAccountId : ''
eventHubAuthorizationRuleId: contains(database, 'eventHubAuthorizationRuleId') ? database.eventHubAuthorizationRuleId : ''
eventHubName: contains(database, 'eventHubName') ? database.eventHubName : ''
isLedgerOn: contains(database, 'isLedgerOn') ? database.isLedgerOn : false
location: contains(database, 'location') ? database.location : server.location
logsToEnable: contains(database, 'logsToEnable') ? database.logsToEnable : []
licenseType: contains(database, 'licenseType') ? database.licenseType : ''
maintenanceConfigurationId: contains(database, 'maintenanceConfigurationId') ? database.maintenanceConfigurationId : ''
minCapacity: contains(database, 'minCapacity') ? database.minCapacity : ''
metricsToEnable: contains(database, 'metricsToEnable') ? database.metricsToEnable : []
highAvailabilityReplicaCount: contains(database, 'highAvailabilityReplicaCount') ? database.highAvailabilityReplicaCount : 0
readScale: contains(database, 'readScale') ? database.readScale : 'Disabled'
requestedBackupStorageRedundancy: contains(database, 'requestedBackupStorageRedundancy') ? database.requestedBackupStorageRedundancy : ''
sampleName: contains(database, 'sampleName') ? database.sampleName : ''
tags: contains(database, 'tags') ? database.tags : {}
workspaceId: contains(database, 'workspaceId') ? database.workspaceId : ''
zoneRedundant: contains(database, 'zoneRedundant') ? database.zoneRedundant : false
}
}]
Expand Down
2 changes: 2 additions & 0 deletions arm/Microsoft.Sql/servers/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This module deploys a SQL server.
| :-- | :-- |
| `Microsoft.Authorization/locks` | 2016-09-01 |
| `Microsoft.Authorization/roleAssignments` | 2020-04-01-preview |
| `Microsoft.Insights/diagnosticSettings` | 2021-05-01-preview |
| `Microsoft.Sql/servers` | 2021-05-01-preview |
| `Microsoft.Sql/servers/databases` | 2021-02-01-preview |
| `Microsoft.Sql/servers/firewallRules` | 2021-05-01-preview |
Expand Down Expand Up @@ -96,6 +97,7 @@ You can specify multiple user assigned identities to a resource by providing add

- [Locks](https://docs.microsoft.com/en-us/azure/templates/Microsoft.Authorization/2016-09-01/locks)
- [Roleassignments](https://docs.microsoft.com/en-us/azure/templates/Microsoft.Authorization/2020-04-01-preview/roleAssignments)
- [Diagnosticsettings](https://docs.microsoft.com/en-us/azure/templates/Microsoft.Insights/2021-05-01-preview/diagnosticSettings)
- [Servers](https://docs.microsoft.com/en-us/azure/templates/Microsoft.Sql/2021-05-01-preview/servers)
- [Servers/Databases](https://docs.microsoft.com/en-us/azure/templates/Microsoft.Sql/2021-02-01-preview/servers/databases)
- [Servers/Firewallrules](https://docs.microsoft.com/en-us/azure/templates/Microsoft.Sql/2021-05-01-preview/servers/firewallRules)
Expand Down
Loading