title: Terraform Modules - Variables and .tfvars
body: <p>Having an issue with Terraform modules and variables and I am at a loss as to what I am doing wrong.</p>
  
  <p>I have a folder structure that looks like this;</p>
  
  <pre><code>Accounts
      |_____Account1
      |        Main.tf
      |        terraform.tfvars
      |_____Account2
      |_____Account3
      |_____Modules
               |________VPC
                        Main.tf
                        Variables.tf
  </code></pre>
  
  <p>In my modules folder I have my main.tf and variables.tf, under the accounts I also have my main.tf (calling module vpc) and terrform.tfvars.</p>
  
  <p>How can I use my terraform.tfvars to pass secure credentials to my main.tf, within my accounts folder?</p>
  
  <p>Variables in my Variables.tf within the VPC module look like so;</p>
  
  <pre><code>variable "aws_access_key" {
    default = ""
   }
  </code></pre>
  
  <p>Within my account folders, in the Main.tf I am trying to call tfvars this way;</p>
  
  <pre><code>variable "aws_access_key" {}
  
  module "VPC" {
  source = "/Accounts/Modules/VPC"
  aws_access_key = "${var.aws_access_key}"
  }
  </code></pre>
  
  <p>Can run terraform init without any issues but trying to run terraform plan, it just comes up in red and fails to run. This does work if I enter the variables into my main.tf within the account folder manually. But I want to strip out anything sensitive into a .tfvars file, that will end up else where.</p>
  
  <p>I hope I am doing something obviously wrong! Have also tried the -var-file=terraform.tfvars switch from within account1's folder.</p>
  
  <p>Any idea's would be great. As everything I read tend to imply this should be working.</p>
  
  <p>Thanks
  Stephen</p>
  
  <p><a href="https://i.stack.imgur.com/l015q.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/l015q.png" alt="enter image description here"></a></p>