Skip to content

onka-cloud/module-terraform-aws-budget

 
 

Repository files navigation

License Latest Release Build Status Build Status Build Status Build Status Build Status Build Status Build Status Build Status

AWS Budget Terraform module

Description

This module simplifies budget management by creating an AWS budget resource and providing an intuitive cost visualization feature powered by AWS Cost Explorer.

Why choose this module

  • This module has the following features:
    • Automatic adjustment of cost amounts based on historical averages and forecasted amounts
    • Customizable spending limits
    • Multiple notifications for various thresholds.
  • Easy to set up and use, with clear instructions and examples available.
  • Saves time and resources by automating budget management.
  • Adheres to AWS security standards through the use of checkov, which scans the code to ensure compliance.

Things to Note before using the module

Planned_limit

  • "For the planned limit feature, data must be supplied for the next 12 months if utilizing a monthly projection, or 4 quarters if utilizing a quarterly projection. The start time should be provided in the format YYYY-MM-DD_HH:MM.".
  • The planned limit feature shows an update in place upon doing a second/ subsequent terraform plan or apply

for example

module "budget" {
  source      = "boldlink/budget/aws"
  name        = "planned_limit_budget"
  budget_type = "COST"
  limit_unit  = "USD"
  time_unit   = "MONTHLY"

  planned_limit = [
    {
      start_time = "2023-01-01_00:00"
      amount     = 30
      unit       = "200"
    },

    ## `Other months here`

    {
      start_time = "2023-12-01_00:00"
      amount     = 30
      unit       = "200"
    }
  ]
}

Notification

  • Only one of subscriber_email_addresses or subscriber_sns_topic_arns must be provided.

Auto Adjust Data

  • Enabling this feature overrides any previously set limit amount. This is because when both are specified, Terraform will always detect a change in the next application. This is because when using the auto-adjust feature, the limit amount is determined by the average cost of the provided time period.

Module Examples

Examples are available here

NOTE: These examples utilize the most recent version of this module. To do so, specify the source without including a version number, as demonstrated below.

Getting Started

  • Install the module by running terraform init
  • Configure the module by providing the necessary data in the module block, as shown in the example below.
  • Run terraform apply to create the budget resource.
  • Use the cost visualization feature in AWS Cost Explorer to monitor your account's costs.
module "minimum_example" {
  source            = "boldlink/budget/aws"
  name              = local.name
  budget_type       = "COST"
  limit_amount      = "300"
  limit_unit        = "USD"
  time_unit         = "MONTHLY"
  time_period_start = "2023-01-01_00:00"
  time_period_end   = "2023-02-28_00:00"

  notification = [
    {
      comparison_operator        = "GREATER_THAN"
      threshold                  = 50
      threshold_type             = "PERCENTAGE"
      notification_type          = "ACTUAL"
      subscriber_email_addresses = [local.email]
    }
  ]
}

Documentation

Amazon Budget Documentation

Terraform module documentation

Requirements

Name Version
terraform >= 0.14.11
aws >= 4.45.0

Providers

Name Version
aws 5.23.1

Modules

No modules.

Resources

Name Type
aws_budgets_budget.main resource

Inputs

Name Description Type Default Required
account_id The ID of the target account for budget. Will use current user's account_id by default if omitted number null no
auto_adjust_data The parameters that determine the budget amount for an auto-adjusting budget. any {} no
budget_type Whether this budget tracks monetary cost or usage. Valid values include COST, USAGE, SAVINGS_PLANS_UTILIZATION, RI_UTILIZATION string n/a yes
cost_filter A list of CostFilter name/values pair to apply to budget. RI UtilizatioSn plans require a service cost filter to be set any [] no
cost_types Object containing CostTypes The types of cost included in a budget, such as tax and subscriptions. Cost types must be defined for RI budgets because the settings conflict with the defaults map(string) {} no
limit_amount The amount of cost or usage being measured for a budget. number null no
limit_unit The unit of measurement used for the budget forecast, actual spend, or budget threshold, such as USD or GBP. string null no
name The name of a budget. Unique within accounts. string null no
name_prefix The prefix of the name of a budget. Unique within accounts. string null no
notification Object containing Budget Notifications. any [] no
planned_limit Object containing Budget Notifications. Can be used multiple times to define more than one budget notification. any [] no
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. string null no
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. string null no
time_unit The length of time until a budget resets the actual and forecasted spend. Valid values: MONTHLY, QUARTERLY, ANNUALLY, and DAILY. string n/a yes

Outputs

Name Description
arn The ARN of the budget.
id id of resource.

Third party software

This repository uses third party software:

  • pre-commit - Used to help ensure code and documentation consistency
    • Install with brew install pre-commit
    • Manually use with pre-commit run
  • terraform 0.14.11 For backwards compatibility we are using version 0.14.11 for testing making this the min version tested and without issues with terraform-docs.
  • terraform-docs - Used to generate the Inputs and Outputs sections
    • Install with brew install terraform-docs
    • Manually use via pre-commit
  • tflint - Used to lint the Terraform code
    • Install with brew install tflint
    • Manually use via pre-commit

Supporting resources:

The example stacks are used by BOLDLink developers to validate the modules by building an actual stack on AWS.

Some of the modules have dependencies on other modules (ex. Ec2 instance depends on the VPC module) so we create them first and use data sources on the examples to use the stacks.

Any supporting resources will be available on the tests/supportingResources and the lifecycle is managed by the Makefile targets.

Resources on the tests/supportingResources folder are not intended for demo or actual implementation purposes, and can be used for reference.

Makefile

The makefile contained in this repo is optimized for linux paths and the main purpose is to execute testing for now.

  • Create all tests stacks including any supporting resources:
make tests
  • Clean all tests except existing supporting resources:
make clean
  • Clean supporting resources - this is done separately so you can test your module build/modify/destroy independently.
make cleansupporting
  • !!!DANGER!!! Clean the state files from examples and test/supportingResources - use with CAUTION!!!
make cleanstatefiles

BOLDLink-SIG 2023

About

Terraform registry repository for AWS budget

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Makefile 51.8%
  • HCL 48.2%