Terraform pass variables to a child module : <p>I am trying to pass a variable from the <code>root module</code> to a <code>child module</code> with the following syntax:</p>

<p><strong>main.tf:</strong></p>

<pre><code>provider "aws" {
  version = "~&gt; 1.11"
  access_key = "${var.aws_access_key}"
  secret_key = "${var.aws_secret_key}"
  region     = "${var.aws_region}"
}

module "iam" {
  account_id = "${var.account_id}"
  source = "./modules/iam"
}

 * account_id value is stored on variables.tf in the root folder
</code></pre>

<p><strong>/modules/iam/iam.tf</strong></p>

<pre><code>resource "aws_iam_policy_attachment" "myName" {
    name       = "myName"
    policy_arn = "arn:aws:iam::${var.account_id}:policy/myName" &lt;-- doesnt work
    groups     = []
    users      = []
    roles      = []
}
</code></pre>

<p>when I try to access within the module to <code>account_id</code> an error is thrown.</p>
