Skip to main content

Module: budgets

Terraform module to create AWS Budgets and an associated SNS topic and Lambda function to send notifications to Slack.

Usage

For a complete example, see examples/complete.

For automated tests of the complete example using bats and Terratest (which tests and deploys the example on AWS), see test.

# Create a standard label resource. See [null-label](https://github.com/cloudposse/terraform-null-label/#terraform-null-label--)
module "label" {
source = "cloudposse/label/null"
# Cloud Posse recommends pinning every module to a specific version, though usually you want to use the current one
# version = "x.x.x"

namespace = "eg"
name = "example"
}

locals {
budgets = [
{
name = "budget-ec2-monthly"
budget_type = "COST"
limit_amount = "1200"
limit_unit = "USD"
time_period_end = "2087-06-15_00:00"
time_unit = "MONTHLY"

cost_filter = {
Service = ["Amazon Elastic Compute Cloud - Compute"]
}

notification = {
comparison_operator = "GREATER_THAN"
threshold = "100"
threshold_type = "PERCENTAGE"
notification_type = "FORECASTED"
}
},
{
name = "100-total-monthly"
budget_type = "COST"
limit_amount = "100"
limit_unit = "USD"
time_unit = "MONTHLY"
},
{
name = "s3-3GB-limit-monthly"
budget_type = "USAGE"
limit_amount = "3"
limit_unit = "GB"
time_unit = "MONTHLY"
}
]
}

module "budgets" {
source = "cloudposse/budgets/aws"
# Cloud Posse recommends pinning every module to a specific version
# version = "x.x.x"

budgets = local.budgets

# create an SNS topic and lambda for Slack notifications
notifications_enabled = true
slack_webhook_url = "https://slack-webhook-url"
slack_username = "AWS Budgets"
slack_channel = "notifications"

# encrypt SNS topic, this also creates a KMS CMK that allows `budgets.amazonaws.com` to use it
encryption_enabled = true

context = module.label.this
}

Examples

Here is an example of using this module: