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

initial commit

parents
terraform {
required_version = ">= 0.14"
backend "azurerm" {
key = "terraform.tfstate"
}
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "=2.41.0"
}
}
}
#-------------------------------
# Providers
#-------------------------------
provider "azurerm" {
features {}
}
#-------------------------------
# Provider Configuration
#-------------------------------
data "azurerm_client_config" "current" {}
#-------------------------------
# Local Variables
#-------------------------------
locals {
action-group-ids = {
DevActionGroup = azurerm_monitor_action_group.DevActionGroup.id
}
}
#-------------------------------
# Resource Group
#-------------------------------
data "azurerm_resource_group" "rg" {
name = "vibsharm-mr-rg"
}
#-------------------------------
# Action Group
#-------------------------------
resource "azurerm_monitor_action_group" "DevActionGroup" {
name = var.action-groups["DevActionGroup"].name
resource_group_name = data.azurerm_resource_group.rg.name
short_name = "vibsharm-ag"
# There can be multiple email receivers
email_receiver {
name = var.action-groups["DevActionGroup"].email-receiver.name
email_address = var.action-groups["DevActionGroup"].email-receiver.email-address
use_common_alert_schema = false
}
}
#-------------------------------
# CPU Usage Alert Rule
#-------------------------------
resource "azurerm_monitor_scheduled_query_rules_alert" "CPU-Usage-Alert" {
name = var.cpu-soft-limit-alert.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.cpu-soft-limit-alert.service-specific-data.storage.action-group-name :
lookup(local.action-group-ids,name)
]
}
/*dynamic "action" {
for_each = [for name in var.cpu-soft-limit-alert.service-specific-data.storage.action-group-name : {
resource-id = lookup(local.action-group-ids,name)
}]
content {
action_group = action.value.resource-id
}
}*/
data_source_id = "/subscriptions/${data.azurerm_client_config.current.subscription_id}/resourceGroups/osdu-mvp-crpentest-qw18-rg/providers/Microsoft.Insights/components/osdu-mvp-crpentest-qw18-ai"
description = var.cpu-soft-limit-alert.description
enabled = true
query = "performanceCounters\n| where cloud_RoleName == \"${var.cpu-soft-limit-alert.service-specific-data.storage.service-name}\"\n| where category == \"Processor\" and name == \"% Processor Time\"\n| summarize AggregatedValue = avg(value) by bin(timestamp, 5min)"
severity = var.cpu-soft-limit-alert.service-specific-data.storage.severity
frequency = var.cpu-soft-limit-alert.service-specific-data.storage.frequency
time_window = var.cpu-soft-limit-alert.service-specific-data.storage.time-window
trigger {
operator = "GreaterThan"
threshold = var.cpu-soft-limit-alert.service-specific-data.storage.threshold
metric_trigger {
operator = "GreaterThan"
threshold = 0
metric_trigger_type = "Total"
metric_column = "timestamp"
}
}
}
/*action-groups = {
DevActionGroup = {
name = "Dev",
email-receiver = {
email-address = "vibsharm@gmail.com",
name = "Dev Email"
}
},
ProdActionGroup = {
name = "Prod",
email-receiver = {
email-address = "vibsharm@gmail.com",
name = "Prod Email"
}
}
}*/
/* This WORKS!!
action-groups = {
name = "Dev",
email-receiver = {
email-address = "vibsharm@gmail.com",
name = "Dev Email"
}
}*/
action-groups = {
DevActionGroup = {
name = "vibsharm-ag",
email-receiver = {
email-address = "vibsharm@microsoft.com",
name = "Dev Email"
}
},
ProdActionGroup = {
name = "Prod",
email-receiver = {
email-address = "vibsharm@gmail.com",
name = "Prod Email"
}
}
}
# Exepectation -
/*DevActionGroup = {
name = "vibsharm-ag",
receiver = {
receiver-1 = {
type = email
email-address = "vibsharm@microsoft.com",
name = "Dev Email"
}
receiver-2 = {
type = SMS
number = "435",
name = "Dev Email"
}
}
}*/
variable "storage-service-alerts" {
type = object({
cpu-soft-limit = object({
alert-rule-name = string,
description = string,
enabled = string,
severity = number,
threshold = number,
frequency = number,
time-window = number,
action-group-name = list(string),
query = string
}),
cpu-hard-limit = object({
alert-rule-name = string,
description = string,
enabled = string,
severity = number,
threshold = number,
frequency = number,
time-window = number,
action-group-name = list(string),
query = string
})
})
default = {
cpu-soft-limit = {
alert-rule-name = "CPU Soft limit",
description = "CPU Soft limit alert rule",
enabled = "true",
severity = 4,
threshold = 60,
frequency = 15,
time-window = 15,
action-group-name = ["DevActionGroup"],
query = "whole query"
},
cpu-hard-limit = {
alert-rule-name = "CPU Hard limit",
description = "CPU Hard limit alert rule",
enabled = "false",
severity = 3,
threshold = 70,
frequency = 5,
time-window = 15,
action-group-name = ["ProdActionGroup","DevActionGroup"],
query = "whole query"
}
}
}
/* THIS WORKS!!!
variable "action-groups" {
type = object({
name = string,
email-receiver = map(string)
})
}*/
variable "action-groups" {
type = map(object({
name = string,
email-receiver = map(string)
}))
}
variable"cpu-soft-limit-alert"{
type=object({
service-specific-data = map(object({
service-name=string,
enabled=string,
severity=string,
threshold=number,
frequency=number,
time-window=number,
action-group-name=list(string)
}))
alert-rule-name=string,
description=string,
location=string
})
default={
service-specific-data= {
storage = {
service-name = "storage",
enabled = true,
severity = 3,
threshold = 0,
frequency = 5,
time-window = 5,
action-group-name = ["DevActionGroup"]
},
legal = {
service-name = "legal",
enabled = true,
severity = 4,
threshold = 70,
frequency = 15,
time-window = 15,
action-group-name = ["DevActionGroup"]
}
},
location="Central US",
alert-rule-name="CPU Soft Limit Alert",
description="Alerting when CPU Usage crosses soft limit threshold value"
}
}
\ No newline at end of file
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