Skip to content

LewisHarveyNHSD/terraform-aws-send-alarms-to-msteams

 
 

Repository files navigation

Terraform AWS Send Alarms to msteams

This module provides the the infrastructure to send Budget and Cloudwatch alarms to msteams.

Example Usage

provider "aws" {
  region = "eu-west-2"
}

resource "random_pet" "this" {
  length = 2
}

module "alarm_module" {
  source                                     = "../../"
  prefix                                     = random_pet.this.id
  msteams_webhook_budget_alarm               = var.MS_TEAMS_WEB_HOOK
  msteams_webhook_cloudwatch_alarm           = var.MS_TEAMS_WEB_HOOK
  cloudwatch_retention_in_days               = 7
  overwrite_msteams_webhook_budget_alarm     = true
  overwrite_msteams_webhook_cloudwatch_alarm = true
}

resource "aws_budgets_budget" "budget" {
  name         = "${random_pet.this.id}-monthly-budget"
  budget_type  = "COST"
  limit_amount = "50"
  limit_unit   = "USD"
  time_unit    = "MONTHLY"

  notification {
    comparison_operator = "GREATER_THAN"
    threshold           = 100
    threshold_type      = "PERCENTAGE"
    notification_type   = "FORECASTED"
    subscriber_sns_topic_arns = [
      module.alarm_module.budget_alarm_topic_arn
    ]
  }
}

resource "aws_cloudwatch_metric_alarm" "concurrent_lambdas" {
  alarm_name          = "${random_pet.this.id}-concurrent-lambdas-alarm"
  comparison_operator = "GreaterThanThreshold"
  evaluation_periods  = "1"
  metric_name         = "ConcurrentExecutions"
  namespace           = "AWS/Lambda"
  period              = "300"
  statistic           = "Sum"
  threshold           = 10
  alarm_actions = [
    module.alarm_module.cloudwatch_alarm_topic_arn
  ]
  alarm_description  = "https://nhsd-confluence.digital.nhs.uk/display/SPACE/PlaybookA"
  treat_missing_data = "notBreaching"
}

This example may create resources which cost money. Run terraform destroy when you don't need the resources.

Inputs

Name Description Type Default Required
cloudwatch_retention_in_days The number of days cloudwatch logs should be kept number 365 no
lambda_reserved_concurrency Reserved concurrency is the maximum number of concurrent instances you want to allocate to your function. When a function has reserved concurrency, no other function can use that concurrency number 1 no
lambda_timeout The time in seconds the lambda function is allowed to run before it times out number "60" no
msteams_webhook_budget_alarm The microsoft teams webhook string n/a yes
msteams_webhook_budget_ssm_lifecycle_ignore_changes_value True to set the lifecycle {ignore = [value]}, e.i. the ssm parameter will not be overwritten on deploy bool n/a yes
msteams_webhook_cloudwatch_alarm The microsoft teams webhook string n/a yes
msteams_webhook_cloudwatch_ssm_lifecycle_ignore_changes_value True to set the lifecycle {ignore = [value]}, e.i. the ssm parameter will not be overwritten on deploy bool n/a yes
prefix The name you want the resources to be prefixed with, for example dev, test, prod string n/a yes

Modules

No modules.

Outputs

Name Description
budget_alarm_topic_arn The budget alarm topic arn. Subscribe your budget alarms to this topic
cloudwatch_alarm_topic_arn The cloudwatch alarm topic arn. Subscribe your cloudwatch alarms to this topic
msteams_lambda_function_name n/a

Providers

Name Version
archive >= 2.0.0
aws >= 4.0.0
null >= 3.2

Requirements

Name Version
terraform >= 1.3.9
archive >= 2.0.0
aws >= 4.0.0
null >= 3.2

Resources

Name Type
aws_cloudwatch_log_group.function_log_group resource
aws_cloudwatch_log_stream.cloudwatch_log_stream resource
aws_iam_policy.function_logging_policy resource
aws_iam_policy.ssm_policy resource
aws_iam_role.iam_for_lambda resource
aws_iam_role_policy_attachment.function_ssm_policy_attachment resource
aws_iam_role_policy_attachment.ssm_policy_attachment resource
aws_lambda_function.lambda_function resource
aws_lambda_layer_version.python_dependencies_layer resource
aws_lambda_permission.invoke_lambda_permissions_budget_alarm_topic resource
aws_lambda_permission.invoke_lambda_permissions_cloudwatch_alarm_topic resource
aws_sns_topic.budget_alarm_topic resource
aws_sns_topic.cloudwatch_alarm_topic resource
aws_sns_topic_policy.budget_alerts_policy resource
aws_sns_topic_subscription.subscribe_lambda_to_budget_alarm_topic resource
aws_sns_topic_subscription.subscribe_lambda_to_cloudwatch_alarm_topic resource
aws_ssm_parameter.budget_webhook resource
aws_ssm_parameter.budget_webhook_lifecycle_ignore_changes_value resource
aws_ssm_parameter.cloudwatch_webhook resource
aws_ssm_parameter.cloudwatch_webhook_lifecycle_ignore_changes_value resource
null_resource.pip_install resource
archive_file.lambda_function data source
archive_file.layer data source
aws_iam_policy_document.assume_role data source
aws_iam_policy_document.function_logging_policy_document data source
aws_iam_policy_document.sns_budget_alerts data source
aws_iam_policy_document.ssm_policy data source

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • HCL 63.0%
  • Python 26.2%
  • Makefile 7.4%
  • Shell 3.4%