How to have multiple tags with terraform

Hi All,

I am new to terraform and still learning in Process i want to build something like where for my resource i want to have multiple tags some via names and some via for loop, is that something possible or i am doing something wrong

image

I keep getting this error

I think you are almost there:

tags  = merge({
  "Name" : "${var.vpcname}-PrivateRoute-Table"
}, var.common_tags)

I hope you are planning to do something like this.

Hi ramsateesh,

No,Actually i have a separate map variable that i want to display along with my Name Tag

image

@shubhammer The solution provided would give you the desired output. What you need to do is merge your common tags with the name tag to produce a new map containing both.

@christopher.avila Thanks for the reply, Still the same error

image

Your syntax isn’t right.

{ for key, value in var.Common_tags : key=>value} is redundant and should be replaced by just using var.Common_tags directly because var.Common_tags is already a map. What you’ve written would produce something like

tags_all = {
  {
    Name = "some-vm-name"
    Createdy_By = "Terraform
    Department = "Staging"
  }
}

What you want would be something more like

tags_all = merge({ Name = var.vmname }, var.Common_tags)

Because var.Common_tags is already a map, this is the same as writing

tags_all = merge({ Name = var.vmname }, { Created_by = "Terraform", Department = "Staging" })

which is the same as writing

tags_all = {
  Name = var.vmname
  Created_by = "Terraform"
  Department = "Staging"
}

Which I believe is what you want.