|
| 1 | +provider "aws" { |
| 2 | + region = "eu-west-1" |
| 3 | +} |
| 4 | + |
| 5 | +locals { |
| 6 | + tags = { |
| 7 | + example = "composite-alarm" |
| 8 | + region = "eu-west-1" |
| 9 | + } |
| 10 | +} |
| 11 | + |
| 12 | +module "composite_alarm" { |
| 13 | + source = "../../modules/composite-alarm" |
| 14 | + |
| 15 | + alarm_name = "composite-alarm" |
| 16 | + alarm_description = "Example of a composite alarm" |
| 17 | + |
| 18 | + alarm_actions = [module.aws_sns_topic_2.sns_topic_arn] |
| 19 | + ok_actions = [module.aws_sns_topic_2.sns_topic_arn] |
| 20 | + |
| 21 | + alarm_rule = join(" AND ", tolist([ |
| 22 | + "ALARM(${module.lambda_duration_alarm.cloudwatch_metric_alarm_id})", |
| 23 | + "ALARM(${module.all_lambdas_errors_alarm.cloudwatch_metric_alarm_id})" |
| 24 | + ])) |
| 25 | + |
| 26 | + actions_suppressor = { |
| 27 | + alarm = module.suppressor.cloudwatch_metric_alarm_id |
| 28 | + extension_period = 20 |
| 29 | + wait_period = 10 |
| 30 | + } |
| 31 | + |
| 32 | + tags = local.tags |
| 33 | +} |
| 34 | + |
| 35 | +################################################################################ |
| 36 | +# Supporting Resources |
| 37 | +################################################################################ |
| 38 | + |
| 39 | +module "aws_sns_topic_1" { |
| 40 | + source = "../fixtures/aws_sns_topic" |
| 41 | +} |
| 42 | + |
| 43 | +module "aws_sns_topic_2" { |
| 44 | + source = "../fixtures/aws_sns_topic" |
| 45 | +} |
| 46 | + |
| 47 | +module "aws_lambda_function1" { |
| 48 | + source = "../fixtures/aws_lambda_function" |
| 49 | +} |
| 50 | + |
| 51 | +module "lambda_duration_alarm" { |
| 52 | + source = "../../modules/metric-alarm" |
| 53 | + |
| 54 | + alarm_name = "lambda-duration" |
| 55 | + alarm_description = "Lambda duration is too high" |
| 56 | + comparison_operator = "GreaterThanOrEqualToThreshold" |
| 57 | + evaluation_periods = 1 |
| 58 | + threshold = 10 |
| 59 | + period = 60 |
| 60 | + unit = "Milliseconds" |
| 61 | + |
| 62 | + namespace = "AWS/Lambda" |
| 63 | + metric_name = "Duration" |
| 64 | + statistic = "Maximum" |
| 65 | + |
| 66 | + dimensions = { |
| 67 | + FunctionName = module.aws_lambda_function1.lambda_function_name |
| 68 | + } |
| 69 | + |
| 70 | + alarm_actions = [module.aws_sns_topic_1.sns_topic_arn] |
| 71 | +} |
| 72 | + |
| 73 | +module "all_lambdas_errors_alarm" { |
| 74 | + source = "../../modules/metric-alarm" |
| 75 | + |
| 76 | + alarm_name = "all-lambdas-errors" |
| 77 | + alarm_description = "Lambdas with errors" |
| 78 | + comparison_operator = "GreaterThanOrEqualToThreshold" |
| 79 | + evaluation_periods = 1 |
| 80 | + threshold = 0 |
| 81 | + period = 60 |
| 82 | + unit = "Count" |
| 83 | + |
| 84 | + namespace = "AWS/Lambda" |
| 85 | + metric_name = "Errors" |
| 86 | + statistic = "Maximum" |
| 87 | + |
| 88 | + alarm_actions = [module.aws_sns_topic_1.sns_topic_arn] |
| 89 | +} |
| 90 | + |
| 91 | +module "suppressor" { |
| 92 | + source = "../../modules/metric-alarm" |
| 93 | + |
| 94 | + alarm_name = "deployment-alarm" |
| 95 | + alarm_description = "Deployment alarm" |
| 96 | + comparison_operator = "GreaterThanThreshold" |
| 97 | + evaluation_periods = 1 |
| 98 | + threshold = 1 |
| 99 | + metric_query = [{ |
| 100 | + id = "e1" |
| 101 | + |
| 102 | + return_data = true |
| 103 | + expression = "TIME_SERIES(1)" |
| 104 | + label = "deployment" |
| 105 | + period = 60 |
| 106 | + }] |
| 107 | + |
| 108 | + alarm_actions = [module.aws_sns_topic_1.sns_topic_arn] |
| 109 | +} |
0 commit comments