Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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}")}"
like image 656
Justin Avatar asked Feb 03 '26 00:02

Justin


1 Answers

In Terraform > 0.12 this can be done as:

tags = merge(tomap({
    Name = var.name,
    Env  = var.environment,
    AutoSnapshot = var.auto_snapshot }),
    var.tags,
)
like image 196
Costas Avatar answered Feb 04 '26 14:02

Costas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!