-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature/PI-550-billing] billing alert
- Loading branch information
Showing
5 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
infrastructure/terraform/per_account/modules/billing-alert/main.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
resource "aws_cloudwatch_metric_alarm" "account_billing_alarm" { | ||
alarm_name = "${var.prefix}--billing-alarm--${var.threshold_dollars}--${var.metric_name}" | ||
alarm_description = "Billing Alarm of ${var.threshold_dollars} USD (${var.metric_name})" | ||
namespace = "AWS/Billing" | ||
tags = var.tags | ||
|
||
# If statistic(metric) >= threshold in dollars then trigger topic | ||
metric_name = var.metric_name | ||
comparison_operator = "GreaterThanOrEqualToThreshold" | ||
threshold = var.threshold_dollars | ||
alarm_actions = [aws_sns_topic.sns_alert_topic.arn] | ||
|
||
# Evaluate a new statistic(metric) every 6 hours | ||
period = 6 * 60 * 60 # seconds | ||
|
||
# Calculate statistic(metric) over the specified number evaluation periods | ||
statistic = var.metric_statistic | ||
evaluation_periods = var.metric_number_of_evaluation_periods | ||
datapoints_to_alarm = 1 | ||
} | ||
|
||
|
||
resource "aws_sns_topic" "sns_alert_topic" { | ||
name = "${var.prefix}--billing-alarm-${var.threshold_dollars}--${var.metric_name}" | ||
tags = var.tags | ||
} | ||
|
||
resource "aws_sns_topic_subscription" "email_target" { | ||
count = length(var.recipients) | ||
topic_arn = aws_sns_topic.sns_alert_topic.arn | ||
protocol = "email" | ||
endpoint = var.recipients[count.index] | ||
} |
26 changes: 26 additions & 0 deletions
26
infrastructure/terraform/per_account/modules/billing-alert/vars.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
variable "prefix" { | ||
type = string | ||
} | ||
|
||
variable "threshold_dollars" { | ||
type = number | ||
} | ||
variable "recipients" { | ||
type = list(string) | ||
} | ||
|
||
variable "metric_name" { | ||
type = string | ||
} | ||
|
||
variable "metric_number_of_evaluation_periods" { | ||
type = number | ||
} | ||
|
||
variable "metric_statistic" { | ||
type = string | ||
} | ||
|
||
variable "tags" { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters