Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Commit

Permalink
add variable for tags
Browse files Browse the repository at this point in the history
  • Loading branch information
lonegunmanb committed Oct 8, 2023
1 parent 4912dea commit a855c1e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 59 deletions.
11 changes: 4 additions & 7 deletions diagnostic_setting.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ resource "azurerm_monitor_diagnostic_setting" "setting" {

name = each.value.name
target_resource_id = azurerm_cognitive_account.this.id
log_analytics_workspace_id = each.value.log_analytics_workspace_id
log_analytics_destination_type = each.value.log_analytics_destination_type
eventhub_name = each.value.eventhub_name
eventhub_authorization_rule_id = each.value.eventhub_authorization_rule_id
storage_account_id = each.value.storage_account_id
eventhub_name = each.value.eventhub_name
log_analytics_destination_type = each.value.log_analytics_destination_type
log_analytics_workspace_id = each.value.log_analytics_workspace_id
partner_solution_id = each.value.partner_solution_id
storage_account_id = each.value.storage_account_id

dynamic "enabled_log" {
for_each = try(each.value.audit_log_retention_policy.enabled, null) == null ? [] : [1]
Expand All @@ -22,7 +22,6 @@ resource "azurerm_monitor_diagnostic_setting" "setting" {
}
}
}

dynamic "enabled_log" {
for_each = try(each.value.request_response_log_retention_policy.enabled, null) == null ? [] : [1]

Expand All @@ -35,7 +34,6 @@ resource "azurerm_monitor_diagnostic_setting" "setting" {
}
}
}

dynamic "enabled_log" {
for_each = try(each.value.trace_log_retention_policy.enabled, null) == null ? [] : [1]

Expand All @@ -48,7 +46,6 @@ resource "azurerm_monitor_diagnostic_setting" "setting" {
}
}
}

dynamic "metric" {
for_each = try(each.value.metric_retention_policy.enabled, null) == null ? [] : [1]

Expand Down
4 changes: 2 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ resource "random_integer" "this" {
locals {
account_name = coalesce(var.account_name, "azure-openai-${random_integer.this.result}")
custom_subdomain_name = coalesce(var.custom_subdomain_name, "azure-openai-${random_integer.this.result}")
tags = var.default_tags_enabled ? {
tags = merge(var.default_tags_enabled ? {
Application_Name = var.application_name
Environment = var.environment
} : {}
} : {}, var.tags)
}

resource "azurerm_cognitive_account" "this" {
Expand Down
107 changes: 57 additions & 50 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,60 @@ variable "deployment" {
nullable = false
}

variable "diagnostic_setting" {
type = map(object({
name = string
log_analytics_workspace_id = optional(string)
log_analytics_destination_type = optional(string)
eventhub_name = optional(string)
eventhub_authorization_rule_id = optional(string)
storage_account_id = optional(string)
partner_solution_id = optional(string)
audit_log_retention_policy = optional(object({
enabled = optional(bool, true)
days = optional(number, 7)
}))
request_response_log_retention_policy = optional(object({
enabled = optional(bool, true)
days = optional(number, 7)
}))
trace_log_retention_policy = optional(object({
enabled = optional(bool, true)
days = optional(number, 7)
}))
metric_retention_policy = optional(object({
enabled = optional(bool, true)
days = optional(number, 7)
}))
}))
default = {}
description = <<-DESCRIPTION
A map of objects that represent the configuration for a diagnostic setting."
type = map(object({
name = (Required) Specifies the name of the diagnostic setting. Changing this forces a new resource to be created.
log_analytics_workspace_id = (Optional) (Optional) Specifies the resource id of an Azure Log Analytics workspace where diagnostics data should be sent.
log_analytics_destination_type = (Optional) Possible values are `AzureDiagnostics` and `Dedicated`. When set to Dedicated, logs sent to a Log Analytics workspace will go into resource specific tables, instead of the legacy `AzureDiagnostics` table.
eventhub_name = (Optional) Specifies the name of the Event Hub where diagnostics data should be sent.
eventhub_authorization_rule_id = (Optional) Specifies the resource id of an Event Hub Namespace Authorization Rule used to send diagnostics data.
storage_account_id = (Optional) Specifies the resource id of an Azure storage account where diagnostics data should be sent.
partner_solution_id = (Optional) The resource id of the market partner solution where diagnostics data should be sent. For potential partner integrations, click to learn more about partner integration.
audit_log_retention_policy = (Optional) Specifies the retention policy for the audit log. This is a block with the following properties:
enabled = (Optional) Specifies whether the retention policy is enabled. If enabled, `days` must be a positive number.
days = (Optional) Specifies the number of days to retain trace logs. If `enabled` is set to `true`, this value must be set to a positive number.
request_response_log_retention_policy = (Optional) Specifies the retention policy for the request response log. This is a block with the following properties:
enabled = (Optional) Specifies whether the retention policy is enabled. If enabled, `days` must be a positive number.
days = (Optional) Specifies the number of days to retain trace logs. If `enabled` is set to `true`, this value must be set to a positive number.
trace_log_retention_policy = (Optional) Specifies the retention policy for the trace log. This is a block with the following properties:
enabled = (Optional) Specifies whether the retention policy is enabled. If enabled, `days` must be a positive number.
days = (Optional) Specifies the number of days to retain trace logs. If `enabled` is set to `true`, this value must be set to a positive number.
metric_retention_policy = (Optional) Specifies the retention policy for the metric. This is a block with the following properties:
enabled = (Optional) Specifies whether the retention policy is enabled. If enabled, `days` must be a positive number.
days = (Optional) Specifies the number of days to retain trace logs. If `enabled` is set to `true`, this value must be set to a positive number.
}))
DESCRIPTION
nullable = false
}

variable "dynamic_throttling_enabled" {
type = bool
default = null
Expand Down Expand Up @@ -217,57 +271,10 @@ variable "storage" {
nullable = false
}

variable "diagnostic_setting" {
type = map(object({
name = string
log_analytics_workspace_id = optional(string)
log_analytics_destination_type = optional(string)
eventhub_name = optional(string)
eventhub_authorization_rule_id = optional(string)
storage_account_id = optional(string)
partner_solution_id = optional(string)
audit_log_retention_policy = optional(object({
enabled = optional(bool, true)
days = optional(number, 7)
}))
request_response_log_retention_policy = optional(object({
enabled = optional(bool, true)
days = optional(number, 7)
}))
trace_log_retention_policy = optional(object({
enabled = optional(bool, true)
days = optional(number, 7)
}))
metric_retention_policy = optional(object({
enabled = optional(bool, true)
days = optional(number, 7)
}))
}))
variable "tags" {
type = map(string)
default = {}
description = <<-DESCRIPTION
A map of objects that represent the configuration for a diagnostic setting."
type = map(object({
name = (Required) Specifies the name of the diagnostic setting. Changing this forces a new resource to be created.
log_analytics_workspace_id = (Optional) (Optional) Specifies the resource id of an Azure Log Analytics workspace where diagnostics data should be sent.
log_analytics_destination_type = (Optional) Possible values are `AzureDiagnostics` and `Dedicated`. When set to Dedicated, logs sent to a Log Analytics workspace will go into resource specific tables, instead of the legacy `AzureDiagnostics` table.
eventhub_name = (Optional) Specifies the name of the Event Hub where diagnostics data should be sent.
eventhub_authorization_rule_id = (Optional) Specifies the resource id of an Event Hub Namespace Authorization Rule used to send diagnostics data.
storage_account_id = (Optional) Specifies the resource id of an Azure storage account where diagnostics data should be sent.
partner_solution_id = (Optional) The resource id of the market partner solution where diagnostics data should be sent. For potential partner integrations, click to learn more about partner integration.
audit_log_retention_policy = (Optional) Specifies the retention policy for the audit log. This is a block with the following properties:
enabled = (Optional) Specifies whether the retention policy is enabled. If enabled, `days` must be a positive number.
days = (Optional) Specifies the number of days to retain trace logs. If `enabled` is set to `true`, this value must be set to a positive number.
request_response_log_retention_policy = (Optional) Specifies the retention policy for the request response log. This is a block with the following properties:
enabled = (Optional) Specifies whether the retention policy is enabled. If enabled, `days` must be a positive number.
days = (Optional) Specifies the number of days to retain trace logs. If `enabled` is set to `true`, this value must be set to a positive number.
trace_log_retention_policy = (Optional) Specifies the retention policy for the trace log. This is a block with the following properties:
enabled = (Optional) Specifies whether the retention policy is enabled. If enabled, `days` must be a positive number.
days = (Optional) Specifies the number of days to retain trace logs. If `enabled` is set to `true`, this value must be set to a positive number.
metric_retention_policy = (Optional) Specifies the retention policy for the metric. This is a block with the following properties:
enabled = (Optional) Specifies whether the retention policy is enabled. If enabled, `days` must be a positive number.
days = (Optional) Specifies the number of days to retain trace logs. If `enabled` is set to `true`, this value must be set to a positive number.
}))
DESCRIPTION
description = "(Optional) A mapping of tags to assign to the resource."
nullable = false
}

Expand Down

0 comments on commit a855c1e

Please sign in to comment.