# How to tag an instance's eni?

**URL:** <https://discuss.hashicorp.com/t/how-to-tag-an-instances-eni/15357>\
**Category:** AWS\
**Created:** [October 9, 2020, 3:10pm UTC](https://discuss.hashicorp.com/t/how-to-tag-an-instances-eni/15357 "2020-10-09T15:10:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulrowlands](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/paulrowlands/32/12611_2.png) [@paulrowlands](https://discuss.hashicorp.com/u/paulrowlands)\
**Post date:** [October 9, 2020, 3:10pm UTC](https://discuss.hashicorp.com/t/how-to-tag-an-instances-eni/15357/1 "2020-10-09T15:10:00Z")

</div>

When I create an instance or an LB it automatically creates an eni network interface for it behind the scenes.

Is there a way to get at that to tag it?

I see that for aws\_instances with EBS volumes there’s a “volume\_tags” option to propagate the tags but I don’t see anything for network interfaces.

I suppose I could get artistic and create a dummy resource with a provisioner which executes an AWS CLI call against the resource’s “primary\_network\_interface\_id” output, but that seems a bit of a stretch…

---

<div class="post-metadata">

**Author:** ![paulrowlands](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/paulrowlands/32/12611_2.png) [@paulrowlands](https://discuss.hashicorp.com/u/paulrowlands)\
**Post date:** [October 9, 2020, 3:22pm UTC](https://discuss.hashicorp.com/t/how-to-tag-an-instances-eni/15357/2 "2020-10-09T15:22:21Z")

</div>

Well, of course I found out how to do it immediately after posing the question…

```
resource "aws_ec2_tag" "ecs_node_eni" {
  resource_id = aws_instance.ecs_node.primary_network_interface_id
  key = "Name"       
  value = var.tags["Name"]
}
```

---

<div class="post-metadata">

**Author:** ![paulrowlands](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/paulrowlands/32/12611_2.png) [@paulrowlands](https://discuss.hashicorp.com/u/paulrowlands)\
**Post date:** [October 9, 2020, 3:23pm UTC](https://discuss.hashicorp.com/t/how-to-tag-an-instances-eni/15357/3 "2020-10-09T15:23:20Z")

</div>

Presumably I could step through the tags with a for\_each to get all of them included.

---

<div class="post-metadata">

**Author:** ![paulrowlands](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/paulrowlands/32/12611_2.png) [@paulrowlands](https://discuss.hashicorp.com/u/paulrowlands)\
**Post date:** [October 9, 2020, 3:30pm UTC](https://discuss.hashicorp.com/t/how-to-tag-an-instances-eni/15357/4 "2020-10-09T15:30:23Z")

</div>

yep.

```
resource "aws_ec2_tag" "ecs_node_eni" {
  resource_id = aws_instance.ecs_node.primary_network_interface_id
  for_each = var.tags
  key = each.key
  value = each.value
}
```

---

<div class="post-metadata">

**Author:** ![kpatel](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/kpatel/32/25825_2.png) [@kpatel](https://discuss.hashicorp.com/u/kpatel)\
**Post date:** [October 11, 2022, 4:37pm UTC](https://discuss.hashicorp.com/t/how-to-tag-an-instances-eni/15357/5 "2022-10-11T16:37:23Z")

</div>

In my case I have 3 instance which I am creating using count so in aws\_ec2\_tag I am using count to get resource\_id for each resources. when I use for\_each for tagging those 3 instances ENI I am getting error say that `The "count" and "for_each" meta-arguments are mutually-exclusive, only one should be used to be explicit about the number of resources to be created.` . How can I tackle this problem?.

Here is my code

```auto
resource "aws_ec2_tag" "ecs_node_eni" {
  count = local.instance_count
  resource_id = aws_instance.ecs_node[count.index].primary_network_interface_id
  for_each = var.tags
  key = each.key
  value = each.value
}

```

---

<div class="post-metadata">

**Author:** ![paulrowlands](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/paulrowlands/32/12611_2.png) [@paulrowlands](https://discuss.hashicorp.com/u/paulrowlands)\
**Post date:** [October 11, 2022, 5:17pm UTC](https://discuss.hashicorp.com/t/how-to-tag-an-instances-eni/15357/6 "2022-10-11T17:17:39Z")

</div>

A quick&easy solution could be to build a local variable to encompass the two, something along the lines of this (sorry, I’m not at a terminal)

locals {  
instance\_tags = for\_each = … {  
\<instance\_id\> = var.tags

}

}

---

<div class="post-metadata">

**Author:** ![kpatel](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/kpatel/32/25825_2.png) [@kpatel](https://discuss.hashicorp.com/u/kpatel)\
**Post date:** [October 13, 2022, 3:01pm UTC](https://discuss.hashicorp.com/t/how-to-tag-an-instances-eni/15357/7 "2022-10-13T15:01:57Z")

</div>

Apologize but I do not understand your code line. Can you write it in proper format?
