Terraform: Cannot interpolate tag key name

Created on 21 Jan 2017  ยท  5Comments  ยท  Source: hashicorp/terraform

Terraform Version

v0.8.5-dev

Affected Resource(s)

  • tags
  • probably core, since it's interpolation

Terraform Configuration Files

resource "random_id" "tag_key" {
  byte_length = "16"
}

resource "random_id" "tag_value" {
  byte_length = "32"
}

resource "aws_instance" "server" {
  count = "${var.servers}"

  ami           = "${data.aws_ami.ubuntu-1404.id}"
  instance_type = "r3.large"
  key_name      = "${aws_key_pair.lab.id}"

  subnet_id              = "${element(aws_subnet.lab.*.id, count.index)}"
  vpc_security_group_ids = ["${aws_security_group.lab.id}"]

  tags {
    "${random_id.tag_key.hex}" = "${random_id.tag_value.hex}"
  }
}

Expected Behavior

Instance should be created with tags from the values of random_id.

Actual Behavior

The tag is created as (literally) ${random_id.tag_key.hex}, and the value is empty.

Steps to Reproduce

  1. terraform apply
config enhancement

Most helpful comment

This is fixed in Terraform 0.12 (beta) slash HCL2

All 5 comments

screen shot 2017-01-20 at 6 04 10 pm

Hey @sethvargo!

Agreed that this ought to work the way you wrote it, but I think you should be able to work around it by using some more awkward syntax:

tags = "${map(random_id.tag_key.hex, random_id.tag_value.hex)}"

I didn't actually test this so maybe there's something else that'll break there but I think that should work.

This is fixed in Terraform 0.12 (beta) slash HCL2

I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings