Skip to main content

Define Resource Tags Once and Inherit Them Across Stacks

· 3 min read
Erik Osterman
Founder @ Cloud Posse

Copying the same resource tags into every component makes ownership changes tedious and lets environments drift. Two focused examples now show how to define shared tags once and inherit them across stacks: one uses AWS provider default tags, and the other passes tags to Null Label. Each includes a terminal recording and commands you can run locally.

Inherit AWS default tags
 
00:00.0 / 00:00.0

View the AWS default tags example

The Problem​

A tagging example should make it easy to see where shared tags are defined and what each environment receives. Adding an organizational hierarchy, Git metadata, CI conditions, and naming rules at the same time makes that basic behavior harder to follow.

The Fix​

Each example has one shared component configuration and two stacks, dev and prod:

  • AWS provider default tags: both stacks inherit managed-by and owner, then add their own environment tag. Atmos generates the provider configuration, so the S3 resource needs no tags argument.
  • Null Label: both stacks inherit the same tags and supply a stage to the naming module. The module combines the supplied tags with generated Name, Namespace, and Stage tags. A built-in terraform_data resource shows the result without creating cloud resources.

The tagging strategy tutorial builds on these basics with an organizational hierarchy, source-control tag tradeoffs, provider limitations, and AWS enforcement guidance. The shared Terraform code tutorial explains how to distribute common files such as context.tf across components.

How to Use It​

The AWS example describes the merged tags without connecting to AWS:

Copy the example into a new directory and make it your own:

atmos init examples/tagging-default-tags
cd tagging-default-tags
atmos describe component app -s dev --query .providers.aws.default_tags.tags
atmos describe component app -s prod --query .providers.aws.default_tags.tags

The example contains a real S3 bucket component. Planning or applying requires AWS credentials; applying creates a bucket. Provider default tags apply to supported resources, with exceptions such as Auto Scaling groups that need resource-specific tagging configuration.

The Null Label example plans locally without cloud credentials. Its first plan downloads the module:

Pass inherited tags to Null Label
 
00:00.0 / 00:00.0

View the Null Label example

Copy the example into a new directory and make it your own:

atmos init examples/tagging-null-label
cd tagging-null-label
atmos describe component app -s dev --query .vars
atmos terraform plan app -s dev

When applying the resulting map to cloud resources, account for the target provider's tag or label restrictions. Null Label preserves supplied tags; it does not normalize them for each provider.

Get Involved​

Share tagging patterns or suggest another focused example in GitHub Discussions.