title: Terraform - How to use tfvars with modules
body: <p>With three different environments, I want to be able to dynamically set variables based on the environment. In my example below, let's say the instance type is different between dev and prod. I'm not able to reference <code>instance_type</code> within the module UNLESS I have a <code>vars.tf</code> file alongside my <code>terraform.tfvars</code>. </p>
  
  <p>The error I get is:</p>
  
  <p><code>unknown variable referenced: 'instance_type'. define it with 'variable' blocks</code></p>
  
  <p>If that's the case, then wouldn't this file be the same exact file under <code>modules/apollo/vars.tf</code>?</p>
  
  <p>I thought <code>modules/apollo/vars.tf</code> defines the necessary variables needed for the module. I didn't think it was necessary within the "root" level under <code>env-dev/services/apollo/</code>. If there's a "better" way of doing this, I'm all ears.</p>
  
  <pre><code>├── env-dev
  │   └── services
  │       └── apollo
  │           ├── main.tf
  │           ├── terraform.tfvars    
  │           └── vars.tf # Do i need this?
  ├── env-test
  ├── global
  ├── mgmt
  └── modules
      ├── apollo
      │   ├── main.tf
      │   ├── user_data.tpl
      │   └── vars.tf
      └── defaults
          └── main.tf
  </code></pre>
  
  <h1>env-dev/services/apollo/terraform.tfvars</h1>
  
  <pre><code>instance_type    = "t2.medium"
  </code></pre>
  
  <h1>env-prod/services/apollo/terraform.tfvars</h1>
  
  <pre><code>instance_type    = "t2.large"
  </code></pre>
  
  <h1>modules/apollo/vars.tf</h1>
  
  <pre><code>variable "instance_type" {
    description = "EC2 Instance Type"
  }
  </code></pre>
  
  <h1>modules/apollo/main.tf</h1>
  
  <pre><code>resource "aws_instance" "instance" {     
    ...
    instance_type           = "${var.instance_type}"
    ...
  }
  </code></pre>