Commit 6d1d6b0b authored by Vibhuti Sharma [Microsoft]'s avatar Vibhuti Sharma [Microsoft]
Browse files

converting list to map

parent d328e954
......@@ -43,14 +43,14 @@ data "azurerm_resource_group" "rg" {
# Action Groups
#-------------------------------
resource "azurerm_monitor_action_group" "action-groups" {
count = length(var.action-groups)
name = var.action-groups[count.index].name
for_each = var.action-groups
name = each.value.name
resource_group_name = data.azurerm_resource_group.rg.name
short_name = var.action-groups[count.index].short-name
short_name = each.value.short-name
# There can be 0 or more email receivers
dynamic "email_receiver" {
for_each = var.action-groups[count.index].email-receiver
for_each = each.value.email-receiver
content {
name = email_receiver.value.name
email_address = email_receiver.value.email-address
......@@ -60,7 +60,7 @@ resource "azurerm_monitor_action_group" "action-groups" {
# There can be 0 or more sms receivers
dynamic "sms_receiver" {
for_each = var.action-groups[count.index].sms-receiver
for_each = each.value.sms-receiver
content {
name = sms_receiver.value.name
country_code = sms_receiver.value.country-code
......@@ -73,35 +73,35 @@ resource "azurerm_monitor_action_group" "action-groups" {
# Custom Log Search Type Alerts
#-------------------------------
resource "azurerm_monitor_scheduled_query_rules_alert" "alerts" {
count = length(var.log-alerts)
name = var.log-alerts[count.index].alert-rule-name
for_each = var.log-alerts
name = each.value.alert-rule-name
location = data.azurerm_resource_group.rg.location
resource_group_name = data.azurerm_resource_group.rg.name
action {
action_group = [for name in var.log-alerts[count.index].action-group-name :
action_group = [for name in each.value.action-group-name :
format("%s%s", local.action-group-id-suffix, name)
]
}
data_source_id = "/subscriptions/${data.azurerm_client_config.current.subscription_id}/resourceGroups/${var.central-group-prefix}-rg/providers/Microsoft.Insights/components/${var.central-group-prefix}-ai"
description = var.log-alerts[count.index].description
enabled = var.log-alerts[count.index].enabled
query = var.log-alerts[count.index].query
severity = var.log-alerts[count.index].severity
frequency = var.log-alerts[count.index].frequency
time_window = var.log-alerts[count.index].time-window
description = each.value.description
enabled = each.value.enabled
query = each.value.query
severity = each.value.severity
frequency = each.value.frequency
time_window = each.value.time-window
trigger {
operator = var.log-alerts[count.index].trigger-operator
threshold = var.log-alerts[count.index].trigger-threshold
operator = each.value.trigger-operator
threshold = each.value.trigger-threshold
dynamic "metric_trigger" {
# create this block only if alert is of `metric` type
for_each = var.log-alerts[count.index].metric-type ? [1] : []
for_each = each.value.metric-type ? [1] : []
content {
operator = var.log-alerts[count.index].metric-trigger-operator
threshold = var.log-alerts[count.index].metric-trigger-threshold
metric_trigger_type = var.log-alerts[count.index].metric-trigger-type
metric_column = var.log-alerts[count.index].metric-trigger-column
operator = each.value.metric-trigger-operator
threshold = each.value.metric-trigger-threshold
metric_trigger_type = each.value.metric-trigger-type
metric_column = each.value.metric-trigger-column
}
}
}
......
......@@ -2,25 +2,25 @@ central-group-prefix = "xxxx"
rg-name = "vibsharm-mr-rg"
action-groups = [
{
action-groups = {
DevActionGroup = {
name = "DevActionGroup",
short-name = "dev-ag",
email-receiver = [
{
name = "primary developer",
email-address = "xxx@microsoft.com",
email-address = "vixxx@microsoft.com",
common-alert-schema = false
},
{
name = "secondary developer",
email-address = "xxx@gmail.com",
email-address = "vixxx@gmail.com",
common-alert-schema = false
}
],
sms-receiver = []
},
{
ProdActionGroup = {
name = "ProdActionGroup",
short-name = "prod-ag",
email-receiver = [],
......@@ -28,15 +28,15 @@ action-groups = [
{
name = "local support",
country-code = "91",
phone = "xxxxxxxxxx"
phone = "805057xxxx"
}
]
}
]
}
log-alerts = [
log-alerts = {
#------------Storage Service Alerts----------------#
{
storage-cpu-alert = {
service-name = "storage",
alert-rule-name = "CPU Soft limit",
description = "CPU Soft limit alert rule for storage service",
......@@ -57,7 +57,7 @@ log-alerts = [
metric-trigger-type = "Total",
metric-trigger-column = "cloud_RoleName"
},
{
storage-put-record-duration = {
service-name = "storage",
alert-rule-name = "Put Record Duration",
description = "Alert for duration of storage service PUT record API call",
......@@ -80,4 +80,4 @@ log-alerts = [
metric-trigger-column = null
}
#------------------Legal Service Alerts--------------------#
]
\ No newline at end of file
}
\ No newline at end of file
......@@ -9,7 +9,7 @@ variable "rg-name" {
}
variable "action-groups" {
type = list(object({
type = map(object({
name = string,
short-name = string,
email-receiver = list(object({
......@@ -26,7 +26,7 @@ variable "action-groups" {
}
variable "log-alerts" {
type = list(object({
type = map(object({
service-name = string,
alert-rule-name = string,
description = string,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment