title: Terraform: Using Local Variables
body: <p>I am trying to understand: 
  - how to use locals as defined <a href="https://github.com/hashicorp/terraform/issues/5480" rel="nofollow noreferrer">here</a>.  </p>
  
  <p>So, I have a directory structure like this: 
      my-example/
        modules/
          test/
            security-groups/
              main.tf
            vpc/
              main.tf</p>
  
  <p>code in <code>my-examples/modules/test/vpc/main.tf</code>: </p>
  
  <pre><code>variable "vpc_name" {
    default = "Test"
  }
  
  resource "aws_vpc" "test_vpc" {
    cidr_block            = "172.31.0.0/16"
    enable_dns_support    = true
    enable_dns_hostnames  = true
  
    tags {
      Name = "${var.vpc_name}:VPC"
      Environment = "${var.vpc_name}"
    }
  }
  
  locals {
    id_vpc = "${aws_vpc.test_vpc.id}"
  }
  
  module "security_groups" {
    source = "../security-groups"
    id_vpc = "${local.id_vpc}"
  }
  </code></pre>
  
  <p>The idea is to be able to use <code>id_vpc</code> in <code>my-examples/modules/security-group/main.tf</code> like so: </p>
  
  <pre><code>resource "aws_security_group" "bastion_sg" {
    vpc_id = id_vpc
    name = "Bastion-SG"
  
    ingress {
      from_port = 22
      to_port = 22
      protocol = "tcp"
      cidr_blocks = ["0.0.0.0/0"]
    }
  
  }
  </code></pre>
  
  <p>Yet, I keep getting this error: 
      Errors:</p>
  
  <pre><code>  * 1 error(s) occurred:
  
    * module root: module security_groups: id_vpc is not a valid parameter
  </code></pre>
  
  <p>Can someone please explain to me why the local variable isn't being evaluated? It would be greatly apprecaited. Thank you.</p>