Skip to content

opsstation/terraform-azure-monitor-alerts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Terraform-azure-monitor-alerts

Terraform Azure Cloud Monitor-Alerts Module

Table of Contents

Introduction

This module provides a Terraform configuration for deploying various Azure resources as part of your infrastructure. The configuration includes the deployment of resource groups, monitor-alerts.

Usage

To use this module, you should have Terraform installed and configured for AZURE. This module provides the necessary Terraform configuration for creating AZURE resources, and you can customize the inputs as needed. Below is an example of how to use this module:

Examples

Example: AzMonitor-ActionGroups

module "azmonitor-action-groups" {
  source      =  "git::https://github.com/opsstation/terraform-azure-monitor-alerts.git?ref=v1.0.0"
  name        = "app"
  environment = "test"
  actionGroups = {
    "group1" = {
      actionGroupName      = "AlertEscalationGroup"
      actionGroupShortName = "alertesc"
      actionGroupRGName    = module.resource_group.resource_group_name
      actionGroupEnabled   = "true"
      actionGroupEmailReceiver = [
        {
          name                    = "example"
          email_address           = "[email protected]"
          use_common_alert_schema = "true"
        },
        {
          name                    = "test"
          email_address           = "yadxxxxxxxxxxxxgmail.com"
          use_common_alert_schema = "true"
        }
      ]
    }
  }
}

Example: AzMonitor-ActivityLogAlerts

module "alerts" {
  depends_on  = [data.azurerm_monitor_action_group.example, ]
  source      =  "git::https://github.com/opsstation/terraform-azure-monitor-alerts.git?ref=v1.0.0"
  name        = "app"
  environment = "test"
  activity_log_alert = {
    "test1" = {
      alertname      = "vm-restart"
      alertrg        = module.resource_group.resource_group_name
      alertscopes    = [module.resource_group.resource_group_id]
      description    = "Administrative alerts for vm"
      operation_name = "Microsoft.Compute/virtualMachines/restart/action"
      actionGroupID  = data.azurerm_monitor_action_group.example.id
      category       = "Administrative"
    },
    "test2" = {
      alertname      = "vm-powerOff"
      alertrg        = module.resource_group.resource_group_name
      alertscopes    = [module.resource_group.resource_group_id]
      description    = "Administrative alerts for vm"
      operation_name = "Microsoft.Compute/virtualMachines/powerOff/action"
      actionGroupID  = data.azurerm_monitor_action_group.example.id
      category       = "Administrative"
    }
  }
}

Example: AzMonitor-MetricAlerts

module "azmonitor-metric-alerts" {
  depends_on = [data.azurerm_monitor_action_group.example, data.azurerm_kubernetes_cluster.example]
  source      =  "git::https://github.com/opsstation/terraform-azure-monitor-alerts.git?ref=v1.0.0"
  name        = "app"
  environment = "test"
  metricAlerts = {
    "alert1" = {
      alertName              = "testing-alert"
      alertResourceGroupName = module.resource_group.resource_group_name
      alertScopes = [
        data.azurerm_kubernetes_cluster.example.id
      ]
      alertDescription           = ""
      alertEnabled               = "true"
      dynCriteriaMetricNamespace = "Microsoft.ContainerService/managedClusters"
      dynCriteriaMetricName      = "node_cpu_usage_percentage"
      dynCriteriaAggregation     = "Average"
      dynCriteriaOperator        = "GreaterThan"
      dynCriteriathreshold       = "1"
      alertAutoMitigate          = "true"
      alertFrequency             = "PT1M"
      alertTargetResourceType    = "Microsoft.ContainerService/managedClusters"
      alertTargetResourceLoc     = data.azurerm_kubernetes_cluster.example.location
      actionGroupID              = data.azurerm_monitor_action_group.example.id
    },
    "alert2" = {
      alertName              = "testing-alert2"
      alertResourceGroupName = module.resource_group.resource_group_name
      alertScopes = [
        data.azurerm_kubernetes_cluster.example.id
      ]
      alertDescription           = ""
      alertEnabled               = "true"
      dynCriteriaMetricNamespace = "Microsoft.ContainerService/managedClusters"
      dynCriteriaMetricName      = "node_memory_working_set_percentage"
      dynCriteriaAggregation     = "Average"
      dynCriteriaOperator        = "GreaterThan"
      dynCriteriathreshold       = "1"
      alertAutoMitigate          = "true"
      alertFrequency             = "PT1M"
      alertTargetResourceType    = "Microsoft.ContainerService/managedClusters"
      alertTargetResourceLoc     = data.azurerm_kubernetes_cluster.example.location
      actionGroupID              = data.azurerm_monitor_action_group.example.id
    }

  }
}

This example demonstrates how to create various AZURE resources using the provided modules. Adjust the input values to suit your specific requirements.

Examples

For detailed examples on how to use this module, please refer to the Examples directory within this repository.

License

This Terraform module is provided under the MIT License. Please see the LICENSE file for more details.

Author

Your Name Replace MIT and Cypik with the appropriate license and your information. Feel free to expand this README with additional details or usage instructions as needed for your specific use case.

Requirements

Name Version
terraform >= 1.0.0
azurerm >=2.90.0

Providers

Name Version
azurerm >=2.90.0

Modules

Name Source Version
labels git::https://github.com/opsstation/terraform-azure-labels.git v1.0.0

Resources

Name Type
azurerm_monitor_action_group.group resource
azurerm_monitor_activity_log_alert.main resource
azurerm_monitor_metric_alert.alert resource

Inputs

Name Description Type Default Required
actionGroups n/a
map(object({
actionGroupName = string
actionGroupShortName = string
actionGroupRGName = string
actionGroupEnabled = string
actionGroupEmailReceiver = list(map(string))
}))
{} no
activity_log_alert n/a
map(object({
alertname = string
alertrg = string
alertscopes = list(string)
description = string
operation_name = string
actionGroupID = string
category = string
}))
{} no
environment Environment (e.g. prod, dev, staging). string "" no
label_order Label order, e.g. name,application. list(any)
[
"name",
"environment"
]
no
managedby ManagedBy, eg 'OpsStation'. string "" no
metricAlerts n/a
map(object({
alertName = string
alertResourceGroupName = string
alertScopes = list(string)
alertDescription = string
alertEnabled = bool
alertAutoMitigate = bool
alertFrequency = string
alertTargetResourceType = string
alertTargetResourceLoc = string
dynCriteriaMetricNamespace = string
dynCriteriaMetricName = string
dynCriteriaAggregation = string
dynCriteriaOperator = string
dynCriteriathreshold = string
actionGroupID = string
}))
{} no
name Name (e.g. app or cluster). string "" no
repository Terraform current module repo string "" no

Outputs

Name Description
ag n/a
metric-alerts n/a

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages