Code Monkey home page Code Monkey logo

terraform-aws-cost-billing-alarm's Introduction

drawing
leverage

AWS Billing Cloudwatch Alarm terraform module: terraform-aws-cost-mgmt-billing-alarm

Adds a billing alert with optional sns topic creation (or use a pre-existing one) to alert when a U$S (currency actually configurable) billing threshold is reached.

If aws_sns_topic_enabled = true then you'll still need to subscribe to the created SNS topic manually (please check Important Consderations section for detailed info).

Releases

Requirements

Name Version
terraform >= 0.12.28
aws >= 2.70.0

Providers

Name Version
aws >= 2.70.0

Inputs

Name Description Type Default Required
aws_account_id AWS account id string "" no
aws_env AWS environment you are deploying to. Will be appended to SNS topic and alarm name. (e.g. dev, stage, prod) string n/a yes
aws_sns_topic_arn If aws_sns_topic_enabled = false, then an existing AWS SNS topic ARN for the billing alert integration will be used string "" no
currency Short notation for currency type (e.g. USD, CAD, EUR) string "USD" no
monthly_billing_threshold The threshold for which estimated monthly charges will trigger the metric alarm. string n/a yes
tags A mapping of tags to assign to all resources map(string) {} no

Outputs

Name Description
sns_topic_arn SNS Topic ARN to be subscribed to in order to delivery the clodwatch billing alarms

The module outputs one block, sns_topic. Access it like this:

output "sns_topic" {
  value = "${module.billing_alert.sns_topic}"
}

Examples

For an specific account

cloudwatch-billing-alert-to-new-sns-with-acct-id

module "billing_alert" {
  source = "billtrust/billing-alarm/aws"

  aws_env = "${var.aws_profile}"
  aws_account_id = 111111111111
  monthly_billing_threshold = 500
  currency = "USD"
}

output "sns_topic" {
  value = "${module.billing_alert.sns_topic}"
}
# Will output the following:
# arn:aws:sns:us-east-1:111111111111:billing-alarm-notification-usd-dev for billing alarms

cloudwatch-billing-alert-to-pre-existing-sns-with-acct-id

module "billing_cloudwatch_alert" {
  source = "billtrust/billing-alarm/aws"

  aws_env = "${var.aws_profile}"
  aws_account_id = 111111111111
  monthly_billing_threshold = 500
  currency = "USD"
}

For a consolidated billing account aws-org like approach (or single account)

cloudwatch-billing-alert-to-new-sns-with-consolidated-acct

module "billing_alert" {
  source = "billtrust/billing-alarm/aws"

  aws_env = "${var.aws_profile}"
  monthly_billing_threshold = 500
  currency = "USD"
}

output "sns_topic" {
  value = "${module.billing_alert.sns_topic}"
}
# Will output the following:
# arn:aws:sns:us-east-1:111111111111:billing-alarm-notification-usd-dev for billing alarms

cloudwatch-billing-alert-to-pre-existing-sns-consolidated-acct

module "billing_cloudwatch_alert" {
  source = "billtrust/billing-alarm/aws"

  aws_env = "${var.aws_profile}"
  monthly_billing_threshold = 500
  currency = "USD"
}

Important Considerations

  • This metric is checked every 8 hours, and a single metric sample above the threshold amount will trigger an alarm state. The metric is named billing-alarm-${lower(currency)}-${aws_env}

  • If aws_sns_topic_enabled = true the alarm action is automatically set to the created SNS topic, billing-alarm-notification-${lower(currency)}-${aws_env}. YOU MUST MANUALLY SUBSCRIBE TO THIS SNS TOPIC.

    !! MANUAL STEP : !! Subscribe emails to arn:aws:sns:us-east-1:111111111111:billing-alarm-notification-usd-dev for billing alarms

Binbash Leverage | DevOps Automation Code Library Integration

In order to get the full automated potential of the Binbash Leverage DevOps Automation Code Library
you should initialize all the necessary helper Makefiles.

How?

You must execute the make init-makefiles command at the root context

╭─delivery at delivery-I7567 in ~/terraform/terraform-aws-backup-by-tags on master✔ 20-09-17
╰─⠠⠵ make
Available Commands:
 - init-makefiles     initialize makefiles

Why?

You'll get all the necessary commands to automatically operate this module via a dockerized approach, example shown below

╭─delivery at delivery-I7567 in ~/terraform/terraform-aws-backup-by-tags on master✔ 20-09-17
╰─⠠⠵ make
Available Commands:
 - circleci-validate-config  ## Validate A CircleCI Config (https
 - format-check        ## The terraform fmt is used to rewrite tf conf files to a canonical format and style.
 - format              ## The terraform fmt is used to rewrite tf conf files to a canonical format and style.
 - tf-dir-chmod        ## run chown in ./.terraform to gran that the docker mounted dir has the right permissions
 - version             ## Show terraform version
 - init-makefiles      ## initialize makefiles
╭─delivery at delivery-I7567 in ~/terraform/terraform-aws-backup-by-tags on master✔ 20-09-17
╰─⠠⠵ make format-check
docker run --rm -v /home/delivery/Binbash/repos/Leverage/terraform/terraform-aws-backup-by-tags:"/go/src/project/":rw -v :/config -v /common.config:/common-config/common.config -v ~/.ssh:/root/.ssh -v ~/.gitconfig:/etc/gitconfig -v ~/.aws/bb:/root/.aws/bb -e AWS_SHARED_CREDENTIALS_FILE=/root/.aws/bb/credentials -e AWS_CONFIG_FILE=/root/.aws/bb/config --entrypoint=/bin/terraform -w "/go/src/project/" -it binbash/terraform-awscli-slim:0.12.28 fmt -check

Release Management

CircleCi PR auto-release job

leverage-circleci

terraform-aws-cost-billing-alarm's People

Contributors

exequielrafaela avatar binbashdevops avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.