https://stackoverflow.com/questions/48460316/terraform-take-parameter-name-from-variable
According to this comment, dynamic variable names are not possible at this time in HCL.
You can use zipmap to emulate this, though it's a bit of a clunky workaround;
locals {
ec2_tag_keys = ["Name", "Group", "${var.vault_tag_name}"]
ec2_tag_vals = ["${var.name}", "${var.group_tag}", "${var.vault_tag_value}"]
}
resource "aws_instance", "instance" {
...
tags = "${zipmap(local.ec2_tag_keys, local.ec2_tag_vals)}"
}
Result;
+ aws_instance.instance
tags.%: "3"
tags.Group: "MyGroup"
tags.Name: "MyName"
tags.MyTagName: "MyTagValue"