Skip to content

Terraform module to create consumption budget with alerting in Azure

License

Notifications You must be signed in to change notification settings

dsb-norge/tf-mod-azure-consumption-budget-monitoring

Repository files navigation

tf-mod-azure-consumption-budget-monitoring

Terraform module to create consumption budget with alerting in Azure.

Usage

Basic example

Example with minimum set of input parameters.

provider "azurerm" {
  features {}
}
module "consumption_budget" {
  source = "[email protected]:dsb-norge/tf-mod-azure-consumption-budget-monitoring.git?ref=v0"

  app_short_name                      = "my-azure-app"
  subscription                        = "my-subscription-name"
  environment                         = "production"
  consumption_budget_amount           = "9000" # in local currency of subscription location
}

Full example

Example with all possible set of input parameters.

provider "azurerm" {
  features {}
}
module "consumption_budget" {
  source = "[email protected]:dsb-norge/tf-mod-azure-consumption-budget-monitoring.git?ref=v0"

  app_short_name                      = "my-azure-app"
  subscription                        = "my-subscription-name"
  environment                         = "production"
  consumption_budget_amount           = "9000" # in local currency of subscription location
  consumption_budget_time_grain       = "Monthly"
  consumption_budget_notification_cfg = {
    "80_percent_consumed" = {
      contact_emails = [
        "[email protected]",
        "[email protected]",
      ]
    }
  }

  cost_anomaly_alert_email_receivers = [
    "[email protected]",
    "[email protected]",
  ]
}

Development

Validate your code

  # Init project, run fmt and validate
  terraform init -reconfigure
  terraform fmt -check -recursive
  terraform validate

  # Lint with TFLint, calling script from https://github.com/dsb-norge/terraform-tflint-wrappers
  alias lint='curl -s https://raw.githubusercontent.com/dsb-norge/terraform-tflint-wrappers/main/tflint_linux.sh | bash -s --'
  lint

Generate and inject terraform-docs in README.md

# go1.17+
go install github.com/terraform-docs/[email protected]
export PATH=$PATH:$(go env GOPATH)/bin
terraform-docs markdown table --output-file README.md .

Release

After merge of PR to main use tags to release.

Use semantic versioning, see semver.org. Always push tags and add tag annotations.

Patch release

Example of patch release v0.0.4:

git checkout origin/main
git pull origin main
git tag --sort=-creatordate | head -n 5 # review latest release tag to determine which is the next one
git log v0..HEAD --pretty=format:"%s"   # output changes since last release
git tag -a 'v0.0.4'  # add patch tag, add change description
git tag -f -a 'v0.0' # move the minor tag, amend the change description
git tag -f -a 'v0'   # move the major tag, amend the change description
git push origin 'refs/tags/v0.0.4'  # push the new tag
git push -f origin 'refs/tags/v0.0' # force push moved tags
git push -f origin 'refs/tags/v0'   # force push moved tags

Major release

Same as patch release except that the major version tag is a new one. I.e. we do not need to force tag/push.

Example of major release v1.0.0:

git checkout origin/main
git pull origin main
git tag --sort=-creatordate | head -n 5 # review latest release tag to determine which is the next one
git log v0..HEAD --pretty=format:"%s"   # output changes since last release
git tag -a 'v1.0.0'  # add patch tag, add your change description
git tag -a 'v1.0'    # add minor tag, add your change description
git tag -a 'v0'      # add major tag, add your change description
git push --tags      # push the new tags

Note: If you are having problems pulling main after a release, try to force fetch the tags: git fetch --tags -f.

Below is a placeholder for Terraform-docs generated documentation. Do not edit between the delimiters.

Requirements

Name Version
terraform >= 1.8.0, < 2.0.0
azurerm >= 3.0.0, < 5.0.0

Providers

Name Version
azurerm >= 3.0.0, < 5.0.0

Modules

No modules.

Resources

Name Type
azurerm_consumption_budget_subscription.sub_budget_consumption resource
azurerm_cost_anomaly_alert.sub_cost_anomaly_alert resource
azurerm_subscription.current data source

Inputs

Name Description Type Default Required
app_short_name Name of app short, used for rg string n/a yes
consumption_budget_amount The amount of money to be consumed number n/a yes
consumption_budget_notification_cfg The notification blocks
map(object({
enabled = optional(bool)
threshold = optional(number)
operator = optional(string)
contact_emails = optional(list(string))
}))
{
"notification1": {
"enabled": false
}
}
no
consumption_budget_time_grain The time grain for the consumption budget string "Monthly" no
cost_anomaly_alert_email_receivers The email addresses to receive cost anomaly alerts list(string) [] no
environment The runtime environment targeted. Development, test, qa, production etc string n/a yes
subscription The subscription string n/a yes

Outputs

Name Description
consumption_budget_id value of the consumption budget id
cost_anomaly_alert_id value of the cost anomaly alert id

About

Terraform module to create consumption budget with alerting in Azure

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages