Skip to main content

How to Add Default Tags

Background

As part of keeping track of our infrastructure we can add default tags to AWS providers, this will mean that at if people forget to add tags that at least we can have a few basic tags such as this resource was created in terraform.

New tag: business-unit has been introduced org-wide for cost allocation for better reporting.

This will need to be applied as a default tag to all MP accounts (including member accounts).

How to Add Default Tags

To add default tags to AWS providers, you can use the following Terraform code:

provider "aws" {
  region = "eu-west-2"
  default_tags {
    tags = { tags = local.tags
    }
  }
}

by simply adding default_tags { tags = { tags = local.tags } to your provider blocks. This will add the tags to all resources created by that provider.

Important Note on Modules

When adding default tags, it’s important to ensure they are applied consistently across all resources, including those created by modules. While default tags are reflected in the tags_all value for locally-created resources during a Terraform plan, this may not always be the case for resources created by modules.

For example, when using the modernisation-platform-terraform-ecs-cluster module, removing the tags {} variable did not result in the default tags being applied automatically.

Recommendation

To ensure default tags are applied consistently, you can take a light-touch approach by adding the default_tags {} block to the provider statements and referencing the local tags within it. This ensures that all resources, including those created by modules, inherit the default tags.

This page was last reviewed on 20 March 2025. It needs to be reviewed again on 20 September 2025 by the page owner #modernisation-platform .
This page was set to be reviewed before 20 September 2025 by the page owner #modernisation-platform. This might mean the content is out of date.