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

added diagnostic setting enable resource #4

Merged
merged 1 commit into from
Mar 14, 2023
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
4 changes: 4 additions & 0 deletions README.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,9 @@ usage: |-
log_analytics_workspace_sku = "PerGB2018"
resource_group_name = module.resource_group.resource_group_name
log_analytics_workspace_location = module.resource_group.resource_group_location

#### enable diagnostic setting
diagnostic_setting_enable = false
log_analytics_workspace_id = module.log-analytics.workspace_id
}
```
6 changes: 5 additions & 1 deletion _example/example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module "resource_group" {
source = "clouddrove/resource-group/azure"
version = "1.0.0"

name = "app"
name = "app-log-analy"
environment = "test"
label_order = ["name", "environment"]
location = "Canada Central"
Expand All @@ -24,4 +24,8 @@ module "log-analytics" {
internet_query_enabled = true
resource_group_name = module.resource_group.resource_group_name
log_analytics_workspace_location = module.resource_group.resource_group_location

#### enable diagnostic setting
diagnostic_setting_enable = false
log_analytics_workspace_id = module.log-analytics.workspace_id
}
40 changes: 40 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,43 @@ resource "azurerm_log_analytics_workspace" "main" {
internet_query_enabled = var.internet_query_enabled
tags = module.labels.tags
}
resource "azurerm_monitor_diagnostic_setting" "example" {
count = var.enabled && var.diagnostic_setting_enable ? 1 : 0
name = format("%s-log-analytics-diagnostic-log", module.labels.id)
target_resource_id = join("", azurerm_log_analytics_workspace.main.*.id)
storage_account_id = var.storage_account_id
eventhub_name = var.eventhub_name
eventhub_authorization_rule_id = var.eventhub_authorization_rule_id
log_analytics_workspace_id = var.log_analytics_workspace_id
log_analytics_destination_type = var.log_analytics_destination_type
metric {
category = "AllMetrics"
enabled = var.Metric_enable
retention_policy {
enabled = var.retention_policy_enabled
days = var.days
}
}
log {
category = var.category
category_group = "AllLogs"
retention_policy {
enabled = var.retention_policy_enabled
days = var.days
}
enabled = var.log_enabled
}

log {
category = var.category
category_group = "Audit"
retention_policy {
enabled = var.retention_policy_enabled
days = var.days
}
enabled = var.log_enabled
}
lifecycle {
ignore_changes = [log_analytics_destination_type]
}
}
55 changes: 55 additions & 0 deletions variable.tf
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,58 @@ variable "internet_query_enabled" {
default = true
description = "Should the Log Analytics Workspace support querying over the Public Internet? Defaults to true."
}
#### enable diagnostic setting
variable "log_analytics_destination_type" {
type = string
default = "AzureDiagnostics"
description = "Possible values are AzureDiagnostics and Dedicated, default to AzureDiagnostics. When set to Dedicated, logs sent to a Log Analytics workspace will go into resource specific tables, instead of the legacy AzureDiagnostics table."
}
variable "retention_policy_enabled" {
type = bool
default = false
description = "Is this Retention Policy enabled?"
}
variable "days" {
type = number
default = "90"
description = " The number of days for which this Retention Policy should apply."
}
variable "Metric_enable" {
type = bool
default = true
description = "Is this Diagnostic Metric enabled? Defaults to true."
}
variable "diagnostic_setting_enable" {
type = bool
default = false
}
variable "log_analytics_workspace_id" {
type = string
default = null
}

variable "category" {
type = string
default = null
description = " The name of a Diagnostic Log Category Group for this Resource."
}
variable "log_enabled" {
type = string
default = true
description = " Is this Diagnostic Log enabled? Defaults to true."
}
variable "storage_account_id" {
type = string
default = null
description = "The ID of the Storage Account where logs should be sent."
}
variable "eventhub_name" {
type = string
default = null
description = "Specifies the name of the Event Hub where Diagnostics Data should be sent."
}
variable "eventhub_authorization_rule_id" {
type = string
default = null
description = "Specifies the ID of an Event Hub Namespace Authorization Rule used to send Diagnostics Data."
}