title: Terraform - conditionally merge multiple aws_iam_policy_document
body: <p>For starters, I've read <a href="https://stackoverflow.com/questions/64976695/how-to-conditionally-merge-multiple-iam-policy-statements-in-terraform">this question</a>, but that solution is rather hacky and I'm hoping that with the newer version of Terraform that there's a more elegant way to achieve this.</p>
  <p>I have multiple IAM policy documents like this:</p>
  <pre><code>data &quot;aws_iam_policy_document&quot; &quot;policy1&quot; { 
    ...
  }
  
  data &quot;aws_iam_policy_document&quot; &quot;policy2&quot; { 
    ...
  }
  
  data &quot;aws_iam_policy_document&quot; &quot;policy3&quot; { 
    ...
  }
  </code></pre>
  <p>And I'm attempting to merge them into one document with <code>source_policy_documents</code>, like so:</p>
  <pre><code>data &quot;aws_iam_policy_document&quot; &quot;combined&quot; {
    source_policy_documents = [
      data.aws_iam_policy_document.policy1.json
      data.aws_iam_policy_document.policy2.json
      data.aws_iam_policy_document.policy3.json
    ]
  }
  </code></pre>
  <p>I would like to offer &quot;override&quot; variables to allow users to exclude each document from being merged into the final policy.</p>
  <p>I'm new to Terraform - is there a straightforward way to either dynamically construct <code>source_policy_documents</code> or maybe use <code>override_policy_documents</code> to get what I want?</p>
  <p>Thanks!</p>