Cost Explorer Integration

Prerequisites

  • AWS account with Billing console access
  • Cost allocation tags enabled
  • Terraform >= 1.0

Step 1: Define Cost Allocation Tags

module "cost_tags" {
  source  = "registry.patterneddesigns.ca/standardnat/tagging-policy/aws"
  version = "1.1.0"

  required_tags = [
    "CostCenter",
    "Project",
    "Team",
    "Environment"
  ]

  default_tags = {
    ManagedBy  = "terraform"
    BillingOrg = "engineering"
  }

  enforce_lowercase = true
}

provider "aws" {
  default_tags {
    tags = module.cost_tags.merged_tags
  }
}

Step 2: Activate Cost Allocation Tags

  1. Navigate to AWS Billing Console
  2. Go to Cost Allocation Tags
  3. Select the tags to activate:
    • CostCenter
    • Project
    • Team
    • Environment

Step 3: Create Cost Explorer Report

  1. Open AWS Cost Explorer
  2. Create a new report grouped by tag
  3. Select the cost allocation tags
  4. Save the report for future use

Step 4: Set Up Budget Alerts

resource "aws_budgets_budget" "team_budget" {
  name         = "team-monthly-budget"
  budget_type  = "COST"
  limit_amount = "1000"
  limit_unit   = "USD"
  time_unit    = "MONTHLY"

  cost_filter {
    name   = "TagKeyValue"
    values = ["user:Team$platform-team"]
  }

  notification {
    comparison_operator = "GREATER_THAN"
    threshold           = 80
    threshold_type      = "PERCENTAGE"
    notification_type   = "FORECASTED"
  }
}

Step 5: Verify Cost Data

After 24-48 hours, verify cost data appears correctly grouped by tags in Cost Explorer.