Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dsb-norge/tf-mod-azure-consumption-budget-monitoring
Terraform module to create consumption budget with alerting in Azure
https://github.com/dsb-norge/tf-mod-azure-consumption-budget-monitoring
dsb-terraform-module
Last synced: 21 days ago
JSON representation
Terraform module to create consumption budget with alerting in Azure
- Host: GitHub
- URL: https://github.com/dsb-norge/tf-mod-azure-consumption-budget-monitoring
- Owner: dsb-norge
- License: isc
- Created: 2024-05-22T12:55:03.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-11-20T10:04:52.000Z (about 1 month ago)
- Last Synced: 2024-11-20T11:59:40.320Z (about 1 month ago)
- Topics: dsb-terraform-module
- Language: HCL
- Homepage: https://www.dsb.no
- Size: 28.3 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# 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.
```terraform
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.
```terraform
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
```shell
# 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
```shell
# 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](https://semver.org/). Always push tags and add tag annotations.
#### Patch release
Example of patch release `v0.0.4`:
```bash
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`:
```bash
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`.
## Requirements
| Name | Version |
|------|---------|
| [terraform](#requirement\_terraform) | >= 1.8.0, < 2.0.0 |
| [azurerm](#requirement\_azurerm) | >= 3.0.0, < 5.0.0 |## Providers
| Name | Version |
|------|---------|
| [azurerm](#provider\_azurerm) | >= 3.0.0, < 5.0.0 |## Modules
No modules.
## Resources
| Name | Type |
|------|------|
| [azurerm_consumption_budget_subscription.sub_budget_consumption](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/consumption_budget_subscription) | resource |
| [azurerm_cost_anomaly_alert.sub_cost_anomaly_alert](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/cost_anomaly_alert) | resource |
| [azurerm_subscription.current](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/subscription) | data source |## Inputs
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| [app\_short\_name](#input\_app\_short\_name) | Name of app short, used for rg | `string` | n/a | yes |
| [consumption\_budget\_amount](#input\_consumption\_budget\_amount) | The amount of money to be consumed | `number` | n/a | yes |
| [consumption\_budget\_notification\_cfg](#input\_consumption\_budget\_notification\_cfg) | The notification blocks |map(object({|
enabled = optional(bool)
threshold = optional(number)
operator = optional(string)
contact_emails = optional(list(string))
})){| no |
"notification1": {
"enabled": false
}
}
| [consumption\_budget\_time\_grain](#input\_consumption\_budget\_time\_grain) | The time grain for the consumption budget | `string` | `"Monthly"` | no |
| [cost\_anomaly\_alert\_email\_receivers](#input\_cost\_anomaly\_alert\_email\_receivers) | The email addresses to receive cost anomaly alerts | `list(string)` | `[]` | no |
| [environment](#input\_environment) | The runtime environment targeted. Development, test, qa, production etc | `string` | n/a | yes |
| [subscription](#input\_subscription) | The subscription | `string` | n/a | yes |## Outputs
| Name | Description |
|------|-------------|
| [consumption\_budget\_id](#output\_consumption\_budget\_id) | value of the consumption budget id |
| [cost\_anomaly\_alert\_id](#output\_cost\_anomaly\_alert\_id) | value of the cost anomaly alert id |