Azure Consumption Budget Subscription

This page shows how to write Terraform and Azure Resource Manager for Consumption Budget Subscription and write them securely.

azurerm_consumption_budget_subscription (Terraform)

The Budget Subscription in Consumption can be configured in Terraform with the resource name azurerm_consumption_budget_subscription. The following sections describe 4 examples of how to use the resource and its parameters.

Example Usage from GitHub

main.tf#L73
resource "azurerm_consumption_budget_subscription" "costlimit" {
  name            = "const-limit-budget"
  subscription_id = data.azurerm_subscription.current.subscription_id

  amount     = 500
  time_grain = "Monthly"
budgets.tf#L29
resource "azurerm_consumption_budget_subscription" "total-cost" {
  name            = "budget-total"
  subscription_id = data.azurerm_subscription.current.subscription_id

  amount     = local.azure_budget_gbp
  time_grain = "Monthly"
subscription_budget.tf#L11
resource "azurerm_consumption_budget_subscription" "this" {
  name = azurecaf_name.this_name.result
  subscription_id = coalesce(
    try(var.settings.subscription.id, null),
    try(var.local_combined_resources["subscriptions"][try(var.settings.subscription.lz_key, var.client_config.landingzone_key)][var.settings.subscription.key].subscription_id, null),
    var.client_config.subscription_id
subscription_budget.tf#L11
resource "azurerm_consumption_budget_subscription" "this" {
  name = azurecaf_name.this_name.result
  subscription_id = coalesce(
    try(var.settings.subscription.id, null),
    try(var.local_combined_resources["subscriptions"][try(var.settings.subscription.lz_key, var.client_config.landingzone_key)][var.settings.subscription.key].subscription_id, null),
    var.client_config.subscription_id

Review your Terraform file for Azure best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

The following arguments are supported:

  • name - (Required) The name which should be used for this Subscription Consumption Budget. Changing this forces a new Subscription Consumption Budget to be created.

  • subscription_id - (Required) The ID of the Consumption Budget. Changing this forces a new Subscription Consumption Budget to be created.

  • amount - (Required) The total amount of cost to track with the budget.

  • time_grain - (Required) The time covered by a budget. Tracking of the amount will be reset based on the time grain. Must be one of Monthly, Quarterly, Annually, BillingMonth, BillingQuarter, or BillingYear. Defaults to Monthly.

  • time_period - (Required) A time_period block as defined below.

  • notification - (Required) One or more notification blocks as defined below.

  • filter - (Optional) A filter block as defined below.


A filter block supports the following:

  • dimension - (Optional) One or more dimension blocks as defined below to filter the budget on.

  • tag - (Optional) One or more tag blocks as defined below to filter the budget on.

  • not - (Optional) A not block as defined below to filter the budget on.


A not block supports the following:

  • dimension - (Optional) One dimension block as defined below to filter the budget on. Conflicts with tag.

  • tag - (Optional) One tag block as defined below to filter the budget on. Conflicts with dimension.


A notification block supports the following:

  • operator - (Required) The comparison operator for the notification. Must be one of EqualTo, GreaterThan, or GreaterThanOrEqualTo.

  • threshold - (Required) Threshold value associated with a notification. Notification is sent when the cost exceeded the threshold. It is always percent and has to be between 0 and 1000.

  • threshold_type - (Optional) The type of threshold for the notification. This determines whether the notification is triggered by forecasted costs or actual costs. The allowed values are Actual and Forecasted. Default is Actual. Changing this forces a new resource to be created.

  • contact_emails - (Optional) Specifies a list of email addresses to send the budget notification to when the threshold is exceeded.

  • contact_groups - (Optional) Specifies a list of Action Group IDs to send the budget notification to when the threshold is exceeded.

  • contact_roles - (Optional) Specifies a list of contact roles to send the budget notification to when the threshold is exceeded.

  • enabled - (Optional) Should the notification be enabled?

NOTE: A notification block cannot have all of contact_emails, contact_roles, and contact_groups empty. This means that at least one of the three must be specified.


A dimension block supports the following:

  • name - (Required) The name of the column to use for the filter. The allowed values are ChargeType, Frequency, InvoiceId, Meter, MeterCategory, MeterSubCategory, PartNumber, PricingModel, Product, ProductOrderId, ProductOrderName, PublisherType, ReservationId, ReservationName, ResourceGroupName, ResourceGuid, ResourceId, ResourceLocation, ResourceType, ServiceFamily, ServiceName, UnitOfMeasure.

  • operator - (Optional) The operator to use for comparison. The allowed values are In.

  • values - (Required) Specifies a list of values for the column.


A tag block supports the following:

  • name - (Required) The name of the tag to use for the filter.

  • operator - (Optional) The operator to use for comparison. The allowed values are In.

  • values - (Required) Specifies a list of values for the tag.


A time_period block supports the following:

  • start_date - (Required) The start date for the budget. The start date must be first of the month and should be less than the end date. Budget start date must be on or after June 1, 2017. Future start date should not be more than twelve months. Past start date should be selected within the timegrain period. Changing this forces a new Subscription Consumption Budget to be created.

  • end_date - (Optional) The end date for the budget. If not set this will be 10 years after the start date.

In addition to the Arguments listed above - the following Attributes are exported:

  • id - The ID of the Subscription Consumption Budget.

  • etag - The ETag of the Subscription Consumption Budget.

Explanation in Terraform Registry

Manages a Subscription Consumption Budget.

Microsoft.Consumption/budgets (Azure Resource Manager)

The budgets in Microsoft.Consumption can be configured in Azure Resource Manager with the resource name Microsoft.Consumption/budgets. The following sections describe how to use the resource and its parameters.

Example Usage from GitHub

BudgetsList.json#L13
            "type": "Microsoft.Consumption/budgets",
            "eTag": "\"1d34d012214157f\"",
            "properties": {
              "category": "Cost",
              "amount": 100.65,
              "timeGrain": "Monthly",
CreateOrUpdateBudget.json#L39
        "type": "Microsoft.Consumption/budgets",
        "eTag": "\"1d34d012214157f\"",
        "properties": {
          "category": "Cost",
          "amount": 100.65,
          "timeGrain": "Monthly",
BudgetsList.json#L13
            "type": "Microsoft.Consumption/budgets",
            "eTag": "\"1d34d012214157f\"",
            "properties": {
              "category": "Cost",
              "amount": 100.65,
              "timeGrain": "Monthly",
CreateOrUpdateBudget.json#L39
        "type": "Microsoft.Consumption/budgets",
        "eTag": "\"1d34d012214157f\"",
        "properties": {
          "category": "Cost",
          "amount": 100.65,
          "timeGrain": "Monthly",
BudgetsList.json#L13
            "type": "Microsoft.Consumption/budgets",
            "eTag": "\"1d34d012214157f\"",
            "properties": {
              "category": "Cost",
              "amount": 100.65,
              "timeGrain": "Monthly",
CreateOrUpdateBudget.json#L39
        "type": "Microsoft.Consumption/budgets",
        "eTag": "\"1d34d012214157f\"",
        "properties": {
          "category": "Cost",
          "amount": 100.65,
          "timeGrain": "Monthly",
BudgetsList.json#L13
            "type": "Microsoft.Consumption/budgets",
            "eTag": "\"1d34d012214157f\"",
            "properties": {
              "category": "Cost",
              "amount": 100.65,
              "timeGrain": "Monthly",
CreateOrUpdateBudget.json#L39
        "type": "Microsoft.Consumption/budgets",
        "eTag": "\"1d34d012214157f\"",
        "properties": {
          "category": "Cost",
          "amount": 100.65,
          "timeGrain": "Monthly",
BudgetsList.json#L13
            "type": "Microsoft.Consumption/budgets",
            "eTag": "\"1d34d012214157f\"",
            "properties": {
              "category": "Cost",
              "amount": 100.65,
              "timeGrain": "Monthly",
CreateOrUpdateBudget.json#L39
        "type": "Microsoft.Consumption/budgets",
        "eTag": "\"1d34d012214157f\"",
        "properties": {
          "category": "Cost",
          "amount": 100.65,
          "timeGrain": "Monthly",

Frequently asked questions

What is Azure Consumption Budget Subscription?

Azure Consumption Budget Subscription is a resource for Consumption of Microsoft Azure. Settings can be wrote in Terraform.

Where can I find the example code for the Azure Consumption Budget Subscription?

For Terraform, the acend/terraform-training-env, elliotpryde/personal-infrastructure and pkhuntia/aztfmod source code examples are useful. See the Terraform Example section for further details.

For Azure Resource Manager, the shawns1/shawns1CI, shawns1/shawns1CI and assing/alertExtension source code examples are useful. See the Azure Resource Manager Example section for further details.