title: terraform: passing list through modules, getting "Error:... should be a list"
body: <p><em>ETA: Found discussion in terraform github issues, <a href="https://github.com/hashicorp/terraform/issues/13103" rel="nofollow noreferrer">https://github.com/hashicorp/terraform/issues/13103</a>. Known and very... "idiosyncratic"... issue.</em></p>
  
  <hr>
  
  <p>After passing a list through two other modules (from <code>top.tf</code> through <code>autoscaling_group</code> to <code>launch_configuration</code>), both of which define the variable as <code>type = "list"</code>, I'm getting the following complaint from <code>terraform plan</code>:</p>
  
  <pre><code>"Error: module.autoscaling_group.aws_launch_configuration.this: 
  security_groups: should be a list"
  </code></pre>
  
  <p>It seems to recognize the parameter as a list type (if I remove the type specification from the variable declaration, it complains). But the only way I find to silence the error is to wrap the final usage in list brackets. This seems counterintuitive (and I haven't seen what happens with <code>apply</code> when I do so) - what's going on?</p>
  
  <hr>
  
  <p>The sequence:</p>
  
  <ul>
  <li><code>top.tf</code> calls <code>security_group</code>.</li>
  <li><code>top.tf</code> also calls <code>autoscaling</code>, passing a list with the security group <code>id</code> output.</li>
  <li><code>autoscaling</code> calls <code>launch_configuration</code>, passing the parameter through.</li>
  </ul>
  
  <p>Here's the layout, contents of .tf files is below.</p>
  
  <pre><code>.
  ├── autoscaling_group
  │   └── main.tf
  ├── launch_configuration
  │   └── main.tf
  ├── security_group
  │   └── main.tf
  └── top.tf
  </code></pre>
  
  <p>The initiating call in <code>top.tf</code> is:</p>
  
  <pre><code>module "autoscaling_group" {
    source = "launch_configuration"
    security_groups = ["${module.security_group.id}"]
    }
  </code></pre>
  
  <p>The offending usage is in <code>launch_configuration/main.tf</code>:</p>
  
  <pre><code>resource "aws_launch_configuration" "this" {
    name_prefix = "foobar"
    image_id = "this_is_fake"
    instance_type = "ts.small"
    security_groups = "${var.security_groups}"
    }
  </code></pre>
  
  <ul>
  <li>If I add brackets: <code>["${var.security_groups}"]</code> I don't get the error.</li>
  <li>If I remove the <code>type = "list"</code> from the variable definition block in <code>launch_configuration/main.tf</code>, <code>terraform plan</code> complains: <code>module.autoscaling_group.var.security_groups: variable security_groups in module autoscaling_group should be type string, got list</code> </li>
  </ul>
  
  <hr>
  
  <p>The content of <code>top.tf</code>:</p>
  
  <pre><code>provider "aws" {
    region = "us-east-1"
    }
  
  module "security_group" {
    source = "security_group"
    }
  
  module "autoscaling_group" {
    source = "launch_configuration"
    security_groups = ["${module.security_group.id}"]
    }
  </code></pre>
  
  <p>The content of <code>autoscaling_group/main.tf</code>:</p>
  
  <pre><code>variable "security_groups" {
    type = "list"
    description = "The security groups to attach to launched instances."
    }
  
  module "launch_configuration" {
    source = "launch_configuration"
    security_groups = "${var.security_groups}"
    }
  
  resource "aws_autoscaling_group" "service_autoscaling_group" {
  
    name_prefix = "foobar"
  
    min_size = 1
    max_size = 1
    health_check_type = "EC2"
    launch_configuration = "${module.launch_configuration.name}"
    vpc_zone_identifier = ["this_is_fake"]
    }
  </code></pre>
  
  <p>The content of <code>launch_configuration/main.tf</code>:</p>
  
  <pre><code>variable "security_groups" {
    type = "list"
    description = "The security groups to attach to launched instances."
    }
  
  output "name" {
    value = "${aws_launch_configuration.this.name}"
    }
  
  resource "aws_launch_configuration" "this" {
    name_prefix = "foobar"
    image_id = "this_is_fake"
    instance_type = "ts.small"
    security_groups = "${var.security_groups}"
    }
  </code></pre>
  
  <p>Again, if I wrap brackets around the RHS of the last assignment <code>["${var.security_groups}"]</code>, I don't see the error from <code>terraform plan</code>. But terraform recognizes the variable as a list (since it complains about it being a list type if I remove the <code>type = "list"</code> from the declaration). So why does it complain that it expects a list here?</p>
  
  <p>The content of <code>security_group/main.tf</code>:</p>
  
  <pre><code>output "id" {
    value = "${aws_security_group.this.id}"
    description = "The security group ID."
    }
  
  resource "aws_security_group" "this" {
  
    name_prefix = "foobar"
    vpc_id      = "this_is_fake"
    description = "foobar"
  
    egress {
      from_port       = 0
      to_port         = 0
      protocol        = "-1"
      cidr_blocks     = ["0.0.0.0/0"]
      }
    }
  </code></pre>