From c7f25fa8e18d8a5c7efa8185bd3f30daaf56f9ac Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Mon, 8 Jul 2024 16:28:50 +0200 Subject: [PATCH] terraform, aws: add last-3-months-mean budget with alert by default --- terraform/aws/budget-alerts.tf | 27 +++++++++++++++++++++++++++ terraform/aws/variables.tf | 14 ++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 terraform/aws/budget-alerts.tf diff --git a/terraform/aws/budget-alerts.tf b/terraform/aws/budget-alerts.tf new file mode 100644 index 0000000000..a480afc0fc --- /dev/null +++ b/terraform/aws/budget-alerts.tf @@ -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) + ] + } +} diff --git a/terraform/aws/variables.tf b/terraform/aws/variables.tf index 8d9b60026a..04c3c0a28f 100644 --- a/terraform/aws/variables.tf +++ b/terraform/aws/variables.tf @@ -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 +}