dictionarymergeterraformhashmap

Merging maps with variables


Running Terraform v0.11.3 and I am trying to merge two maps into a single map using the merge() function. However I can't get the syntax right. Does merge() support using dynamic variables?

  tags = "${merge({
    Name         = "${var.name}"
    Env          = "${var.environment}"
    AutoSnapshot = "${var.auto_snapshot}"
  }, "${var.tags}")}"

Solution

  • The syntax for merge in TF 0.11 is shown here:

    ${merge(map("a", "b"), map("c", "d"))} 
    

    So in your case, you should have something as follows:

    tags = "${merge(map("Name", var.name,
                        "Env", var.environment,
                        "AutoSnapshot", var.auto_snapshot
                   ), var.tags)}"