# Aws \`default\_tags\` config - module inheritance?

**URL:** <https://discuss.hashicorp.com/t/aws-default-tags-config-module-inheritance/37477>\
**Category:** AWS\
**Created:** [March 23, 2022, 9:03pm UTC](https://discuss.hashicorp.com/t/aws-default-tags-config-module-inheritance/37477 "2022-03-23T21:03:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rjhornsby](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/rjhornsby/32/4886_2.png) [@rjhornsby](https://discuss.hashicorp.com/u/rjhornsby)\
**Post date:** [March 23, 2022, 9:03pm UTC](https://discuss.hashicorp.com/t/aws-default-tags-config-module-inheritance/37477/1 "2022-03-23T21:03:18Z")

</div>

I’m using an in house module to build aws ec2 instances, but I’m running into a weird issue with the aws provider’s `default_tags` feature. I can’t figure out if there’s a bug or I’m doing it wrong.

TL;DR: It looks as if the module must contain its own `provider` + `default_tags` configuration. It isn’t inheriting the `default_tags` from the caller/parent afaict.

The caller/parent has its provider configured thusly, and seems to work fine on resources defined directly in this project:

```auto
provider "aws" {
  region = "us-west-2"
  default_tags {
    tags = {
      created-by: "terraform"
      owned-by: "dept_42"
      terraform-source: "https://some.vcs_url"
    }
  }
}

```

As an example of the behavior in question, this project calls out to a module requesting to build a standardized ec2 instance:

```auto
module "green_instances" {
  source = "/path/to/module/source"
  instance_count = var.instance_count
  ami = {owner: module.base_config.aws_account_owner, id: "ami-123456789a0"}
  # ...a few other parameters here
}

```

The module appears to need to have its own `provider` block with the `default_tags` defined, or it won’t set the tags properly even though they’re defined in the caller’s provider. If the module is not configured as described, Terraform will remove these tags, despite them being declared in the caller’s provider config.

Is this expected behavior? thanks!

---

<div class="post-metadata">

**Author:** ![stuart-c](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/stuart-c/32/10789_2.png) [@stuart-c](https://discuss.hashicorp.com/u/stuart-c)\
**Post date:** [March 24, 2022, 10:59am UTC](https://discuss.hashicorp.com/t/aws-default-tags-config-module-inheritance/37477/2 "2022-03-24T10:59:01Z")

</div>

So are you meaning the module contains a provider block or just the root module?

---

<div class="post-metadata">

**Author:** ![rjhornsby](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/rjhornsby/32/4886_2.png) [@rjhornsby](https://discuss.hashicorp.com/u/rjhornsby)\
**Post date:** [March 24, 2022, 1:56pm UTC](https://discuss.hashicorp.com/t/aws-default-tags-config-module-inheritance/37477/3 "2022-03-24T13:56:34Z")

</div>

The child module must contain a provider block with the `default_tags` or the tags won’t be set on the resources the child module creates, even if the `default_tags` are defined on the root module’s provider.

---

<div class="post-metadata">

**Author:** ![stuart-c](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/stuart-c/32/10789_2.png) [@stuart-c](https://discuss.hashicorp.com/u/stuart-c)\
**Post date:** [March 24, 2022, 4:43pm UTC](https://discuss.hashicorp.com/t/aws-default-tags-config-module-inheritance/37477/4 "2022-03-24T16:43:45Z")

</div>

So you are saying that if there is no provider block at all in the module it seems to not set the default tags?

---

<div class="post-metadata">

**Author:** ![rjhornsby](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/rjhornsby/32/4886_2.png) [@rjhornsby](https://discuss.hashicorp.com/u/rjhornsby)\
**Post date:** [March 24, 2022, 5:45pm UTC](https://discuss.hashicorp.com/t/aws-default-tags-config-module-inheritance/37477/5 "2022-03-24T17:45:46Z")

</div>

correct. this block exists in the root module:

```auto
provider "aws" {
  region = "us-west-2" # not included in child module declaration
  default_tags {
    tags = { ... some tags here ... }
  }
}

```

However, this block must also appear in the child module. If it is removed from the child module, Terraform will remove the associated tags from the resources the child module creates (ec2 instances in my case). The anticipated behavior is configuring the provider once in the root module, and any children would inherit its settings.

---

<div class="post-metadata">

**Author:** ![stuart-c](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/stuart-c/32/10789_2.png) [@stuart-c](https://discuss.hashicorp.com/u/stuart-c)\
**Post date:** [March 24, 2022, 9:21pm UTC](https://discuss.hashicorp.com/t/aws-default-tags-config-module-inheritance/37477/6 "2022-03-24T21:21:40Z")

</div>

So if you have absolutely no provider blocks in the module you are seeing this issue?
