Skip to content

Examples

This page provides practical examples of how to use Terratags in various scenarios.

Configuration Examples

Basic Required Tags Configuration (YAML)

required_tags:
  - Name
  - Environment
  - Owner
  - Project

Required Tags with Descriptions (YAML)

required_tags:
  - key: Name
    description: "Identifies the resource"
  - key: Environment
    description: "Deployment environment (dev, test, prod)"
  - key: Owner
    description: "Team or individual responsible for the resource"
  - key: Project
    description: "Project or application name"

Exemptions Configuration

exemptions:
  - resource_type: aws_s3_bucket
    resource_name: logs_bucket
    exempt_tags: [Owner, Project]
    reason: "Legacy bucket used for system logs only"

  - resource_type: aws_dynamodb_table
    resource_name: "*"
    exempt_tags: [Environment]
    reason: "DynamoDB tables use environment from provider default_tags"

Terraform Examples

AWS Provider with Default Tags

provider "aws" {
  region = "us-west-2"

  default_tags {
    tags = {
      Environment = "dev"
      Owner       = "team-a"
      Project     = "demo"
    }
  }
}

Resource with Tags

resource "aws_instance" "example" {
  ami           = "ami-12345678"
  instance_type = "t2.micro"

  tags = {
    Name = "example-instance"
    Environment = "production"
    Owner = "team-b"
    Project = "website"
  }
}

Resource with Default Tags

resource "aws_instance" "example" {
  ami           = "ami-12345678"
  instance_type = "t2.micro"

  # Only need to specify Name tag, as other required tags come from default_tags
  tags = {
    Name = "example-instance"
  }
}

Module with Tags

module "vpc" {
  source = "terraform-aws-modules/vpc/aws"
  version = "3.14.0"

  name = "my-vpc"
  cidr = "10.0.0.0/16"

  tags = {
    Name = "my-vpc"
    Environment = "production"
    Owner = "team-b"
    Project = "website"
  }
}

Command Examples

Basic Usage

terratags -config config.yaml -dir ./infra

Generate HTML Report

terratags -config config.yaml -dir ./infra -report report.html

Validate Terraform Plan

terraform plan -out=tfplan
terraform show -json tfplan > plan.json
terratags -config config.yaml -plan plan.json

Show Auto-remediation Suggestions

terratags -config config.yaml -dir ./infra -remediate

Use Exemptions

terratags -config config.yaml -dir ./infra -exemptions exemptions.yaml

Verbose Output

terratags -config config.yaml -dir ./infra -verbose

Additional Resources

For more detailed examples, please check: