Skip to content

Commit 3e1fdd0

Browse files
committed
updating azure dignostics settings and Log analytics id input
1 parent 1bfadc6 commit 3e1fdd0

File tree

2 files changed

+17
-20
lines changed

2 files changed

+17
-20
lines changed

main.tf

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ resource "azurerm_resource_group" "rg" {
2323

2424
data "azurerm_client_config" "current" {}
2525

26-
data "azurerm_log_analytics_workspace" "logws" {
27-
count = var.log_analytics_workspace_name != null ? 1 : 0
28-
name = var.log_analytics_workspace_name
29-
resource_group_name = local.resource_group_name
30-
}
31-
3226
#---------------------------------------------------------
3327
# Storage Account to keep Audit logs - Default is "false"
3428
#----------------------------------------------------------
@@ -103,7 +97,7 @@ resource "azurerm_mssql_server_extended_auditing_policy" "primary" {
10397
storage_account_access_key = azurerm_storage_account.storeacc.0.primary_access_key
10498
storage_account_access_key_is_secondary = false
10599
retention_in_days = var.log_retention_days
106-
log_monitoring_enabled = var.enable_log_monitoring == true && var.log_analytics_workspace_name != null ? true : false
100+
log_monitoring_enabled = var.enable_log_monitoring == true && var.log_analytics_workspace_id != null ? true : false
107101
}
108102

109103
resource "azurerm_sql_server" "secondary" {
@@ -131,7 +125,7 @@ resource "azurerm_mssql_server_extended_auditing_policy" "secondary" {
131125
storage_account_access_key = azurerm_storage_account.storeacc.0.primary_access_key
132126
storage_account_access_key_is_secondary = false
133127
retention_in_days = var.log_retention_days
134-
log_monitoring_enabled = var.enable_log_monitoring == true && var.log_analytics_workspace_name != null ? true : null
128+
log_monitoring_enabled = var.enable_log_monitoring == true && var.log_analytics_workspace_id != null ? true : null
135129
}
136130

137131

@@ -167,7 +161,7 @@ resource "azurerm_mssql_database_extended_auditing_policy" "primary" {
167161
storage_account_access_key = azurerm_storage_account.storeacc.0.primary_access_key
168162
storage_account_access_key_is_secondary = false
169163
retention_in_days = var.log_retention_days
170-
log_monitoring_enabled = var.enable_log_monitoring == true && var.log_analytics_workspace_name != null ? true : null
164+
log_monitoring_enabled = var.enable_log_monitoring == true && var.log_analytics_workspace_id != null ? true : null
171165
}
172166

173167
#-----------------------------------------------------------------------------------------------
@@ -415,11 +409,11 @@ resource "azurerm_private_dns_a_record" "arecord2" {
415409
# azurerm monitoring diagnostics - Default is "false"
416410
#------------------------------------------------------------------
417411
resource "azurerm_monitor_diagnostic_setting" "extaudit" {
418-
count = var.enable_log_monitoring == true && var.log_analytics_workspace_name != null ? 1 : 0
412+
count = var.enable_log_monitoring == true && var.log_analytics_workspace_id != null ? 1 : 0
419413
name = lower("extaudit-${var.database_name}-diag")
420414
target_resource_id = azurerm_sql_database.db.id
421-
log_analytics_workspace_id = data.azurerm_log_analytics_workspace.logws.0.id
422-
storage_account_id = azurerm_storage_account.storeacc.0.id
415+
log_analytics_workspace_id = var.log_analytics_workspace_id
416+
storage_account_id = var.storage_account_id != null ? var.storage_account_id : null
423417

424418
dynamic "log" {
425419
for_each = var.extaudit_diag_logs

variables.tf

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,14 @@ variable "storage_account_name" {
1414
default = null
1515
}
1616

17-
variable "log_analytics_workspace_name" {
18-
description = "The name of log analytics workspace name"
19-
default = null
20-
}
21-
2217
variable "location" {
2318
description = "The location/region to keep all your network resources. To get the list of all locations with table format from azure cli, run 'az account list-locations -o table'"
2419
default = ""
2520
}
2621

2722
variable "random_password_length" {
2823
description = "The desired length of random password created by this module"
29-
default = 24
24+
default = 32
3025
}
3126

3227
variable "enable_sql_server_extended_auditing_policy" {
@@ -181,6 +176,16 @@ variable "sqldb_init_script_file" {
181176
default = ""
182177
}
183178

179+
variable "log_analytics_workspace_id" {
180+
description = "Specifies the ID of a Log Analytics Workspace where Diagnostics Data to be sent"
181+
default = null
182+
}
183+
184+
variable "storage_account_id" {
185+
description = "The name of the storage account to store the all monitoring logs"
186+
default = null
187+
}
188+
184189
variable "extaudit_diag_logs" {
185190
description = "Database Monitoring Category details for Azure Diagnostic setting"
186191
default = ["SQLSecurityAuditEvents", "SQLInsights", "AutomaticTuning", "QueryStoreRuntimeStatistics", "QueryStoreWaitStatistics", "Errors", "DatabaseWaitStatistics", "Timeouts", "Blocks", "Deadlocks"]
@@ -191,5 +196,3 @@ variable "tags" {
191196
type = map(string)
192197
default = {}
193198
}
194-
195-

0 commit comments

Comments
 (0)