Skip to content

Commit

Permalink
feat: Add option to define a delimiter for metric-alarms-by-multiple-…
Browse files Browse the repository at this point in the history
…dimensions (#66)
  • Loading branch information
caseycs authored Feb 26, 2024
1 parent 6434bd3 commit 0959943
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions modules/metric-alarms-by-multiple-dimensions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ No modules.
| <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). | `list(string)` | `null` | no |
| <a name="input_alarm_description"></a> [alarm\_description](#input\_alarm\_description) | The description for the alarm. | `string` | `null` | no |
| <a name="input_alarm_name"></a> [alarm\_name](#input\_alarm\_name) | The descriptive name for the alarm. This name must be unique within the user's AWS account. | `string` | n/a | yes |
| <a name="input_alarm_name_delimiter"></a> [alarm\_name\_delimiter](#input\_alarm\_name\_delimiter) | Delimiter between alarm name and dimension key. Use dash or underscore for pretty alert names. | `string` | `""` | no |
| <a name="input_comparison_operator"></a> [comparison\_operator](#input\_comparison\_operator) | The arithmetic operation to use when comparing the specified Statistic and Threshold. The specified Statistic value is used as the first operand. Either of the following is supported: GreaterThanOrEqualToThreshold, GreaterThanThreshold, LessThanThreshold, LessThanOrEqualToThreshold. | `string` | n/a | yes |
| <a name="input_create_metric_alarm"></a> [create\_metric\_alarm](#input\_create\_metric\_alarm) | Whether to create the Cloudwatch metric alarm | `bool` | `true` | no |
| <a name="input_datapoints_to_alarm"></a> [datapoints\_to\_alarm](#input\_datapoints\_to\_alarm) | The number of datapoints that must be breaching to trigger the alarm. | `number` | `null` | no |
Expand Down
2 changes: 1 addition & 1 deletion modules/metric-alarms-by-multiple-dimensions/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
resource "aws_cloudwatch_metric_alarm" "this" {
for_each = { for k, v in var.dimensions : k => v if var.create_metric_alarm }

alarm_name = format("%s%s", var.alarm_name, each.key)
alarm_name = format("%s%s%s", var.alarm_name, var.alarm_name_delimiter, each.key)
alarm_description = var.alarm_description
actions_enabled = var.actions_enabled

Expand Down
6 changes: 6 additions & 0 deletions modules/metric-alarms-by-multiple-dimensions/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ variable "alarm_name" {
type = string
}

variable "alarm_name_delimiter" {
description = "Delimiter between alarm name and dimension key. Use dash or underscore for pretty alert names."
type = string
default = ""
}

variable "alarm_description" {
description = "The description for the alarm."
type = string
Expand Down
1 change: 1 addition & 0 deletions wrappers/metric-alarms-by-multiple-dimensions/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module "wrapper" {

create_metric_alarm = try(each.value.create_metric_alarm, var.defaults.create_metric_alarm, true)
alarm_name = try(each.value.alarm_name, var.defaults.alarm_name)
alarm_name_delimiter = try(each.value.alarm_name_delimiter, var.defaults.alarm_name_delimiter, "")
alarm_description = try(each.value.alarm_description, var.defaults.alarm_description, null)
comparison_operator = try(each.value.comparison_operator, var.defaults.comparison_operator)
evaluation_periods = try(each.value.evaluation_periods, var.defaults.evaluation_periods)
Expand Down

0 comments on commit 0959943

Please sign in to comment.