title: Reading terraform variable from file
body: <p>In terraform, long keys can be specified as follows:</p>
  
  <pre><code>resource "aws_iam_role_policy" "foo-policy" {
      role = "${aws_iam_role.foo-role.name}"
      name = "foo-policy"
  
      policy = &lt;&lt;EOF
  {
      "Version": "2012-10-17",
      "Statement": [
          {
              "Effect": "Allow",
              "Action": [
                  "logs:CreateLogGroup",
                  "logs:CreateLogStream",
                  "logs:PutLogEvents",
                  "logs:DescribeLogStreams"
              ],
              "Resource": [
                  "arn:aws:logs:*:*:*"
              ]
          }
      ]
  }
  EOF
  }
  </code></pre>
  
  <p>This is a common pattern for IAM policy documents. The approach is documented <a href="https://www.terraform.io/docs/configuration/variables.html" rel="noreferrer">here</a> and is the example given in the <a href="https://www.terraform.io/docs/providers/aws/r/iam_role_policy.html" rel="noreferrer">AWS IAM role policy page on terraform</a>. Is there a way to instead read the document from an external file?</p>
  
  <p>This has numerous advantages:</p>
  
  <ul>
  <li>you can use tools to generate the policy</li>
  <li>you can use linting tools to validate the policy JSON. Also editor syntax highlighting will work, showing JSON mistakes like trailing commas.</li>
  <li>you can use more advanced tools to validate the policy document syntax</li>
  </ul>