https://github.com/omers/aws-cost-anomaly-detector
AWS Cost Anomaly Detection Terraform module
https://github.com/omers/aws-cost-anomaly-detector
aws aws-cost-explorer cost-control finops monitoring terraform
Last synced: 6 months ago
JSON representation
AWS Cost Anomaly Detection Terraform module
- Host: GitHub
- URL: https://github.com/omers/aws-cost-anomaly-detector
- Owner: omers
- Created: 2023-07-02T10:21:36.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-04-06T06:36:00.000Z (6 months ago)
- Last Synced: 2025-04-14T22:02:46.729Z (6 months ago)
- Topics: aws, aws-cost-explorer, cost-control, finops, monitoring, terraform
- Language: HCL
- Homepage:
- Size: 34.2 KB
- Stars: 2
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# AWS Cost Anomaly Detector 🚨
## Description
This Terraform module streamlines AWS cost management by automatically setting up AWS Cost Anomaly Detection. It continuously monitors your cloud expenses and instantly alerts you to unexpected cost spikes—helping you optimize your AWS billing, prevent overspending, and maintain tight control over your cloud budget. Whether you're looking to enhance cost monitoring, streamline AWS cost management, or integrate automated cost alerts into your infrastructure, this module is your key to a more predictable and efficient AWS spending strategy.
## Key Features
- **Simple Deployment**: Intuitive and declarative Terraform module for cost anomaly detection.
- **Automated Configuration**: Automatically configures AWS Cost Explorer and anomaly detection settings.
- **Real-time Alerts**: Receive instant notifications for cost anomalies.
- **Cost Optimization**: Gain insights to optimize AWS spending and identify cost-saving opportunities.
- **Scalability**: Supports large-scale AWS environments with ease.## Quick Start
```hcl
terraform {
# Setup yor state backend here.
# Either s3 / local
}module "cost_anomaly_detection" {
source = "github.com/omers/aws-cost-anomaly-detector.git"
region = "us-west-2"
environment = "production"
emails = ["devops@example.com", "finance@example.com"]
raise_amount_percent = "20"
raise_amount_absolute = "100"
# Optional PagerDuty integration
create_pagerduty = true
pagerduty_endpoint = "https://events.pagerduty.com/integration/abcdef123456/enqueue"
resource_tags = {
ManagedBy = "Terraform"
Project = "CostOptimization"
}
}
```## Prerequisites
- Terraform v1.0+
- AWS account with appropriate permissions
- AWS provider v5.6.2 or later## PagerDuty Setup
1. Create a new PagerDuty service with the **Amazon CloudWatch** integration type.
2. Copy the PagerDuty Integration URL to the `pagerduty_endpoint` input variable.
3. Set `create_pagerduty = true` in your module configuration.## Module Documentation
## Requirements
| Name | Version |
|------|---------|
| [aws](#requirement\_aws) | ~> 5.0 |### Providers
| Name | Version |
|------|---------|
| [aws](#provider\_aws) | ~> 5.0 |### Modules
No modules.
### Resources
| Name | Type |
|------|------|
| [aws_ce_anomaly_monitor.anomaly_monitor](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ce_anomaly_monitor) | resource |
| [aws_ce_anomaly_subscription.realtime_subscription](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ce_anomaly_subscription) | resource |
| [aws_sns_topic.cost_anomaly_updates](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sns_topic) | resource |
| [aws_sns_topic_policy.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sns_topic_policy) | resource |
| [aws_sns_topic_subscription.pagerduty](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sns_topic_subscription) | resource |
| [aws_sns_topic_subscription.topic_email_subscription](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sns_topic_subscription) | resource |
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
| [aws_iam_policy_document.sns_topic_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |### Inputs
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| [create\_pagerduty](#input\_create\_pagerduty) | Set to true in order to send notifications to PagerDuty | `bool` | `false` | no |
| [emails](#input\_emails) | List of email addresses to notify | `list(any)` | n/a | yes |
| [environment](#input\_environment) | The account environment (Prod / Dev etc.) | `string` | n/a | yes |
| [pagerduty\_endpoint](#input\_pagerduty\_endpoint) | The PagerDuty HTTPS endpoint where SNS notifications will be sent to | `string` | n/a | yes |
| [raise\_amount\_absolute](#input\_raise\_amount\_absolute) | The Absolut increase in USD to trigger the detector. (ANOMALY\_TOTAL\_IMPACT\_ABSOLUTE) | `string` | n/a | yes |
| [raise\_amount\_percent](#input\_raise\_amount\_percent) | An Expression object used to specify the anomalies that you want to generate alerts for. The precentage service cost increase than the expected | `string` | n/a | yes |
| [region](#input\_region) | AWS Region | `string` | n/a | yes |
| [resource\_tags](#input\_resource\_tags) | Tags to set for all resources | `map(string)` | `{}` | no |### Outputs
| Name | Description |
|------|-------------|
| [sns\_arn](#output\_sns\_arn) | n/a |