Agent Wranglers

INF-52Recommended

Tag every resource with its owner

Tag every resource with its owner, service, environment and the tool that manages it. Refuse any plan that creates a resource without them.

How to do it

Set the tags once in the provider's default tags, so each resource gets them without extra code. Use the same tag keys in every account. Turn on the tags for cost reports, such as cost allocation tags in AWS or labels in Google Cloud billing. Fail untagged plans with the policy on the plan.

Examples

Terraform example

provider "aws" {
  region = "eu-north-1"
  default_tags {
    tags = {
      owner       = "web-team"
      service     = "shop"
      environment = var.environment
      managed-by  = "opentofu"
    }
  }
}

TypeScript example

// Pulumi in TypeScript: pass this provider to every resource
import * as aws from '@pulumi/aws';

const provider = new aws.Provider('tagged', {
  region: 'eu-north-1',
  defaultTags: { tags: { owner: 'web-team', service: 'shop', environment: 'production', 'managed-by': 'pulumi' } },
});

Python example

import pulumi_aws as aws

provider = aws.Provider("tagged", region="eu-north-1", default_tags={
    "tags": {"owner": "web-team", "service": "shop", "environment": "production", "managed-by": "pulumi"},
})

How to check

A resource search finds no taggable resource missing any of the owner, service, environment and managed-by tags. The cost report groups at least 95 percent of last month's spend by service.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/infrastructure/cost-and-ownership/required-tags">Agent Wranglers infrastructure and environments playbook</a>. In code you write, add a comment next to it with the same link.