Resource: aws_budgets_budget

Provides a budgets budget resource. Budgets use the cost visualisation provided by Cost Explorer to show you the status of your budgets, to provide forecasts of your estimated costs, and to track your AWS usage, including your free tier usage.

Example Usage

resource "aws_budgets_budget" "ec2" {
  name              = "budget-ec2-monthly"
  budget_type       = "COST"
  limit_amount      = "1200"
  limit_unit        = "USD"
  time_period_end   = "2087-06-15_00:00"
  time_period_start = "2017-07-01_00:00"
  time_unit         = "MONTHLY"

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

  notification {
    comparison_operator        = "GREATER_THAN"
    threshold                  = 100
    threshold_type             = "PERCENTAGE"
    notification_type          = "FORECASTED"
    subscriber_email_addresses = ["test@example.com"]
  }
}

Create a budget for $100.

resource "aws_budgets_budget" "cost" {
  # ...
  budget_type  = "COST"
  limit_amount = "100"
  limit_unit   = "USD"
}

Create a budget with planned budget limits.

resource "aws_budgets_budget" "cost" {
  # ...

  planned_limit {
    start_time = "2017-07-01_00:00"
    amount     = "100"
    unit       = "USD"
  }

  planned_limit {
    start_time = "2017-08-01_00:00"
    amount     = "200"
    unit       = "USD"
  }
}

Create a budget for s3 with a limit of 3 GB of storage.

resource "aws_budgets_budget" "s3" {
  # ...
  budget_type  = "USAGE"
  limit_amount = "3"
  limit_unit   = "GB"
}

Create a Savings Plan Utilization Budget

resource "aws_budgets_budget" "savings_plan_utilization" {
  # ...
  budget_type  = "SAVINGS_PLANS_UTILIZATION"
  limit_amount = "100.0"
  limit_unit   = "PERCENTAGE"

  cost_types {
    include_credit             = false
    include_discount           = false
    include_other_subscription = false
    include_recurring          = false
    include_refund             = false
    include_subscription       = true
    include_support            = false
    include_tax                = false
    include_upfront            = false
    use_blended                = false
  }
}

Create a RI Utilization Budget

resource "aws_budgets_budget" "ri_utilization" {
  # ...
  budget_type  = "RI_UTILIZATION"
  limit_amount = "100.0" # RI utilization must be 100
  limit_unit   = "PERCENTAGE"

  #Cost types must be defined for RI budgets because the settings conflict with the defaults
  cost_types {
    include_credit             = false
    include_discount           = false
    include_other_subscription = false
    include_recurring          = false
    include_refund             = false
    include_subscription       = true
    include_support            = false
    include_tax                = false
    include_upfront            = false
    use_blended                = false
  }

  # RI Utilization plans require a service cost filter to be set
  cost_filter {
    name = "Service"
    values = [
      "Amazon Relational Database Service",
    ]
  }
}

Create a Cost Filter using Resource Tags

resource "aws_budgets_budget" "cost" {
  # ...
  cost_filter {
    name = "TagKeyValue"
    values = [
      "TagKey$TagValue",
    ]
  }
}

Create a cost_filter using resource tags, obtaining the tag value from a terraform variable

resource "aws_budgets_budget" "cost" {
  # ...
  cost_filter {
    name = "TagKeyValue"
    values = [
      "TagKey${"$"}${var.TagValue}"
    ]
  }
}

Argument Reference

For more detailed documentation about each argument, refer to the AWS official documentation.

This argument supports the following arguments:

Attribute Reference

This resource exports the following attributes in addition to the arguments above:

Auto Adjust Data

The parameters that determine the budget amount for an auto-adjusting budget.

auto_adjust_type (Required) - The string that defines whether your budget auto-adjusts based on historical or forecasted data. Valid values: FORECAST,HISTORICAL historical_options (Optional) - Configuration block of Historical Options. Required for auto_adjust_type of HISTORICAL Configuration block that defines the historical data that your auto-adjusting budget is based on. last_auto_adjust_time (Optional) - The last time that your budget was auto-adjusted.

Historical Options

budget_adjustment_period (Required) - The number of budget periods included in the moving-average calculation that determines your auto-adjusted budget amount. lookback_available_periods (Optional) - The integer that describes how many budget periods in your BudgetAdjustmentPeriod are included in the calculation of your current budget limit. If the first budget period in your BudgetAdjustmentPeriod has no cost data, then that budget period isn’t included in the average that determines your budget limit. You can’t set your own LookBackAvailablePeriods. The value is automatically calculated from the budget_adjustment_period and your historical cost data.

Cost Types

Valid keys for cost_types parameter.

Refer to AWS CostTypes documentation for further detail.

Cost Filter

Based on your choice of budget type, you can choose one or more of the available budget filters.

Refer to AWS CostFilter documentation for further detail.

Budget Notification

Valid keys for notification parameter.

Planned Budget Limits

Valid keys for planned_limit parameter.

Import

In Terraform v1.5.0 and later, use an import block to import budgets using AccountID:BudgetName. For example:

import {
  to = aws_budgets_budget.myBudget
  id = "123456789012:myBudget"
}

Using terraform import, import budgets using AccountID:BudgetName. For example:

% terraform import aws_budgets_budget.myBudget 123456789012:myBudget