Skip to content

azurermConsumptionBudgetSubscription

Manages a Subscription Consumption Budget.

Example Usage

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as azurerm from "./.gen/providers/azurerm";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: azurerm.
For a more precise conversion please use the --provider flag in convert.*/
const azurermResourceGroupExample = new azurerm.resourceGroup.ResourceGroup(
  this,
  "example",
  {
    location: "eastus",
    name: "example",
  }
);
const dataAzurermSubscriptionCurrent =
  new azurerm.dataAzurermSubscription.DataAzurermSubscription(
    this,
    "current",
    {}
  );
const azurermMonitorActionGroupExample =
  new azurerm.monitorActionGroup.MonitorActionGroup(this, "example_2", {
    name: "example",
    resource_group_name: azurermResourceGroupExample.name,
    short_name: "example",
  });
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermMonitorActionGroupExample.overrideLogicalId("example");
const azurermConsumptionBudgetSubscriptionExample =
  new azurerm.consumptionBudgetSubscription.ConsumptionBudgetSubscription(
    this,
    "example_3",
    {
      amount: 1000,
      filter: [
        {
          dimension: [
            {
              name: "ResourceGroupName",
              values: [azurermResourceGroupExample.name],
            },
          ],
          tag: [
            {
              name: "foo",
              values: ["bar", "baz"],
            },
          ],
        },
      ],
      name: "example",
      notification: [
        {
          contact_emails: ["foo@example.com", "bar@example.com"],
          contact_groups: [azurermMonitorActionGroupExample.id],
          contact_roles: ["Owner"],
          enabled: true,
          operator: "EqualTo",
          threshold: 90,
        },
        {
          contact_emails: ["foo@example.com", "bar@example.com"],
          enabled: false,
          operator: "GreaterThan",
          threshold: 100,
          threshold_type: "Forecasted",
        },
      ],
      subscription_id: dataAzurermSubscriptionCurrent.id,
      time_grain: "Monthly",
      time_period: [
        {
          end_date: "2022-07-01T00:00:00Z",
          start_date: "2022-06-01T00:00:00Z",
        },
      ],
    }
  );
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermConsumptionBudgetSubscriptionExample.overrideLogicalId("example");

Arguments Reference

The following arguments are supported:

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

  • subscriptionId - (Required) The ID of the Subscription for which to create a Consumption Budget. Changing this forces a new resource to be created.

\~> NOTE: The subscriptionId property can accept a subscription ID e.g. 00000000000000000000000000000000 or the subscription resource ID e.g. /subscriptions/00000000000000000000000000000000. In version 3.0 this property will only accept the subscription resource ID.

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

  • timeGrain - (Optional) The time covered by a budget. Tracking of the amount will be reset based on the time grain. Must be one of billingAnnual, billingMonth, billingQuarter, annually, monthly and quarterly. Defaults to monthly. Changing this forces a new resource to be created.

  • timePeriod - (Required) A timePeriod 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. This is deprecated as the API no longer supports it and will be removed in version 4.0 of the provider.


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.

  • thresholdType - (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.

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

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

  • contactRoles - (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? Defaults to true.

\~> NOTE: A notification block cannot have all of contactEmails, contactRoles, and contactGroups 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, subscriptionId, subscriptionName, 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 timePeriod block supports the following:

  • startDate - (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.

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

Attributes Reference

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

  • id - The ID of the Subscription Consumption Budget.

  • etag - (Optional) The ETag of the Subscription Consumption Budget.

Timeouts

The timeouts block allows you to specify timeouts for certain actions:

  • create - (Defaults to 30 minutes) Used when creating the Subscription Consumption Budget.
  • read - (Defaults to 5 minutes) Used when retrieving the Subscription Consumption Budget.
  • update - (Defaults to 30 minutes) Used when updating the Subscription Consumption Budget.
  • delete - (Defaults to 30 minutes) Used when deleting the Subscription Consumption Budget.

Import

Subscription Consumption Budgets can be imported using the resourceId, e.g.

terraform import azurerm_consumption_budget_subscription.example /subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Consumption/budgets/subscription1