Skip to content

synapsestudios/terraform-aws-cost-anomaly-monitor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Terraform AWS Cost Anomaly Monitor

A Terraform module to create an AWS Cost Anomaly Monitor.

Pre-requisites

To use this module, you need to ensure the SNS topic you pass contains this statement in it's policy:

data "aws_iam_policy_document" "sns_topic_policy" {
  policy_id = "sns_topic_policy"

  statement {
    sid = "AWSAnomalyDetectionSNSPublishingPermission"

    actions = [
      "SNS:Publish",
    ]

    principals {
      type        = "Service"
      identifiers = ["costalerts.amazonaws.com"]
    }

    resources = [
      aws_sns_topic.example.arn,
    ]
  }
}

Usage

Service

For monintoring spend per provisioned AWS service

module "example" {
    source = "github.com/synapsestudios/terraform-aws-cost-anomaly-monitor"

    threshold = "10"
    environment = "production"
    sns_topic_arn = aws_sns_topic.example.arn

    tags = {
        "ProvisionedBy" = "terraform"
        "Environment"   = "production"
        "Module"        = "terraform-aws-cost-explorer-anomaly-monitor"
    }
}

Account

For monitoring total account spend.

module "example" {
    source = "github.com/synapsestudios/terraform-aws-cost-anomaly-monitor"

    threshold = "5"
    environment = "production"
    sns_topic_arn = aws_sns_topic.example.arn
    type = "account"
    account_list ["012345678901", "012345678901"]

    tags = {
        "ProvisionedBy" = "terraform"
        "Environment"   = "production"
        "Module"        = "terraform-aws-cost-explorer-anomaly-monitor"
    }
}

Resource Graph

Requirements

No requirements.

Providers

Name Version
aws n/a

Modules

No modules.

Resources

Name Type
aws_ce_anomaly_monitor.account resource
aws_ce_anomaly_monitor.service resource
aws_ce_anomaly_subscription.this resource

Inputs

Name Description Type Default Required
account_list List of AWS account numbers to monitor for cost anomalies. Required if using "type" argument list(string) [] no
environment The environment this module is being deployed to string "dev" no
sns_topic_arn The ARN of the SNS topic to send notifications to string n/a yes
tags Tags to apply to all resources created, see internal documentation for tagging standards map(string)
{
"Environment": "dev",
"Module": "terraform-aws-cost-explorer-anomaly-monitor",
"ProvisionedBy": "terraform"
}
no
threshold Value between 0 and 100 representing the percentage of impact to trigger an alert string "10" no
type The type of anomaly to detect for. Requires "account_list" argument. You won't be able to create a linked account monitor using this method from the linked account, the resource must be created in the parent account. string "service" no

Outputs

Name Description
cost_anomaly_subscription_arn n/a