hashicorp / terraform

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
https://www.terraform.io/
Other
41.68k stars 9.41k forks source link

Cannot interpolate tag key name #11324

Closed sethvargo closed 5 years ago

sethvargo commented 7 years ago

Terraform Version

v0.8.5-dev

Affected Resource(s)

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
sethvargo commented 7 years ago
screen shot 2017-01-20 at 6 04 10 pm
apparentlymart commented 7 years ago

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.

mvisonneau commented 6 years ago

Related to https://github.com/hashicorp/terraform/issues/14516

sethvargo commented 5 years ago

This is fixed in Terraform 0.12 (beta) slash HCL2

ghost commented 4 years ago

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.