Skip to content

Commit 7760f26

Browse files
stefanfreitagrwestefanfreitag
authored andcommitted
feat: ok and alert actions can be configured
1 parent 0b5018d commit 7760f26

File tree

5 files changed

+48
-7
lines changed

5 files changed

+48
-7
lines changed

.devcontainer/devcontainer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
"version": "latest"
1313
},
1414
"ghcr.io/devcontainers/features/terraform:1": {
15-
"version": "1.6.2",
16-
"tflint": "0.48.0",
15+
"version": "1.9.0",
16+
"tflint": "0.51.1",
1717
"installTFsec": "true",
1818
"installTerraformDocs": "true"
1919
},

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,26 @@
55

66
This module deploys a Lambda function that checks the health of MSK cluster and sends a notification if a cluster is unhealthy.
77

8+
If the target for `ok_actions`, `alarm_actions` or `insufficient_data_actions` is an SNS topic using a KMS key, ensure
9+
that CloudWatch Alarms has sufficient permissions to publish messages.
10+
For example:
11+
```shell
12+
statement {
13+
sid = "Allow access for CloudWatch Alarms"
14+
effect = "Allow"
15+
principals {
16+
type = "Service"
17+
identifiers = ["cloudwatch.amazonaws.com"]
18+
}
19+
actions = [
20+
"kms:Decrypt",
21+
"kms:GenerateDataKey"
22+
]
23+
resources = ["*"]
24+
25+
}
26+
```
27+
828
<!-- BEGIN_TF_DOCS -->
929
## Requirements
1030

@@ -49,15 +69,18 @@ No modules.
4969

5070
| Name | Description | Type | Default | Required |
5171
|------|-------------|------|---------|:--------:|
72+
| <a name="input_alarm_actions"></a> [alarm\_actions](#input\_alarm\_actions) | The list of actions to execute when this alarm transitions into an ALARM state from any other state. Each action is specified as an Amazon Resource Name (ARN). Default is `null`. | `list(string)` | `null` | no |
5273
| <a name="input_cloudwatch_alarms_treat_missing_data"></a> [cloudwatch\_alarms\_treat\_missing\_data](#input\_cloudwatch\_alarms\_treat\_missing\_data) | Sets how the alarms handle missing data points. The following values are supported: `missing`, `ignore`, `breaching` and `notBreaching`. Default is `breaching`. | `string` | `"breaching"` | no |
5374
| <a name="input_cluster_arns"></a> [cluster\_arns](#input\_cluster\_arns) | List of MSK cluster ARNs. Default is `[]`. | `list(string)` | `[]` | no |
5475
| <a name="input_email"></a> [email](#input\_email) | List of e-mail addresses subscribing to the SNS topic. Default is `[]`. | `list(string)` | `[]` | no |
5576
| <a name="input_enable_cloudwatch_alarms"></a> [enable\_cloudwatch\_alarms](#input\_enable\_cloudwatch\_alarms) | Setup CloudWatch alarms for the MSK clusters state. For each state a separate alarm will be created. Default is `false`. | `bool` | `false` | no |
5677
| <a name="input_enable_sns_notifications"></a> [enable\_sns\_notifications](#input\_enable\_sns\_notifications) | Setup SNS notifications for the MSK clusters state. Default is `false`. | `bool` | `false` | no |
5778
| <a name="input_ignore_states"></a> [ignore\_states](#input\_ignore\_states) | Suppress warnings for the listed MSK states. Default: ['MAINTENANCE'] | `list(string)` | <pre>[<br> "MAINTENANCE"<br>]</pre> | no |
79+
| <a name="input_insufficient_data_actions"></a> [insufficient\_data\_actions](#input\_insufficient\_data\_actions) | The list of actions to execute when this alarm transitions into an INSUFFICIENT\_DATA state from any other state. Each action is specified as an Amazon Resource Name (ARN). Default is `null`. | `list(string)` | `null` | no |
5880
| <a name="input_log_retion_period_in_days"></a> [log\_retion\_period\_in\_days](#input\_log\_retion\_period\_in\_days) | Number of days logs will be retained. Default is `365`. | `number` | `365` | no |
5981
| <a name="input_memory_size"></a> [memory\_size](#input\_memory\_size) | Amount of memory in MByte that the Lambda function can use at runtime. Default is `160`. | `number` | `160` | no |
6082
| <a name="input_name"></a> [name](#input\_name) | Name of the health monitor. Default is `msk_status_monitor`. | `string` | `"msk_status_monitor"` | no |
83+
| <a name="input_ok_actions"></a> [ok\_actions](#input\_ok\_actions) | The list of actions to execute when this alarm transitions into an OK state from any other state. Each action is specified as an Amazon Resource Name (ARN). | `list(string)` | `null` | no |
6184
| <a name="input_schedule_expression"></a> [schedule\_expression](#input\_schedule\_expression) | The schedule expression for the CloudWatch event rule. Default is `rate(5 minutes)`. | `string` | `"rate(5 minutes)"` | no |
6285
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to add to all resources. Default is `{}`. | `map(string)` | `{}` | no |
6386

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
terraform {
2-
required_version = "~>1.8"
2+
required_version = "~>1.9"
33
required_providers {
44
aws = {
55
source = "hashicorp/aws"
6-
version = "~>5.32"
6+
version = "~>5.59"
77
}
88
}
99
}

main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ resource "aws_cloudwatch_metric_alarm" "this" {
178178
statistic = "Average"
179179
threshold = 0
180180
treat_missing_data = var.cloudwatch_alarms_treat_missing_data
181-
alarm_actions = []
182-
insufficient_data_actions = []
183-
# TODO: ok_actions = [var.sns_topic_alarms_arn]
181+
ok_actions = var.ok_actions
182+
alarm_actions = var.alarm_actions
183+
insufficient_data_actions = var.insufficient_data_actions
184184
dimensions = {
185185
ClusterName = each.key
186186
}

variables.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,24 @@ variable "cloudwatch_alarms_treat_missing_data" {
2626
}
2727
}
2828

29+
variable "alarm_actions" {
30+
description = "The list of actions to execute when this alarm transitions into an ALARM state from any other state. Each action is specified as an Amazon Resource Name (ARN). Default is `null`."
31+
type = list(string)
32+
default = null
33+
}
34+
35+
variable "insufficient_data_actions" {
36+
description = "The list of actions to execute when this alarm transitions into an INSUFFICIENT_DATA state from any other state. Each action is specified as an Amazon Resource Name (ARN). Default is `null`."
37+
type = list(string)
38+
default = null
39+
}
40+
41+
variable "ok_actions" {
42+
description = "The list of actions to execute when this alarm transitions into an OK state from any other state. Each action is specified as an Amazon Resource Name (ARN)."
43+
type = list(string)
44+
default = null
45+
}
46+
2947
variable "enable_sns_notifications" {
3048
description = "Setup SNS notifications for the MSK clusters state. Default is `false`."
3149
type = bool

0 commit comments

Comments
 (0)