title: Terraform module - output variable as input for another module
body: <p>I am new to terraform and trying to build an infrastructure with two subnets and VPC. I have created two modules</p>
  <ul>
  <li>VPC</li>
  <li>subnet</li>
  </ul>
  <p>The VPC module will create a VPC and will return vpc_id as output, the same return vpc_id I am trying to use in the subnet module, but when I run the terraform plan, it asks me for the enter vpc_id input.</p>
  <p>I want the vpc_id from the output value of the VPC module, can anyone please help me on the same.</p>
  <p>Below is the code,</p>
  <p><strong>root tf file,</strong></p>
  <pre><code> provider &quot;aws&quot; {
    shared_credentials_file = var.shared_cred
    profile                 = &quot;default&quot; 
    region                  = var.aws_region
  }
  
  module &quot;vpc&quot; {
    source = &quot;./vpc&quot;
    name   = &quot;terraformVPC&quot;
    cidr   = &quot;10.50.40.0/27&quot;
  }
  
  module &quot;private_subnet&quot; {
    source      = &quot;./subnet&quot;
    subnet_name = &quot;private_subnet&quot;
    subnet_cidr = &quot;10.50.40.16/28&quot;
    #VPC_id = aws_vpc.moduleVPC.id
    VPCid = module.vpc.outvpc_id # this is the issue
  }
  
  module &quot;public_subnet&quot; {
    source      = &quot;./subnet&quot;
    subnet_name = &quot;public_subnet&quot;
    subnet_cidr = &quot;10.50.40.0/28&quot;
    VPCid      = module.vpc.outvpc_id
  }
  </code></pre>
  <p><strong>Subnet resource</strong></p>
  <pre><code>resource &quot;aws_subnet&quot; &quot;module_subnet&quot; {
    cidr_block = var.subnet_cidr
    vpc_id     = var.VPCid
  
    tags = {
      Name = var.subnet_name
    }
  }
  </code></pre>
  <p><strong>Subnet module variable declaration</strong></p>
  <pre><code>variable &quot;subnet_name&quot; {
    description = &quot; define th subnet name&quot;
  }
  
  variable &quot;subnet_cidr&quot; {
    description = &quot;define th subnet cidr block&quot;
  }
  
  variable &quot;VPCid&quot; {
    description = &quot;Assign VPC id to subnet&quot;
  }
  </code></pre>
  <p><strong>VPC output</strong></p>
  <pre><code>output &quot;outvpc_id&quot; {
    value = &quot;${aws_vpc.moduleVPC.id}&quot;
  }
  </code></pre>