# Module - Variable Tags

**URL:** <https://discuss.hashicorp.com/t/module-variable-tags/21657>\
**Category:** Terraform\
**Created:** [March 3, 2021, 10:39pm UTC](https://discuss.hashicorp.com/t/module-variable-tags/21657 "2021-03-03T22:39:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![stevenjw0228001](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/stevenjw0228001/32/6911_2.png) [@stevenjw0228001](https://discuss.hashicorp.com/u/stevenjw0228001)\
**Post date:** [March 3, 2021, 10:39pm UTC](https://discuss.hashicorp.com/t/module-variable-tags/21657/1 "2021-03-03T22:39:38Z")

</div>

Looking on how to accomplish variable tags for reusable modules. Cant seem to find any good documentation on how to accomplish this.

---

<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:** [March 3, 2021, 11:43pm UTC](https://discuss.hashicorp.com/t/module-variable-tags/21657/2 "2021-03-03T23:43:28Z")

</div>

Hi @stevenjw0228001,

Unfortunately I’m not sure what you mean by “variable tags”. It would help if you could describe what you want to achieve in some more detail, ideally including some things you might’ve tried or considered so far, even if they didn’t work out, because that at least helps put your goals in context and gives a starting point for approaches that might work.

---

<div class="post-metadata">

**Author:** ![jbouse](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/jbouse/32/17520_2.png) [@jbouse](https://discuss.hashicorp.com/u/jbouse)\
**Post date:** [March 4, 2021, 3:09am UTC](https://discuss.hashicorp.com/t/module-variable-tags/21657/3 "2021-03-04T03:09:26Z")

</div>

I’m in agreement with @apparentlymart in not being quite sure what you mean by “variable tags” but I can share how I have my modules utilize tags if that helps and serves as a basis to start from.

In most all of my modules, I insure that a `ManagedBy` tag is created and set it to `Terraform` but also wanting to allow for customizable additional tags to be added as I write them to be used to work as a template I use the following pattern in my module code for any resource I wish to tag.

```auto
  tags = merge(
    var.additional_tags,
    {
      ManagedBy = "Terraform"
    },
  )

```

I then just have the definition for `additional_tags` as:

```auto
variable "additional_tags" {
  type = map(string)
  description = "A mapping of additional resource tags"
  default = {}
}

```

This has allowed me to enforce certain tags be present while also being flexible enough to support additional custom tags.

---

<div class="post-metadata">

**Author:** ![stevenjw0228001](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/stevenjw0228001/32/6911_2.png) [@stevenjw0228001](https://discuss.hashicorp.com/u/stevenjw0228001)\
**Post date:** [March 4, 2021, 2:51pm UTC](https://discuss.hashicorp.com/t/module-variable-tags/21657/4 "2021-03-04T14:51:01Z")

</div>

If I build a module for EC2 and I want to always Tag my instance with certain keys that I will be changing per instance deployment, how do you go about that?

---

<div class="post-metadata">

**Author:** ![ohmer](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/ohmer/32/17491_2.png) [@ohmer](https://discuss.hashicorp.com/u/ohmer)\
**Post date:** [March 4, 2021, 11:11pm UTC](https://discuss.hashicorp.com/t/module-variable-tags/21657/5 "2021-03-04T23:11:29Z")

</div>

You might be coming from CloudFormation which adds some tags without writing anything in the template. Terraform does not have an equivalent “automatic tagging” feature.

You have to add tags yourself explicitly.  
The use of the function `merge` as described by @jbouse is one method.  
There is also a more recent alternative for EC2 resources, an independant `ec2_tag` resource. See [https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ec2\_tag](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ec2_tag)
