https://github.com/getindata/terraform-aws-budget
Terraform module to manage AWS Budgets
https://github.com/getindata/terraform-aws-budget
Last synced: 5 months ago
JSON representation
Terraform module to manage AWS Budgets
- Host: GitHub
- URL: https://github.com/getindata/terraform-aws-budget
- Owner: getindata
- License: apache-2.0
- Created: 2022-08-12T11:56:46.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-10-20T12:36:27.000Z (over 2 years ago)
- Last Synced: 2025-01-24T02:30:33.068Z (over 1 year ago)
- Language: HCL
- Size: 94.7 KB
- Stars: 2
- Watchers: 7
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Terraform AWS Budget




We help companies turn their data into assets
---
This terraform module creates and manages multiple AWS budgets for single AWS Account.
It makes use of submodules, placed in `./modules` directory, to create the resources.
## USAGE
```terraform
module "aws_budgets" {
source = "github.com/getindata/terraform-aws-budget"
context = module.this.context
budgets = {
default = {
limit_amount = 100
}
}
default_notifications = {
default-actual-100 = {
comparison_operator = "GREATER_THAN"
threshold = 100
threshold_type = "PERCENTAGE"
notification_type = "ACTUAL"
subscriber_email_addresses = []
}
}
default_email_addresses = ["aws@example.com"]
```
## NOTES
This module uses a specific `budgets` object for configurations - below paragraph describes it in detail:
```terraform
```
{
BUDGET-NAME = {
# Optional
budget_type # - Whether this budget tracks monetary cost or usage. Availiable options: 'COST', 'USAGE', 'SAVINGS_PLANS_UTILIZATION', 'RI_UTILIZATION'."
time_period_start # - The start of the time period covered by the budget. If you don't specify a start date, AWS defaults to the start of your chosen time period. The start date must come before the end date. Format: 2017-01-01_12:00
time_period_end # - The end of the time period covered by the budget. There are no restrictions on the end date. Format: 2017-01-01_12:00
name # - Budget name (if omitted, map key, BUDGET-NAME will be used)
time_unit # -The length of time until a budget resets the actual and forecasted spend. Valid values: MONTHLY, QUARTERLY, ANNUALLY, and DAILY
extra_email_addresses # - List containing email addresses that will receive all notifications
cost filters # - A list of CostFilter name/values pair to apply to budget
[
{
name string # - A list of CostFilter name/values pair to apply to budget
value = list(string) # - Refer to AWS CostFilter documentation for further detail.
}
]
notifications # - A map of objects containing Budget Notifications
{
NOTIFICATION-NAME = {
comparison_operator # - Comparison operator to use to evaluate the condition. Can be LESS_THAN, EQUAL_TO or GREATER_THAN.
threshold # - Threshold when the notification should be sent.
threshold_type # - What kind of threshold is defined. Can be PERCENTAGE OR ABSOLUTE_VALUE.
notification_type # - What kind of budget value to notify on. Can be ACTUAL or FORECASTED.
subscriber_email_addresses # - E-Mail addresses to notify.
},
}
extra_notifications # - A map of objects containing Additional Budget Notifications (will be combined with var.default_notifications)
{
ADDITIONAL-NOTIFICATION-NAME = {
comparison_operator # - Comparison operator to use to evaluate the condition. Can be LESS_THAN, EQUAL_TO or GREATER_THAN.
threshold # - Threshold when the notification should be sent.
threshold_type # - What kind of threshold is defined. Can be PERCENTAGE OR ABSOLUTE_VALUE.
notification_type # - What kind of budget value to notify on. Can be ACTUAL or FORECASTED.
subscriber_email_addresses # - E-Mail addresses to notify.
},
}
cost_types # - A map containing CostTypes The types of cost included in a budget, such as tax and subscriptions.
{
include_credit # - A boolean value whether to include credits in the cost budget. Defaults to true
include_discount # - Specifies whether a budget includes discounts. Defaults to true
include_other_subscription # - A boolean value whether to include other subscription costs in the cost budget. Defaults to true
include_recurring # - A boolean value whether to include recurring costs in the cost budget. Defaults to true
include_refund # - A boolean value whether to include refunds in the cost budget. Defaults to true
include_subscription # - A boolean value whether to include subscriptions in the cost budget. Defaults to true
include_support # - A boolean value whether to include support costs in the cost budget. Defaults to true
include_tax # - A boolean value whether to include tax in the cost budget. Defaults to true
include_upfront # - A boolean value whether to include upfront costs in the cost budget. Defaults to true
use_amortized # - Specifies whether a budget uses the amortized rate. Defaults to false
use_blended # - A boolean value whether to use blended costs in the cost budget. Defaults to false
}
# Required
limit_amount # - The amount of cost or usage being measured for a budget
}
}
```
```
## EXAMPLES
```hcl
module "aws_budgets" {
source = "../../"
context = module.this.context
budgets = {
custom-notifications = {
budget_type = "COST"
limit_amount = 1000
time_period_start = "2017-01-01_12:00"
time_period_end = "2017-02-01_12:00"
time_unit = "MONTHLY"
cost_filters = [
{
name = "AZ"
value = ["eu-central-1b"]
},
]
cost_types = {
include_tax = false
}
notifications = {
test = {
comparison_operator = "GREATER_THAN"
notification_type = "ACTUAL"
subscriber_email_addresses = ["test@example.com"]
threshold = 80
threshold_type = "PERCENTAGE"
},
}
},
extra-notifications = {
budget_type = "COST"
limit_amount = 100
time_unit = "DAILY"
extra_notifications = {
extra = {
comparison_operator = "GREATER_THAN"
notification_type = "ACTUAL"
subscriber_email_addresses = ["test@example.com"]
threshold = 50
threshold_type = "PERCENTAGE"
},
}
},
default-notifications = {
budget_type = "COST"
limit_amount = 1000
time_period_start = "2017-01-01_12:00"
time_period_end = "2017-02-01_12:00"
time_unit = "MONTHLY"
extra_email_addresses = ["product_owner@example.com"]
cost_filters = [
{
name = "AZ"
value = ["eu-central-1b"]
},
]
},
minimal-example = {
limit_amount = 1000
}
}
default_notifications = {
default-forcast-100 = {
comparison_operator : "GREATER_THAN"
threshold : 100
threshold_type : "PERCENTAGE"
notification_type : "FORECASTED"
subscriber_email_addresses : []
},
default-actual-80 = {
comparison_operator : "GREATER_THAN"
threshold : 80
threshold_type : "PERCENTAGE"
notification_type : "ACTUAL"
subscriber_email_addresses : []
},
default-actual-100 = {
comparison_operator : "GREATER_THAN"
threshold : 100
threshold_type : "PERCENTAGE"
notification_type : "ACTUAL"
subscriber_email_addresses : []
}
}
default_email_addresses = ["aws@example.com"]
}
```
## Inputs
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| [additional\_tag\_map](#input\_additional\_tag\_map) | Additional key-value pairs to add to each map in `tags_as_list_of_maps`. Not added to `tags` or `id`.
This is for some rare cases where resources want additional configuration of tags
and therefore take a list of maps with tag key, value, and additional configuration. | `map(string)` | `{}` | no |
| [attributes](#input\_attributes) | ID element. Additional attributes (e.g. `workers` or `cluster`) to add to `id`,
in the order they appear in the list. New attributes are appended to the
end of the list. The elements of the list are joined by the `delimiter`
and treated as a single ID element. | `list(string)` | `[]` | no |
| [budgets](#input\_budgets) | A map of 'aws-budget' configuration objects:
{
BUDGET-NAME = {
# Optional
budget_type # - Whether this budget tracks monetary cost or usage. Availiable options: 'COST', 'USAGE', 'SAVINGS_PLANS_UTILIZATION', 'RI_UTILIZATION'."
time_period_start # - The start of the time period covered by the budget. If you don't specify a start date, AWS defaults to the start of your chosen time period. The start date must come before the end date. Format: 2017-01-01_12:00
time_period_end # - The end of the time period covered by the budget. There are no restrictions on the end date. Format: 2017-01-01_12:00
name # - Budget name (if omitted, map key, BUDGET-NAME will be used)
time_unit # -The length of time until a budget resets the actual and forecasted spend. Valid values: MONTHLY, QUARTERLY, ANNUALLY, and DAILY
extra_email_addresses # - List containing email addresses that will receive all notifications
cost filters # - A list of CostFilter name/values pair to apply to budget
[
{
name string # - A list of CostFilter name/values pair to apply to budget
value = list(string) # - Refer to AWS CostFilter documentation for further detail.
}
]
notifications # - A map of objects containing Budget Notifications
{
NOTIFICATION-NAME = {
comparison_operator # - Comparison operator to use to evaluate the condition. Can be LESS_THAN, EQUAL_TO or GREATER_THAN.
threshold # - Threshold when the notification should be sent.
threshold_type # - What kind of threshold is defined. Can be PERCENTAGE OR ABSOLUTE_VALUE.
notification_type # - What kind of budget value to notify on. Can be ACTUAL or FORECASTED.
subscriber_email_addresses # - E-Mail addresses to notify.
},
}
extra_notifications # - A map of objects containing Additional Budget Notifications (will be combined with var.default_notifications)
{
ADDITIONAL-NOTIFICATION-NAME = {
comparison_operator # - Comparison operator to use to evaluate the condition. Can be LESS_THAN, EQUAL_TO or GREATER_THAN.
threshold # - Threshold when the notification should be sent.
threshold_type # - What kind of threshold is defined. Can be PERCENTAGE OR ABSOLUTE_VALUE.
notification_type # - What kind of budget value to notify on. Can be ACTUAL or FORECASTED.
subscriber_email_addresses # - E-Mail addresses to notify.
},
}
cost_types # - A map containing CostTypes The types of cost included in a budget, such as tax and subscriptions.
{
include_credit # - A boolean value whether to include credits in the cost budget. Defaults to true
include_discount # - Specifies whether a budget includes discounts. Defaults to true
include_other_subscription # - A boolean value whether to include other subscription costs in the cost budget. Defaults to true
include_recurring # - A boolean value whether to include recurring costs in the cost budget. Defaults to true
include_refund # - A boolean value whether to include refunds in the cost budget. Defaults to true
include_subscription # - A boolean value whether to include subscriptions in the cost budget. Defaults to true
include_support # - A boolean value whether to include support costs in the cost budget. Defaults to true
include_tax # - A boolean value whether to include tax in the cost budget. Defaults to true
include_upfront # - A boolean value whether to include upfront costs in the cost budget. Defaults to true
use_amortized # - Specifies whether a budget uses the amortized rate. Defaults to false
use_blended # - A boolean value whether to use blended costs in the cost budget. Defaults to false
}
# Required
limit_amount # - The amount of cost or usage being measured for a budget
}
}Example with fully configurable notifications (not using var.default\_notifications):terraform
{
test-budget = {
budget_type = "COST"
limit_amount = 1000
time_period_start = "2017-01-01_12:00"
time_period_end = "2017-02-01_12:00"
time_unit = "MONTHLY"
extra_email_addresses = ["product_owner@example.com"]
cost_filters = [
{
name = "AZ"
value = "eu-central-1b"
},
]
notifications = {
test = {
comparison_operator = "GREATER_THAN"
notification_type = "ACTUAL"
subscriber_email_addresses = ["test@example.com"]
threshold = 80
threshold_type = "PERCENTAGE"
},
}
},
}
Example additional notifications:terraform
{
test-budget = {
budget_type = "COST"
limit_amount = 1000
time_period_start = "2017-01-01_12:00"
time_period_end = "2017-02-01_12:00"
time_unit = "MONTHLY"
extra_email_addresses = ["product_owner@example.com"]
cost_filters = [
{
name = "AZ"
value = "eu-central-1b"
},
]
extra_notifications = {
extra = {
comparison_operator = "GREATER_THAN"
notification_type = "ACTUAL"
subscriber_email_addresses = ["test-extra@example.com"]
threshold = 80
threshold_type = "PERCENTAGE"
},
}
},
}
Example with only default notifications:terraform
{
test-budget = {
budget_type = "COST"
limit_amount = 1000
time_period_start = "2017-01-01_12:00"
time_period_end = "2017-02-01_12:00"
time_unit = "MONTHLY"
extra_email_addresses = ["product_owner@example.com"]
cost_filters = [
{
name = "AZ"
value = "eu-central-1b"
},
]
},
}
| `any` | n/a | yes |
| [context](#input\_context) | Single object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables as `null` to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional\_tag\_map, which are merged. | `any` | {
"additional_tag_map": {},
"attributes": [],
"delimiter": null,
"descriptor_formats": {},
"enabled": true,
"environment": null,
"id_length_limit": null,
"label_key_case": null,
"label_order": [],
"label_value_case": null,
"labels_as_tags": [
"unset"
],
"name": null,
"namespace": null,
"regex_replace_chars": null,
"stage": null,
"tags": {},
"tenant": null
} | no |
| [default\_email\_addresses](#input\_default\_email\_addresses) | A list of default e-mail addresses that will receive all notifications | `list(string)` | `[]` | no |
| [default\_notifications](#input\_default\_notifications) | Configuration of default notifications
map(object({
comparison\_operator = string
threshold = number
threshold\_type = string
notification\_type = string
subscriber\_email\_addresses = list(string)
})) | map(object({
comparison_operator = string
threshold = number
threshold_type = string
notification_type = string
subscriber_email_addresses = list(string)
})) | `{}` | no |
| [delimiter](#input\_delimiter) | Delimiter to be used between ID elements.
Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
| [descriptor\_formats](#input\_descriptor\_formats) | Describe additional descriptors to be output in the `descriptors` output map.
Map of maps. Keys are names of descriptors. Values are maps of the form
`{
format = string
labels = list(string)
}`
(Type is `any` so the map values can later be enhanced to provide additional options.)
`format` is a Terraform format string to be passed to the `format()` function.
`labels` is a list of labels, in order, to pass to `format()` function.
Label values will be normalized before being passed to `format()` so they will be
identical to how they appear in `id`.
Default is `{}` (`descriptors` output will be empty). | `any` | `{}` | no |
| [enabled](#input\_enabled) | Set to false to prevent the module from creating any resources | `bool` | `null` | no |
| [environment](#input\_environment) | ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no |
| [id\_length\_limit](#input\_id\_length\_limit) | Limit `id` to this many characters (minimum 6).
Set to `0` for unlimited length.
Set to `null` for keep the existing setting, which defaults to `0`.
Does not affect `id_full`. | `number` | `null` | no |
| [label\_key\_case](#input\_label\_key\_case) | Controls the letter case of the `tags` keys (label names) for tags generated by this module.
Does not affect keys of tags passed in via the `tags` input.
Possible values: `lower`, `title`, `upper`.
Default value: `title`. | `string` | `null` | no |
| [label\_order](#input\_label\_order) | The order in which the labels (ID elements) appear in the `id`.
Defaults to ["namespace", "environment", "stage", "name", "attributes"].
You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present. | `list(string)` | `null` | no |
| [label\_value\_case](#input\_label\_value\_case) | Controls the letter case of ID elements (labels) as included in `id`,
set as tag values, and output by this module individually.
Does not affect values of tags passed in via the `tags` input.
Possible values: `lower`, `title`, `upper` and `none` (no transformation).
Set this to `title` and set `delimiter` to `""` to yield Pascal Case IDs.
Default value: `lower`. | `string` | `null` | no |
| [labels\_as\_tags](#input\_labels\_as\_tags) | Set of labels (ID elements) to include as tags in the `tags` output.
Default is to include all labels.
Tags with empty values will not be included in the `tags` output.
Set to `[]` to suppress all generated tags.
**Notes:**
The value of the `name` tag, if included, will be the `id`, not the `name`.
Unlike other `null-label` inputs, the initial setting of `labels_as_tags` cannot be
changed in later chained modules. Attempts to change it will be silently ignored. | `set(string)` | [
"default"
]
| no |
| [name](#input\_name) | ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.
This is the only ID element not also included as a `tag`.
The "name" tag is set to the full `id` string. There is no tag with the value of the `name` input. | `string` | `null` | no |
| [namespace](#input\_namespace) | ID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally unique | `string` | `null` | no |
| [regex\_replace\_chars](#input\_regex\_replace\_chars) | Terraform regular expression (regex) string.
Characters matching the regex will be removed from the ID elements.
If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no |
| [stage](#input\_stage) | ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no |
| [tags](#input\_tags) | Additional tags (e.g. `{'BusinessUnit': 'XYZ'}`).
Neither the tag keys nor the tag values will be modified by this module. | `map(string)` | `{}` | no |
| [tenant](#input\_tenant) | ID element \_(Rarely used, not included by default)\_. A customer identifier, indicating who this instance of a resource is for | `string` | `null` | no |
## Modules
| Name | Source | Version |
|------|--------|---------|
| [aws\_budget](#module\_aws\_budget) | ./modules/budget | n/a |
| [this](#module\_this) | cloudposse/label/null | 0.25.0 |
## Outputs
| Name | Description |
|------|-------------|
| [budgets](#output\_budgets) | Map of budgets configuration |
## Providers
No providers.
## Requirements
| Name | Version |
|------|---------|
| [terraform](#requirement\_terraform) | >= 1.3.0 |
## Resources
No resources.
## CONTRIBUTING
Contributions are very welcomed!
Start by reviewing [contribution guide](CONTRIBUTING.md) and our [code of conduct](CODE_OF_CONDUCT.md). After that, start coding and ship your changes by creating a new PR.
## LICENSE
Apache 2 Licensed. See [LICENSE](LICENSE) for full details.
## AUTHORS
Made with [contrib.rocks](https://contrib.rocks).