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

Passing Lists as Template Variables #71

Open
voroniys opened this issue Sep 13, 2019 · 2 comments
Open

Passing Lists as Template Variables #71

voroniys opened this issue Sep 13, 2019 · 2 comments

Comments

@voroniys
Copy link

Hi there,

Thank you for opening an issue. Please note that we try to keep the Terraform issue tracker reserved for bug reports and feature requests. For general usage questions, please see: https://www.terraform.io/community.html.

Terraform Version

Terraform v0.12.8

  • provider.aws v2.27.0
  • provider.template v2.1.2

Affected Resource(s)

Please list the resources as a list, for example:
template_file

Terraform Configuration Files

data "template_file" "kops_config" {
  template = file("${path.module}/config.tpl")
  vars     = {
    aws_account_id     = data.aws_caller_identity.current.account_id
    availability_zones = data.aws_availability_zones.available.names
  }
}

Debug Output

Error: Incorrect attribute value type

on kops_config.tf line 3, in data "template_file" "config":
3: vars = {

Inappropriate value for attribute "vars": element "availability_zones": string
required.

Expected Behavior

Since in templates %{for } loops now possible I would expect there is a way to pass the list to template as variable

Actual Behavior

List is not accepted as string is required

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform apply

References

This is kind of re-openning of #40 since there was nothing done to fix this issue.

@apparentlymart
Copy link
Contributor

Hi @voroniys,

Since you are using Terraform 0.12 you can use the templatefile built-in function instead of this data source. The data source continues to exist primarily to support Terraform 0.11 users and provides no significant advantages for 0.12 users. In fact, it has disadvantages like this one specifically because it is built around Terraform 0.11 limitations.

@xM8WVqaG
Copy link

@apparentlymart Although the OP's example suggests this functionality for the template_file data source - the templatefile function workaround isn't appropriate for workflows that have to use the template_dir resource that's also part of this provider.

Usecase: Populating a directory of yaml files for consumption in Kubernetes that currently have every IP address and image tag set as individual variables.

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

No branches or pull requests

3 participants