Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot pass a list of maps to a resource/data #7705

Closed
wr0ngway opened this issue Jul 19, 2016 · 11 comments
Closed

Cannot pass a list of maps to a resource/data #7705

wr0ngway opened this issue Jul 19, 2016 · 11 comments
Milestone

Comments

@wr0ngway
Copy link

wr0ngway commented Jul 19, 2016

Terraform Version

Terraform v0.7.0-rc3 (3f4857a)

Affected Resource(s)

  • core

Terraform Configuration Files

// Works for a single map, does not work for a list of maps

variable "vars" {
  type = "map"
  default = {
    foo = "bar"
  }
}

data "template_file" "file" {
  template = "foo=${foo}"
  vars = "${var.vars}"
}

output "output" {
  value = "${data.template_file.file.rendered}"
}

variable "parts" {
  type = "list"
  default = [
    {
      content_type = "text/x-shellscript"
      content      = "ls"
    },
    {
      content_type = "text/x-shellscript"
      content      = "echo hi"
    }
  ]
}

data "template_cloudinit_config" "config" {
  gzip = false
  base64_encode = false

  part = "${var.parts}"
}

output "output" {
  value = "${data.template_cloudinit_config.config.rendered}"
}

Debug Output

https://gist.github.com/dd910b4bdb9b2cbe03850080ff218ca9

Panic Output

N/A

Expected Behavior

Literal list of maps should work as a parameter to a resource or data source that takes a list of maps. The example uses a data source for ease in duplication, but the same error is seen when passing to a resource, e.g. aws_db_parameter_group.parameter

Actual Behavior

The resource doesn't see each map as a valid object:

Errors:

  * data.template_cloudinit_config.config: part.0: expected object, got invalid
  * data.template_cloudinit_config.config: part.1: expected object, got invalid

Steps to Reproduce

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

  1. terraform apply

Important Factoids

N/A

References

@otakup0pe
Copy link

Any updates on this? I ask only because of the release-0.7 tag with 0.7.3 being out and no traffic on this issue 👼

@queensengineer
Copy link

For example I could this to solve the variable number of listeners for an aws_elb ...

This looks good

output "output" {
value = "${var.listOfListenerObjects}"
}

but

resource "aws_elb" "elb" {
provider = "aws"
.
.
listener = ["${var.listOfListenerObjects}"]
}

gives listener.0: expected object, but got string

@kaii-zen
Copy link

Hitting the same issue with 0.9.1. This would be super useful!

@eredi93
Copy link

eredi93 commented Mar 23, 2017

+1

4 similar comments
@kwach
Copy link

kwach commented Apr 21, 2017

+1

@anthonyjoubert
Copy link

+1

@savar
Copy link

savar commented May 10, 2017

+1

@eredi93
Copy link

eredi93 commented May 10, 2017

👍

@apparentlymart
Copy link
Contributor

Hi all!

Thanks for reporting this, @wr0ngway. This is one of a number of quirks with more complex data structures in Terraform right now, resulting from the fact that Terraform originally didn't support such structures at all and so the current state is a pragmatic intermediate step to allow simple use-cases to be addressed. We are planning to further improve the situation around complex structures, including looking at whether we can find a way to support dynamic generation of nested configuration blocks from variables, but we're not currently actively working on implementing this since things are still in the early design phase.

Since this discussion seems to just be attracting upvotes at this point, I'm going to lock it to remove the noise for the many people who are following this issue. We'll unlock it again later when things are further along and we have more to discuss here.

Thanks again!

@apparentlymart
Copy link
Contributor

Hi all! Sorry for the long silence here; some outdated labeling on this issue caused me to miss it on a previous pass.

This issue is actually covering the same problem as #7034, which has now been resolved in master with the introduction of the special dynamic block type, which I showed an example of in a comment over there. This will be included in the forthcoming v0.12.0 release, so I'm going to close this out.

@apparentlymart apparentlymart added this to the v0.12.0 milestone Nov 6, 2018
keirbadger pushed a commit to mergermarket/terraform-acuris-ecs-task-definition that referenced this issue Dec 5, 2019
For some cases and workloads we need to pass some modules to the task
definition. The volumes are passed as a list of maps to the
ecs_task_resource[1].

But the current syntax of terraform does not allow consume this value
directly from a variable. Trying to do so, we hit the issues described
in [2] and [3] (pending to report a specific bug).

But we found out that it works if we build the map structure directly
within the resource, and we use interpolation to consume the values of
the map.

Meanwhile the terraform project does not provide a definitive solution,
we will implement the following workaround:

 - The module will receive configuration for one unique module, being
   the default a empty map {}
 - If the map is empty, a dummy volume will be passed as `name=dummy`
   and `host_path=/tmp/dummy_volume`

This would cover our specific case in the short term, and can be later
easily adapted to use a optional list of volumes.

[1] https://www.terraform.io/docs/providers/aws/r/ecs_task_definition.html#volume
[2] hashicorp/terraform#10407
[3] hashicorp/terraform#7705 (comment)
@ghost
Copy link

ghost commented Mar 31, 2020

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.

@ghost ghost locked and limited conversation to collaborators Mar 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests