Skip to content
This repository has been archived by the owner on Oct 8, 2020. It is now read-only.

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

Open
hashibot opened this issue Jul 4, 2017 · 1 comment
Labels

Comments

@hashibot
Copy link

hashibot commented Jul 4, 2017

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 👍

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

@landro
Copy link

landro commented May 29, 2018

Quick confirmation - I'm seeing this issue as well

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants