These step-by-step demonstrations walk you through complete workflows using the tagging-policy module. Each demonstration includes prerequisites, detailed instructions, and verification steps.

Getting Started

To follow any demonstration, ensure you have:

  1. Prerequisites met: Terraform >= 1.0, AWS CLI configured
  2. Authenticate with the registry: terraform login registry.patterneddesigns.ca
  3. Clone the demonstration repository: git clone <demo-repo-url>
  4. Follow the step-by-step instructions below

Step-by-Step Guides

Tag Enforcement Setup

Set up organization-wide tag enforcement with AWS Organizations

Prerequisites

  • AWS account with appropriate permissions
  • AWS Organizations enabled (for organization-wide enforcement)
  • Terraform >= 1.0

Step 1: Define the Tagging Policy

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

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

  tag_values = {
    Environment = ["dev", "staging", "prod"]
  }

  default_tags = {
    ManagedBy    = "terraform"
    Organization = "acme-corp"
  }

  enforce_lowercase = true
}

Step 2: Apply Provider Default Tags

Configure the AWS provider to automatically apply tags:

provider "aws" {
  region = "us-east-1"

  default_tags {
    tags = module.org_tags.merged_tags
  }
}

Step 3: Export Validation Rules

Export the validation rules for use in CI/CD pipelines:

output "tag_validation_rules" {
  value       = module.org_tags.validation_rules
  description = "Tag validation rules for policy enforcement"
}

output "required_tags" {
  value       = module.org_tags.required_tag_keys
  description = "List of required tag keys"
}

Step 4: Deploy and Verify

Run terraform apply and verify tags are applied to resources.

terraform apply

# Verify tags on a resource
aws ec2 describe-instances \
  --query "Reservations[].Instances[].Tags" \
  --output table

Cost Explorer Integration

Configure tags for AWS Cost Explorer analysis

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.