Skip to content

Commit

Permalink
terraform, aws: add last-3-months-mean budget with alert by default
Browse files Browse the repository at this point in the history
  • Loading branch information
consideRatio committed Jul 8, 2024
1 parent 7a8be26 commit c7f25fa
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
27 changes: 27 additions & 0 deletions terraform/aws/budget-alerts.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
resource "aws_budgets_budget" "budgets" {
count = var.default_budget_alert.enabled ? 1 : 0

name = "Auto-adjusting budget for ${var.cluster_name}"
budget_type = "COST"
limit_unit = "USD"
time_unit = "MONTHLY"

auto_adjust_data {
auto_adjust_type = "HISTORICAL"

historical_options {
budget_adjustment_period = 3
}
}

notification {
comparison_operator = "GREATER_THAN"
threshold = 120
threshold_type = "PERCENTAGE"
notification_type = "FORECASTED"
subscriber_email_addresses = [
for email in var.default_budget_alert.subscriber_email_addresses :
replace(email, "{var_cluster_name}", var.cluster_name)
]
}
}
14 changes: 14 additions & 0 deletions terraform/aws/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,17 @@ variable "tags" {
they deploy and manage themselves.
EOT
}

variable "default_budget_alert" {
type = object({
enabled : optional(bool, true)
subscriber_email_addresses : optional(
list(string),
["support+{var_cluster_name}@2i2c.org"]
)
})
default = {}
description = <<-EOT
A boilerplate budget alert initially setup for AWS accounts we pay the bill for.
EOT
}

0 comments on commit c7f25fa

Please sign in to comment.