Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more params: datapoints_to_alarm and actions_enabled #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ variable "default_evaluation_periods" {
default = 2
}

variable "default_datapoints_to_alarm" {
description = "The default amount of datapoints to alarm."
default = 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While true is the default value for actions_enabled, it seems there is no default value for datapoints_to_alarm. The AWS UI seems to set this value to 1 by default.

I think we can set the default to null here, just in case users don't want to override this value. In that case AWS will set whatever value they have defined as default.

}

variable "default_period" {
description = "The default evaluation period."
default = 60
Expand All @@ -23,6 +28,11 @@ variable "default_statistic" {
default = "Average"
}

variable "default_actions_enabled" {
description = "Indicates whether or not actions should be executed during any changes to the alarm's state."
default = true
}

resource "aws_cloudwatch_metric_alarm" "alarm" {
count = length(var.alarms)

Expand All @@ -44,6 +54,12 @@ resource "aws_cloudwatch_metric_alarm" "alarm" {
var.default_evaluation_periods
)

datapoints_to_alarm = lookup(
var.alarms[element(keys(var.alarms), count.index)],
"datapoints_to_alarm",
var.default_datapoints_to_alarm
)

metric_name = element(keys(var.alarms), count.index)

namespace = "AWS/CloudFront"
Expand Down Expand Up @@ -76,4 +92,10 @@ resource "aws_cloudwatch_metric_alarm" "alarm" {
"actions",
""
)))

actions_enabled = compact(split(",", lookup(
var.alarms[element(keys(var.alarms), count.index)],
"actions_enabled",
var.default_actions_enabled
)))
}
2 changes: 2 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ The following arguments are supported:
- period: The period in seconds over which the specified statistic is applied.
- statistic: The statistic to apply to the alarm's associated metric.
- threshold: The number of occurances over a given period.
- datapoints_to_alarm: The number of datapoints that must be breaching to trigger the alarm.
- actions: The actions to execute when the alarm transitions into an ALARM state.
Due to a limitation in Terraform, this list must be given as a comma-separated string.
- actions_enabled: Indicates whether or not actions should be executed during any changes to the alarm's state.
EOF
}