tftag icon indicating copy to clipboard operation
tftag copied to clipboard

A DRY approach to tagging Terraform resources

tftag

Release GitHub release (latest SemVer) GitHub commits since latest release (by SemVer) Go Reference

A DRY approach to tagging Terraform resources

Supported Terraform providers:

Brew

To install tftag using brew, simply do the below.

brew tap bschaatsbergen/tftag
brew install tftag

Binaries

You can download the latest binary for Linux, MacOS, and Windows.

Examples

Using tftag is very simple.

Create a .tftag.hcl

tftag "all" {
  tags = {
    Pine = "Apple",
  }
}

tftag "developers" {
  tags = {
    Straw = "Berry",
  }
}

Optionally apply a filter on a resource

resource "aws_s3_bucket" "users" {
  bucket = "users-bucket"
}

resource "aws_sns_topic" "user_updates" {
  #tftag:developers
  name = "user-updates-topic"
}

Run tftag

$ tftag
INFO[0000] Tagged `aws_s3_bucket.users` in main.tf
INFO[0000] Tagged `aws_sns_topic.user_updates` in main.tf

Your resources are updated

resource "aws_s3_bucket" "users" {
  bucket = "users-bucket"
  tags = {
    Pine  = "Apple"
    Straw = "Berry"
  }
}

resource "aws_sns_topic" "user_updates" {
  #tftag:developers
  name = "user-updates-topic"
  tags = {
    Straw = "Berry"
  }
}

Contributing

Contributions are highly appreciated and always welcome. Have a look through existing Issues and Pull Requests that you could help with.