Skip to content

Instantly share code, notes, and snippets.

@Pelirrojo
Last active September 20, 2025 21:52
Show Gist options
  • Save Pelirrojo/e175230cdbdd1205f58f0cd98fcab42b to your computer and use it in GitHub Desktop.
Save Pelirrojo/e175230cdbdd1205f58f0cd98fcab42b to your computer and use it in GitHub Desktop.
Terraform Budget alert for AWS Marketplace
#
# Budgets & Limits for AWS Bedrock
# https://github.com/evereven-tech/horizons-omnichat/blob/main/aws/13-budgets.tf
# #############################################################################
terraform {
required_version = "~> 1.10.5"
required_providers {
aws = {
source = "hashicorp/aws"
version = "6.11.0"
}
}
backend "s3" {}
}
# Variables
variable "budget_notification_emails" {
description = "Email addresses for budget notifications"
type = list(string)
}
variable "budget_notification_thresholds" {
description = "Budget notification thresholds"
type = list(number)
}
variable "platform_budget_limit" {
description = "Platform budget limit"
type = string
}
variable "marketplace_budget_limit" {
description = "Marketplace budget limit"
type = string
}
# Resources
resource "aws_budgets_budget" "platform_cost" {
name = "Platform-Cost-Budget"
budget_type = "COST"
time_unit = "MONTHLY"
limit_amount = var.platform_budget_limit
limit_unit = "USD"
cost_filter {
name = "BillingEntity"
values = ["AWS"]
}
dynamic "notification" {
for_each = var.budget_notification_thresholds
content {
comparison_operator = "GREATER_THAN"
threshold_type = "PERCENTAGE"
notification_type = "ACTUAL"
threshold = notification.value
subscriber_email_addresses = var.budget_notification_emails
}
}
dynamic "notification" {
for_each = var.budget_notification_thresholds
content {
comparison_operator = "GREATER_THAN"
threshold_type = "PERCENTAGE"
notification_type = "FORECASTED"
threshold = notification.value
subscriber_email_addresses = var.budget_notification_emails
}
}
}
resource "aws_budgets_budget" "marketplace_cost" {
name = "Marketplace-External-Models-Budget"
budget_type = "COST"
time_unit = "MONTHLY"
limit_amount = var.marketplace_budget_limit
limit_unit = "USD"
cost_filter {
name = "BillingEntity"
values = ["AWS Marketplace"]
}
dynamic "notification" {
for_each = var.budget_notification_thresholds
content {
comparison_operator = "GREATER_THAN"
threshold_type = "PERCENTAGE"
notification_type = "ACTUAL"
threshold = notification.value
subscriber_email_addresses = var.budget_notification_emails
}
}
dynamic "notification" {
for_each = var.budget_notification_thresholds
content {
comparison_operator = "GREATER_THAN"
threshold_type = "PERCENTAGE"
notification_type = "FORECASTED"
threshold = notification.value
subscriber_email_addresses = var.budget_notification_emails
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment