Skip to content

Commit 7e6185b

Browse files
authored
Add variable for datapoints_to_alarm (#30)
This adds the option to customize the `datapoints_to_alarm` attribute of the `aws_cloudwatch_metric_alarm` resources
1 parent a402c6a commit 7e6185b

File tree

3 files changed

+36
-20
lines changed

3 files changed

+36
-20
lines changed

README.md

+22-20
Original file line numberDiff line numberDiff line change
@@ -77,26 +77,28 @@ Terraform module to setup alarms and autoscaling triggers for autoscaling
7777
### Inputs
7878

7979
| Name | Description | Type | Default | Required |
80-
|------|-------------|:----:|:-----:|:-----:|
81-
| adjustment\_down | The number of instances to remove when the alarm is triggered (the value has to be negative) | number | `-1` | no |
82-
| adjustment\_type | What typ of adjustment needs to happen | string | `"ChangeInCapacity"` | no |
83-
| adjustment\_up | The number of instances to add when the alarm is triggered | number | `1` | no |
84-
| autoscaling\_group\_names | The names of the Auto Scaling Groups this config needs to be applied to | list | n/a | yes |
85-
| cooldown\_down | The amount of time, in seconds, after a scaling activity completes and before the next scaling activity can start. | number | `600` | no |
86-
| cooldown\_up | The amount of time, in seconds, after a scaling activity completes and before the next scaling activity can start. | number | `300` | no |
87-
| dimension\_name | | string | `"AutoScalingGroupName"` | no |
88-
| dimension\_value | | bool | `false` | no |
89-
| evaluation\_periods | The number of samples to evaluate | number | `4` | no |
90-
| metric\_name | The metric the scaling is based upon | string | `"CPUUtilization"` | no |
91-
| name | Name of the Auto Scaling Groups | string | n/a | yes |
92-
| namespace | The namespace of the cloudwatch metric | string | `"AWS/EC2"` | no |
93-
| num\_asg | The number of autoscaling groups passed | number | `2` | no |
94-
| period\_down | The period in seconds over which the selected metric statistic is applied. | number | `120` | no |
95-
| period\_up | The period in seconds over which the selected metric statistic is applied. | number | `60` | no |
96-
| policy\_type | The policy type, either SimpleScaling or StepScaling | string | `"SimpleScaling"` | no |
97-
| statistic | The statistic to apply to the alarm's associated metric. Either of the following is supported: | string | `"Average"` | no |
98-
| threshold\_down | The metric value to scale down | number | `30` | no |
99-
| threshold\_up | The metric value to scale up | number | `80` | no |
80+
|------|-------------|------|---------|:-----:|
81+
| adjustment_down | The number of instances to remove when the alarm is triggered (the value has to be negative) | `number` | `-1` | no |
82+
| adjustment_type | What typ of adjustment needs to happen | `string` | `"ChangeInCapacity"` | no |
83+
| adjustment_up | The number of instances to add when the alarm is triggered | `number` | `1` | no |
84+
| autoscaling_group_names | The names of the Auto Scaling Groups this config needs to be applied to | `list(string)` | n/a | yes |
85+
| cooldown_down | The amount of time, in seconds, after a scaling activity completes and before the next scaling activity can start. | `number` | `600` | no |
86+
| cooldown_up | The amount of time, in seconds, after a scaling activity completes and before the next scaling activity can start. | `number` | `300` | no |
87+
| datapoints_to_alarm_down | The number of datapoints that must be breaching to trigger the scale DOWN alarm | `number` | n/a | yes |
88+
| datapoints_to_alarm_up | The number of datapoints that must be breaching to trigger the scale UP alarm | `number` | n/a | yes |
89+
| dimension_name | n/a | `string` | `"AutoScalingGroupName"` | no |
90+
| dimension_value | n/a | `string` | n/a | yes |
91+
| evaluation_periods | The number of samples to evaluate | `number` | `4` | no |
92+
| metric_name | The metric the scaling is based upon | `string` | `"CPUUtilization"` | no |
93+
| name | Name for the created resources | `string` | n/a | yes |
94+
| namespace | The namespace of the cloudwatch metric | `string` | `"AWS/EC2"` | no |
95+
| num_asg | The number of autoscaling groups passed | `number` | `2` | no |
96+
| period_down | The period in seconds over which the selected metric statistic is applied. | `number` | `120` | no |
97+
| period_up | The period in seconds over which the selected metric statistic is applied. | `number` | `60` | no |
98+
| policy_type | The policy type, either SimpleScaling or StepScaling | `string` | `"SimpleScaling"` | no |
99+
| statistic | The statistic to apply to the alarm's associated metric. Either of the following is supported: | `string` | `"Average"` | no |
100+
| threshold_down | The metric value to scale down | `number` | `30` | no |
101+
| threshold_up | The metric value to scale up | `number` | `80` | no |
100102

101103
### Example
102104

scaling/main.tf

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ resource "aws_cloudwatch_metric_alarm" "alarm_down" {
88
period = var.period_down
99
statistic = var.statistic
1010
threshold = var.threshold_down
11+
datapoints_to_alarm = var.datapoints_to_alarm_down
1112

1213
dimensions = {
1314
"${var.dimension_name}" = coalesce(var.dimension_value, var.autoscaling_group_names[count.index])
@@ -27,6 +28,7 @@ resource "aws_cloudwatch_metric_alarm" "alarm_up" {
2728
period = var.period_up
2829
statistic = var.statistic
2930
threshold = var.threshold_up
31+
datapoints_to_alarm = var.datapoints_to_alarm_up
3032

3133
dimensions = {
3234
"${var.dimension_name}" = coalesce(var.dimension_value, var.autoscaling_group_names[count.index])

scaling/variables.tf

+12
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,15 @@ variable "dimension_value" {
107107
type = string
108108
default = null
109109
}
110+
111+
variable "datapoints_to_alarm_up" {
112+
type = number
113+
description = "The number of datapoints that must be breaching to trigger the scale UP alarm"
114+
default = null
115+
}
116+
117+
variable "datapoints_to_alarm_down" {
118+
type = number
119+
description = "The number of datapoints that must be breaching to trigger the scale DOWN alarm"
120+
default = null
121+
}

0 commit comments

Comments
 (0)