terraform-provider-template icon indicating copy to clipboard operation
terraform-provider-template copied to clipboard

Template File's count attribute within a module can't be computed when using interpolation syntax inside a list of map

Open hashibot opened this issue 7 years ago • 1 comments

This issue was originally opened by @YoannMa as hashicorp/terraform#15430. It was migrated here as a result of the provider split. The original body of the issue is below.


Hi,

First, thanks you all for your works :+1:

I encountered a problem when trying to generate commands line from a List of parameters.

My use case is for creating create database commands lines for a MySQL database and using the virtual network address for the host access value for the user. (I can't use the MySQL provider)

Terraform Version

v0.9.9

Terraform Configuration Files

main.tf

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

module "commands" {
  source = "module_commands"

  values = [
    {
      var1 = "test"
      var2 = "${random_id.id.b64}"
    },
    {
      var1 = "test2"
      var2 = "${random_id.id.b64}"
    },
  ]
}

module_commands/main.tf

variable "values" {
  type        = "list"
  description = "List of map"
  default     = []
}

data "template_file" "commands" {
  count = "${length(var.values)}"

  template = <<EOF
  commandtodo $${var1} $${var2}}
EOF

  vars {
    var1 = "${lookup(var.values[count.index], "var1")}"
    var2 = "${lookup(var.values[count.index], "var2")}"
  }
}

output "values" {
  value = "${data.template_file.commands.*.rendered}"
}

Debug Output

https://gist.github.com/YoannMa/b200742d79638898cb68041608d5dd13

Expected Behavior

Compute the count value

Actual Behavior

Couldn't compute the count value

Steps to Reproduce

terraform plan or terraform apply

hashibot avatar Jul 04 '17 17:07 hashibot

Quick confirmation - I'm seeing this issue as well

landro avatar May 29 '18 08:05 landro