🐰

TerraformでAWS budgetsを設定する

2024/01/10に公開

概要

  • TerraformをつかってAWS budgetsを設定した時のメモ

コード

  • main.tf
provider "aws" {
    region = "ap-northeast-1"
}

resource "aws_budgets_budget" "total" {
    name         = "sample_budgets"
    budget_type  = "COST"
    limit_amount = "1000"
    limit_unit   = "USD"
    time_unit    = "MONTHLY"

    notification {
        comparison_operator        = "GREATER_THAN"
        threshold                  = 85
        threshold_type             = "PERCENTAGE"
        notification_type          = "FORECASTED"
        subscriber_email_addresses = ["sre@e-mail.com"]
    }
    notification {
        comparison_operator        = "GREATER_THAN"
        threshold                  = 100
        threshold_type             = "PERCENTAGE"
        notification_type          = "FORECASTED"
        subscriber_email_addresses = ["sre@e-mail.com","cto@e-mail.com"]
    }
    notification {
        comparison_operator        = "GREATER_THAN"
        threshold                  = 100
        threshold_type             = "PERCENTAGE"
        notification_type          = "ACTUAL"
        subscriber_email_addresses = ["sre@e-mail.com","cto@e-mail.com","invoice@e-mail.com"]
    }
}

解説

limit_amount : 予算額
limit_unit : 通貨
notification : 複数記載することで段階的な通知ができる
threshold : 閾値
threshold_type  : PERCENTAGEパーセンテージ OR ABSOLUTE_VALUE絶対値
notification_type  : FORECASTED予想 OR ACTUAL実数
subscriber_email_addresses : 通知先、Listなので複数記載可能

  • その他
    • cost_filter を設定すると特定のサービスだけに絞ることも可能

参考

https://kiririmode.hatenablog.jp/entry/20211114/1636873014
https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/budgets_budget.html

Discussion