# Add default tags in sub-modules

**URL:** <https://discuss.hashicorp.com/t/add-default-tags-in-sub-modules/42528>\
**Category:** Terraform\
**Created:** [July 27, 2022, 11:10pm UTC](https://discuss.hashicorp.com/t/add-default-tags-in-sub-modules/42528 "2022-07-27T23:10:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![schollii](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/schollii/32/16958_2.png) [@schollii](https://discuss.hashicorp.com/u/schollii)\
**Post date:** [July 27, 2022, 11:10pm UTC](https://discuss.hashicorp.com/t/add-default-tags-in-sub-modules/42528/1 "2022-07-27T23:10:15Z")

</div>

I’ve been using the `default_tags` of aws provider for a while, super practical and saves so much code. I noticed that many submodules I write have all resources add the same tags to the default tags, by setting them in the `tags` property of the resource.

So I’m wondering if there is a way for a submodule to “extend” the parent’s aws provider that it inherits, with additional default tags, so that I could remove the `tags` property form almost every resource of every submodule.

Sounds like defining provider aliases in submodule is anti pattern, so approach of adding an aws provider block in submodule is no-go.

So the only other way I see is to define additional providers in the root module. But

1. this is a fair bit of work: if your root module uses N submodules which each use M sub-submodules, you need N\*M provider aliases!
2. this seems to violate treating modules as black boxes: a submodule should be able to “customize” what it inherits (at least in terms of tags), without affecting the parent; a root module should not know details of a submodule.

Which technically means submodules should have their own providers, with syntax on each provider to specify whether it should inherit from one of the “passed in” providers, or be a “clean slate”.

Is there a better solution?

---

<div class="post-metadata">

**Author:** ![apparentlymart](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/apparentlymart/32/702_2.png) [@apparentlymart](https://discuss.hashicorp.com/u/apparentlymart)\
**Post date:** [August 17, 2022, 12:15am UTC](https://discuss.hashicorp.com/t/add-default-tags-in-sub-modules/42528/2 "2022-08-17T00:15:00Z")

</div>

Hi @schollii,

I can’t think of any way other than what you’ve already considered. Since `default_tags` is a property of the provider configuration, the only way to vary it between resources would be to declare multiple provider configurations.

For legacy reasons it is technically possible to declare a separate `provider "aws"` block inside a module, but I would not recommend doing so because if you ever want to remove the module from your configuration you’ll get into a tricky mess where you need to somehow avoid removing both the resources and the provider configuration at the same time, or else Terraform won’t have the configuration necessary to destroy the resources. We continue to support this really only for backward compatibility with very old modules that predate the ability to explicitly pass provider configuration from a parent module into a child module.
