<p>I have a resource task to create nodes in EKS. My problem begin when I'm trying to define some tags according to the value of a specific variable and if not, don't declare the tag. Something like that:</p>
<pre><code>resource &quot;aws_eks_node_group&quot; &quot;managed_workers&quot; {
  for_each = var.nodegroups[terraform.workspace]

  cluster_name    = aws_eks_cluster.cluster.name
  node_group_name = each.value.Name
  node_role_arn   = aws_iam_role.managed_workers.arn
  subnet_ids      = aws_subnet.private.*.id

  tags = merge(
      var.tags[terraform.workspace], {
      
    if somevar = value then
      &quot;topology.kubernetes.io/zone&quot; = &quot;us-east-2a&quot;  &lt;--- THIS TAG IS CONDITIONAL
    fi
      &quot;type&quot; = each.value.type
      &quot;Name&quot; = each.value.Name
      &quot;ob&quot;   = each.value.ob
      &quot;platform&quot; = each.value.platform
  })      

</code></pre>
<p>Is there possible?</p>

<p>Yes, you can do this. For example:</p>
<pre><code>resource &quot;aws_eks_node_group&quot; &quot;managed_workers&quot; {
  for_each = var.nodegroups[terraform.workspace]

  cluster_name    = aws_eks_cluster.cluster.name
  node_group_name = each.value.Name
  node_role_arn   = aws_iam_role.managed_workers.arn
  subnet_ids      = aws_subnet.private.*.id

  tags = merge(
      var.tags[terraform.workspace], {      
      &quot;type&quot; = each.value.type
      &quot;Name&quot; = each.value.Name
      &quot;ob&quot;   = each.value.ob
      &quot;platform&quot; = each.value.platform},
      [somevar == value  ? {&quot;topology.kubernetes.io/zone&quot; = &quot;us-east-2a&quot;} : null]...)
} 
</code></pre>
<p>The <code>...</code> is for <a href="https://www.terraform.io/docs/language/expressions/function-calls.html#expanding-function-arguments" rel="nofollow noreferrer">expanding-function-arguments</a>.</p>
