What are advantages and disadvantages of Cloud Computing
October 3, 2018
Difference between Office365 vs Office 2019 and why Office365 is best
October 10, 2018

How to tag AWS resources efficiently and effectively

What is a Tag?

A tag is a label that you assign to an AWS or any cloud resource. Each tag consists of a key and an optional value, both of which you define.

Why tagging is important?

Tags enable us to categorize the AWS resources in different ways, for example, by project, team, or environment. This is useful when we have many resources of the same type. We can use tags to organize our AWS bill to reflect own cost structure.  For more information about setting up a cost allocation report with tags, see The Monthly Cost Allocation Report in AWS Billing and Cost Management User Guide. For Azure & Google resources, the same feature is available so that, you can see the costs of particular resources as per their tags.

1. Effective tagging using Terraform:

By using the locals. See Terraform documentation here for more information.

This is supported from Terraform version 0.10.3.

In your single variables.tf define locals

# Define the common tags for all resources
locals {
  common_tags = {
    project   = "ecommerce-app"
    environment = "production"
  }
}

And use above in all the resources you create.

Ex.

# Create a resource that blends the common tags with instance-specific tags.
resource "aws_instance" "server" {
  ami           = "ami-123456"
  instance_type = "t2.micro"

  tags = "${merge(
    local.common_tags,
    map(
      "name", "App-server",
      "team", "database"
    )
  )}"
}

In the above code, extra resource specific values can be added apart from common values.

This is how you can define all the common tags at a single point and use them everywhere. If something is needed to be changed, you can do it at a single place and it gets applied at all the calling locations.

If you are using the cloudformation, then there is no way to define the tags at single locations, but via variables, you can pass them at use it.
To know how to validate and debug the cloud formation template please refer the post Validate and debug the cloud formation template.

2. Using Tag Editor in AWS Console

When you have to tag very large number of AWS resources and you don’t have cloud formation or Terraform templates available for it then, this is the best method so far.
With Tag Editor,
1. You can search for the resources that you want to tag, and then add, remove, or edit tags for the resources in your search results.
2. You can view the tags of all the selected resources at a single place.

To start Tag Editor:

  • Sign in to the AWS Management Console.
  • On the navigation bar, choose Resource Groups, and then choose Tag Editor.
  • Choose Region
  • For Resource types, choose the kind of resources that you want to locate. To search for all resource types or all regions, select All resource types.

Finding Untagged Resources:

Its useful to know what resources in your account have yet to be tagged and also want to know what resources have tag keys but no tag values.

You can use Tag Editor to find these resources.

  • Sign in to the AWS Management Console.
  • On the navigation bar, choose Resource Groups, and then choose Tag Editor.
  • Choose Region
  • For Tags, select a tag key that you want to apply to resources that do not already have it.
  • Choose Find Resources to have Tag Editor find all such resources and list them at the bottom of the page.
  • Next click button, “Create a new tag key” and type the name of the tag you want to search
Not tagged resources

               Not tagged resources

Bitnami